cxl: Set cxlmd->endpoint before adding port device
authorDave Jiang <dave.jiang@intel.com>
Fri, 8 Mar 2024 21:59:27 +0000 (14:59 -0700)
committerDan Williams <dan.j.williams@intel.com>
Tue, 12 Mar 2024 19:34:11 +0000 (12:34 -0700)
Move setting of cxlmd->endpoint to before calling add_device() on the port
device. Otherwise when referencing cxlmd->endpoint in region discovery code
that is triggered by the port driver probe function, the endpoint port
pointer is not valid.

Current code does not hit this issue yet since cxlmd->endpoint is not being
referenced during region discovery. However follow on code that does
performance calculations will.

Tested-by: Wonjae Lee <wj28.lee@samsung.com>
Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Tested-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Signed-off-by: Dave Jiang <dave.jiang@intel.com>
Link: https://lore.kernel.org/r/20240308220055.2172956-9-dave.jiang@intel.com
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
drivers/cxl/core/port.c

index b2a2f6c34886d7b49a5778631a10c8486f9a6719..9ab542e7af65151472629dfa5584072b383041e2 100644 (file)
@@ -822,6 +822,7 @@ static struct cxl_port *__devm_cxl_add_port(struct device *host,
                 */
                port->reg_map = cxlds->reg_map;
                port->reg_map.host = &port->dev;
+               cxlmd->endpoint = port;
        } else if (parent_dport) {
                rc = dev_set_name(dev, "port%d", port->id);
                if (rc)
@@ -1374,7 +1375,6 @@ int cxl_endpoint_autoremove(struct cxl_memdev *cxlmd, struct cxl_port *endpoint)
 
        get_device(host);
        get_device(&endpoint->dev);
-       cxlmd->endpoint = endpoint;
        cxlmd->depth = endpoint->depth;
        return devm_add_action_or_reset(dev, delete_endpoint, cxlmd);
 }