Skip to contentSkip to conversation

dax/bus: clear parent drvdata when releasing a region

PATCH In review Avi Weiss 2 participants 2 messages Oct 28 – Dec 3

Subsystems (2)
lore
Share & tools
lore

Avi Weiss

author
#0 lore raw

PATCH 1/1 dax/bus: clear parent drvdata when releasing a region

alloc_dax_region() sets parent drvdata before reserving the resource and registering sysfs attributes. If either operation fails, the region is freed but drvdata still points to it. A later allocation on the same parent is rejected by the non-NULL drvdata check.

The devres unregister action also leaves drvdata pointing to the released region. Clear drvdata on both allocation error and unregister paths.

Fixes d7fe1a67f658 ("dax: add region 'id', 'size', and 'align' attributes")
---
 drivers/dax/bus.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/dax/bus.c +2 -0
index b809e1a264afa..dceaa395760e7 100644
@@ -627,6 +627,7 @@ static void dax_region_unregister(void *region)
 	sysfs_remove_groups(&dax_region->dev->kobj,
 			dax_region_attribute_groups);
 	release_resource(&dax_region->res);
+	dev_set_drvdata(dax_region->dev, NULL);
 	dax_region_put(dax_region);
 }
 
@@ -685,6 +686,7 @@ struct dax_region *alloc_dax_region(struct device *parent, int region_id,
 err_sysfs:
 	release_resource(&dax_region->res);
 err_res:
+	dev_set_drvdata(parent, NULL);
 	dax_region_put(dax_region);
 	return NULL;
 }

base-commit: d135ab453a7400a34930bdda1ef4bdc8acfac80e

Signature · 1 line
2.43.0
maintainer
#1 lore raw
Quoted 8 lines · Avi Weiss

alloc_dax_region() sets parent drvdata before reserving the resource and registering sysfs attributes. If either operation fails, the region is freed but drvdata still points to it. A later allocation on the same parent is rejected by the non-NULL drvdata check.

The devres unregister action also leaves drvdata pointing to the released region. Clear drvdata on both allocation error and unregister paths.

Hi Avi,

Thanks for the patch!

I'm not finding a way to reach a second alloc_dax_region() call with stale drvdata? The PMEM, HMEM, and CXL callers all fail probe if allocation fails, and the driver core clears drvdata before the next probe. On unbind, the driver core also clears it after releasing devres.

If there’s a path where the stale pointer causes a failure, please describe it in the commit message. Otherwise, please drop the reprobe claim and the
Fixes: tag and describe the change as clearing the parent’s drvdata before dropping the region reference.

The code changes look fine as written.

-- Alison

Quoted 32 lines
Fixes d7fe1a67f658 ("dax: add region 'id', 'size', and 'align' attributes")
---
 drivers/dax/bus.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/dax/bus.c +2 -0
index b809e1a264afa..dceaa395760e7 100644
@@ -627,6 +627,7 @@ static void dax_region_unregister(void *region)
 	sysfs_remove_groups(&dax_region->dev->kobj,
 			dax_region_attribute_groups);
 	release_resource(&dax_region->res);
+	dev_set_drvdata(dax_region->dev, NULL);
 	dax_region_put(dax_region);
 }
 
@@ -685,6 +686,7 @@ struct dax_region *alloc_dax_region(struct device *parent, int region_id,
 err_sysfs:
 	release_resource(&dax_region->res);
 err_res:
+	dev_set_drvdata(parent, NULL);
 	dax_region_put(dax_region);
 	return NULL;
 }

base-commit: d135ab453a7400a34930bdda1ef4bdc8acfac80e

Signature · 1 line
2.43.0