mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-09-27 04:47:05 +00:00
kunit: device: Unregister the kunit_bus on shutdown
If KUnit is built as a module, and it's unloaded, the kunit_bus is not
unregistered. This causes an error if it's then re-loaded later, as we
try to re-register the bus.
Unregister the bus and root_device on shutdown, if it looks valid.
In addition, be more specific about the value of kunit_bus_device. It
is:
- a valid struct device* if the kunit_bus initialised correctly.
- an ERR_PTR if it failed to initialise.
- NULL before initialisation and after shutdown.
Fixes: d03c720e03
("kunit: Add APIs for managing devices")
Signed-off-by: David Gow <davidgow@google.com>
Reviewed-by: Rae Moar <rmoar@google.com>
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
This commit is contained in:
parent
1a9f2c776d
commit
829388b725
3 changed files with 19 additions and 0 deletions
|
@ -13,5 +13,7 @@
|
||||||
|
|
||||||
// For internal use only -- registers the kunit_bus.
|
// For internal use only -- registers the kunit_bus.
|
||||||
int kunit_bus_init(void);
|
int kunit_bus_init(void);
|
||||||
|
// For internal use only -- unregisters the kunit_bus.
|
||||||
|
void kunit_bus_shutdown(void);
|
||||||
|
|
||||||
#endif //_KUNIT_DEVICE_IMPL_H
|
#endif //_KUNIT_DEVICE_IMPL_H
|
||||||
|
|
|
@ -54,6 +54,20 @@ int kunit_bus_init(void)
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Unregister the 'kunit_bus' in case the KUnit module is unloaded. */
|
||||||
|
void kunit_bus_shutdown(void)
|
||||||
|
{
|
||||||
|
/* Make sure the bus exists before we unregister it. */
|
||||||
|
if (IS_ERR_OR_NULL(kunit_bus_device))
|
||||||
|
return;
|
||||||
|
|
||||||
|
bus_unregister(&kunit_bus_type);
|
||||||
|
|
||||||
|
root_device_unregister(kunit_bus_device);
|
||||||
|
|
||||||
|
kunit_bus_device = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
/* Release a 'fake' KUnit device. */
|
/* Release a 'fake' KUnit device. */
|
||||||
static void kunit_device_release(struct device *d)
|
static void kunit_device_release(struct device *d)
|
||||||
{
|
{
|
||||||
|
|
|
@ -928,6 +928,9 @@ static void __exit kunit_exit(void)
|
||||||
#ifdef CONFIG_MODULES
|
#ifdef CONFIG_MODULES
|
||||||
unregister_module_notifier(&kunit_mod_nb);
|
unregister_module_notifier(&kunit_mod_nb);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
kunit_bus_shutdown();
|
||||||
|
|
||||||
kunit_debugfs_cleanup();
|
kunit_debugfs_cleanup();
|
||||||
}
|
}
|
||||||
module_exit(kunit_exit);
|
module_exit(kunit_exit);
|
||||||
|
|
Loading…
Reference in a new issue