History

cxl: Fix cleanup of port devices on failure to probe driver.

The device is created, and then there is a check if a driver succesfully bound to it. In event of failing the bind (e.g. failure in cxl_port_probe()) the device is left registered. When a bus rescan later occurs, fresh devices are created leading to a multiple device representing the same underlying hardware. Bad things may follow and at very least we have far too many devices. Fix by ensuring autoremove is registered if the device create succeeds, but doesn't depend on sucessful binding to a driver. Bug was observed as side effect of incorrect ownership in [PATCH v9 6/9] cxl/port: Read CDAT table but will result from any failure to in cxl_port_probe().

Jonathan Cameron committed 4 years ago

Commit db9a3a31 parent f6f0dab1 file · +6 −1Browse files

Unified · Split

drivers/cxl/mem.c+6−1
@@ -29,6 +29,7 @@ static int create_endpoint(struct cxl_memdev *cxlmd, · 28 unmodified lines
29{29{
30 struct cxl_dev_state *cxlds = cxlmd->cxlds;30 struct cxl_dev_state *cxlds = cxlmd->cxlds;
31 struct cxl_port *endpoint;31 struct cxl_port *endpoint;
32 int rc;
32 33
33 endpoint = devm_cxl_add_port(&parent_port->dev, &cxlmd->dev,34 endpoint = devm_cxl_add_port(&parent_port->dev, &cxlmd->dev,
34 cxlds->component_reg_phys, parent_port);35 cxlds->component_reg_phys, parent_port);
@@ -37,13 +38,17 @@ static int create_endpoint(struct cxl_memdev *cxlmd, · 2 unmodified lines
37 38
38 dev_dbg(&cxlmd->dev, "add: %s\n", dev_name(&endpoint->dev));39 dev_dbg(&cxlmd->dev, "add: %s\n", dev_name(&endpoint->dev));
39 40
41 rc = cxl_endpoint_autoremove(cxlmd, endpoint);
42 if (rc)
43 return rc;
44
40 if (!endpoint->dev.driver) {45 if (!endpoint->dev.driver) {
41 dev_err(&cxlmd->dev, "%s failed probe\n",46 dev_err(&cxlmd->dev, "%s failed probe\n",
42 dev_name(&endpoint->dev));47 dev_name(&endpoint->dev));
43 return -ENXIO;48 return -ENXIO;
44 }49 }
45 50
46 return cxl_endpoint_autoremove(cxlmd, endpoint);51 return 0;
47}52}
48 53
49static void enable_suspend(void *data)54static void enable_suspend(void *data)