cxl: Refactor to use __free() for cxl_root allocation in cxl_endpoint_port_probe()
authorDave Jiang <dave.jiang@intel.com>
Fri, 5 Jan 2024 22:07:59 +0000 (15:07 -0700)
committerDan Williams <dan.j.williams@intel.com>
Fri, 5 Jan 2024 22:36:29 +0000 (14:36 -0800)
Use scope-based resource management __free() macro to drop the open coded
put_device() in cxl_endpoint_port_probe().

Reviewed-by: Ira Weiny <ira.weiny@intel.com>
Signed-off-by: Dave Jiang <dave.jiang@intel.com>
Link: https://lore.kernel.org/r/170449247973.3779673.15088722836135359275.stgit@djiang5-mobl3
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
drivers/cxl/port.c

index 4f3a08fdc9e9430008000afdb803969caec71ddc..97c21566677aa3b4dbdd84d7d656198d53af63fd 100644 (file)
@@ -94,7 +94,6 @@ static int cxl_endpoint_port_probe(struct cxl_port *port)
        struct cxl_endpoint_dvsec_info info = { .port = port };
        struct cxl_memdev *cxlmd = to_cxl_memdev(port->uport_dev);
        struct cxl_dev_state *cxlds = cxlmd->cxlds;
-       struct cxl_root *cxl_root;
        struct cxl_hdm *cxlhdm;
        struct cxl_port *root;
        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 = &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(&port->dev, root, discover_region);
-       put_device(&root->dev);
 
        return 0;
 }