Skip to content

Commit bea5b15

Browse files
robherringgregkh
authored andcommitted
driver core: add test of driver remove calls during probe
In recent discussions on ksummit-discuss[1], it was suggested to do a sequence of probe, remove, probe for testing driver remove paths. This adds a kconfig option for said test. [1] https://lists.linuxfoundation.org/pipermail/ksummit-discuss/2016-August/003459.html Suggested-by: Arnd Bergmann <[email protected]> Cc: Greg Kroah-Hartman <[email protected]> Signed-off-by: Rob Herring <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent cebf8fd commit bea5b15

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

drivers/base/Kconfig

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,16 @@ config DEBUG_DEVRES
212212

213213
If you are unsure about this, Say N here.
214214

215+
config DEBUG_TEST_DRIVER_REMOVE
216+
bool "Test driver remove calls during probe"
217+
depends on DEBUG_KERNEL
218+
help
219+
Say Y here if you want the Driver core to test driver remove functions
220+
by calling probe, remove, probe. This tests the remove path without
221+
having to unbind the driver or unload the driver module.
222+
223+
If you are unsure about this, say N here.
224+
215225
config SYS_HYPERVISOR
216226
bool
217227
default n

drivers/base/dd.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,7 @@ static int really_probe(struct device *dev, struct device_driver *drv)
329329
{
330330
int ret = -EPROBE_DEFER;
331331
int local_trigger_count = atomic_read(&deferred_trigger_count);
332+
bool test_remove = IS_ENABLED(CONFIG_DEBUG_TEST_DRIVER_REMOVE);
332333

333334
if (defer_all_probes) {
334335
/*
@@ -346,6 +347,7 @@ static int really_probe(struct device *dev, struct device_driver *drv)
346347
drv->bus->name, __func__, drv->name, dev_name(dev));
347348
WARN_ON(!list_empty(&dev->devres_head));
348349

350+
re_probe:
349351
dev->driver = drv;
350352

351353
/* If using pinctrl, bind pins now before probing */
@@ -383,6 +385,25 @@ static int really_probe(struct device *dev, struct device_driver *drv)
383385
goto probe_failed;
384386
}
385387

388+
if (test_remove) {
389+
test_remove = false;
390+
391+
if (dev->bus && dev->bus->remove)
392+
dev->bus->remove(dev);
393+
else if (drv->remove)
394+
drv->remove(dev);
395+
396+
devres_release_all(dev);
397+
driver_sysfs_remove(dev);
398+
dev->driver = NULL;
399+
dev_set_drvdata(dev, NULL);
400+
if (dev->pm_domain && dev->pm_domain->dismiss)
401+
dev->pm_domain->dismiss(dev);
402+
pm_runtime_reinit(dev);
403+
404+
goto re_probe;
405+
}
406+
386407
pinctrl_init_done(dev);
387408

388409
if (dev->pm_domain && dev->pm_domain->sync)

0 commit comments

Comments
 (0)