diff mbox series

[v4,6/6] cxl: Refactor to use __free() for cxl_root allocation in cxl_endpoint_port_probe()

Message ID 170441751817.3632067.18926893176028509.stgit@djiang5-mobl3
State New, archived
Headers show
Series find_cxl_root() related cleanups | expand

Commit Message

Dave Jiang Jan. 5, 2024, 1:18 a.m. UTC
Use scope-based resource management __free() macro to make cxl_root
allocation simpler and safer in cxl_endpoint_port_probe().

Signed-off-by: Dave Jiang <dave.jiang@intel.com>
---
v4:
- Don't check return value of find_cxl_root() per comment. (Dan)
---
 drivers/cxl/port.c |    5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
diff mbox series

Patch

diff --git a/drivers/cxl/port.c b/drivers/cxl/port.c
index ddbb42f0fd70..89d303f048e7 100644
--- a/drivers/cxl/port.c
+++ b/drivers/cxl/port.c
@@ -95,7 +95,6 @@  static int cxl_endpoint_port_probe(struct cxl_port *port)
 	struct cxl_memdev *cxlmd = to_cxl_memdev(port->uport_dev);
 	struct cxl_dev_state *cxlds = cxlmd->cxlds;
 	struct cxl_hdm *cxlhdm;
-	struct cxl_root *cxl_root;
 	struct cxl_port *root_port;
 	int rc;
 
@@ -131,7 +130,8 @@  static int cxl_endpoint_port_probe(struct cxl_port *port)
 	 * This can't fail in practice as CXL root exit unregisters all
 	 * descendant ports and that in turn synchronizes with cxl_port_probe()
 	 */
-	cxl_root = find_cxl_root(port);
+	struct cxl_root *cxl_root __free(put_cxl_root) = find_cxl_root(port);
+
 	root_port = &cxl_root->port;
 
 	/*
@@ -139,7 +139,6 @@  static int cxl_endpoint_port_probe(struct cxl_port *port)
 	 * assemble regions from committed decoders
 	 */
 	device_for_each_child(&root_port->dev, root_port, discover_region);
-	put_cxl_root(cxl_root);
 
 	return 0;
 }