Commit 829388b7 authored by David Gow's avatar David Gow Committed by Shuah Khan

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: d03c720e ("kunit: Add APIs for managing devices")
Signed-off-by: default avatarDavid Gow <davidgow@google.com>
Reviewed-by: default avatarRae Moar <rmoar@google.com>
Signed-off-by: default avatarShuah Khan <skhan@linuxfoundation.org>
parent 1a9f2c77
......@@ -13,5 +13,7 @@
// For internal use only -- registers the kunit_bus.
int kunit_bus_init(void);
// For internal use only -- unregisters the kunit_bus.
void kunit_bus_shutdown(void);
#endif //_KUNIT_DEVICE_IMPL_H
......@@ -54,6 +54,20 @@ int kunit_bus_init(void)
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. */
static void kunit_device_release(struct device *d)
{
......
......@@ -928,6 +928,9 @@ static void __exit kunit_exit(void)
#ifdef CONFIG_MODULES
unregister_module_notifier(&kunit_mod_nb);
#endif
kunit_bus_shutdown();
kunit_debugfs_cleanup();
}
module_exit(kunit_exit);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment