Skip to content

Commit 4b775aa

Browse files
robherringgregkh
authored andcommitted
driver core: Refactor sysfs and drv/bus remove hooks
There are 3 copies of the same device sysfs cleanup and drv/bus remove() hooks used for probe failure, testing re-probing, and device unbinding. Let's refactor the code to its own function. Signed-off-by: Rob Herring <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 9ad3072 commit 4b775aa

File tree

1 file changed

+14
-20
lines changed

1 file changed

+14
-20
lines changed

drivers/base/dd.c

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -520,6 +520,17 @@ static void device_unbind_cleanup(struct device *dev)
520520
dev_pm_set_driver_flags(dev, 0);
521521
}
522522

523+
static void device_remove(struct device *dev)
524+
{
525+
device_remove_file(dev, &dev_attr_state_synced);
526+
device_remove_groups(dev, dev->driver->dev_groups);
527+
528+
if (dev->bus && dev->bus->remove)
529+
dev->bus->remove(dev);
530+
else if (dev->driver->remove)
531+
dev->driver->remove(dev);
532+
}
533+
523534
static int call_driver_probe(struct device *dev, struct device_driver *drv)
524535
{
525536
int ret = 0;
@@ -633,14 +644,7 @@ static int really_probe(struct device *dev, struct device_driver *drv)
633644
if (test_remove) {
634645
test_remove = false;
635646

636-
device_remove_file(dev, &dev_attr_state_synced);
637-
device_remove_groups(dev, drv->dev_groups);
638-
639-
if (dev->bus->remove)
640-
dev->bus->remove(dev);
641-
else if (drv->remove)
642-
drv->remove(dev);
643-
647+
device_remove(dev);
644648
driver_sysfs_remove(dev);
645649
device_unbind_cleanup(dev);
646650

@@ -658,12 +662,8 @@ static int really_probe(struct device *dev, struct device_driver *drv)
658662
goto done;
659663

660664
dev_sysfs_state_synced_failed:
661-
device_remove_groups(dev, drv->dev_groups);
662665
dev_groups_failed:
663-
if (dev->bus->remove)
664-
dev->bus->remove(dev);
665-
else if (drv->remove)
666-
drv->remove(dev);
666+
device_remove(dev);
667667
probe_failed:
668668
driver_sysfs_remove(dev);
669669
sysfs_failed:
@@ -1196,13 +1196,7 @@ static void __device_release_driver(struct device *dev, struct device *parent)
11961196

11971197
pm_runtime_put_sync(dev);
11981198

1199-
device_remove_file(dev, &dev_attr_state_synced);
1200-
device_remove_groups(dev, drv->dev_groups);
1201-
1202-
if (dev->bus && dev->bus->remove)
1203-
dev->bus->remove(dev);
1204-
else if (drv->remove)
1205-
drv->remove(dev);
1199+
device_remove(dev);
12061200

12071201
device_links_driver_cleanup(dev);
12081202
device_unbind_cleanup(dev);

0 commit comments

Comments
 (0)