Skip to content

Commit 0998d06

Browse files
jwrdegoedegregkh
authored andcommitted
device-core: Ensure drvdata = NULL when no driver is bound
1) drvdata is for a driver to store a pointer to driver specific data 2) If no driver is bound, there is no driver specific data associated with the device 3) Thus logically drvdata should be NULL if no driver is bound. But many drivers don't clear drvdata on device_release, or set drvdata early on in probe and leave it set on probe error. Both of which results in a dangling pointer in drvdata. This patch enforce for drvdata to be NULL after device_release or on probe failure. Signed-off-by: Hans de Goede <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent b02f8be commit 0998d06

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

drivers/base/dd.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,7 @@ static int really_probe(struct device *dev, struct device_driver *drv)
283283
devres_release_all(dev);
284284
driver_sysfs_remove(dev);
285285
dev->driver = NULL;
286+
dev_set_drvdata(dev, NULL);
286287

287288
if (ret == -EPROBE_DEFER) {
288289
/* Driver requested deferred probing */
@@ -487,6 +488,7 @@ static void __device_release_driver(struct device *dev)
487488
drv->remove(dev);
488489
devres_release_all(dev);
489490
dev->driver = NULL;
491+
dev_set_drvdata(dev, NULL);
490492
klist_remove(&dev->p->knode_driver);
491493
if (dev->bus)
492494
blocking_notifier_call_chain(&dev->bus->p->bus_notifier,

0 commit comments

Comments
 (0)