Skip to content

Commit 91f842f

Browse files
committed
Merge tag 'linux_kselftest-kunit-fixes-6.8-rc5' of git://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest
Pull KUnit fix from Shuah Khan: "One important fix to unregister kunit_bus when KUnit module is unloaded. Not doing so causes an error when KUnit module tries to re-register the bus when it gets reloaded" * tag 'linux_kselftest-kunit-fixes-6.8-rc5' of git://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest: kunit: device: Unregister the kunit_bus on shutdown
2 parents 7e90b5c + 829388b commit 91f842f

3 files changed

Lines changed: 19 additions & 0 deletions

File tree

lib/kunit/device-impl.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,7 @@
1313

1414
// For internal use only -- registers the kunit_bus.
1515
int kunit_bus_init(void);
16+
// For internal use only -- unregisters the kunit_bus.
17+
void kunit_bus_shutdown(void);
1618

1719
#endif //_KUNIT_DEVICE_IMPL_H

lib/kunit/device.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,20 @@ int kunit_bus_init(void)
5454
return error;
5555
}
5656

57+
/* Unregister the 'kunit_bus' in case the KUnit module is unloaded. */
58+
void kunit_bus_shutdown(void)
59+
{
60+
/* Make sure the bus exists before we unregister it. */
61+
if (IS_ERR_OR_NULL(kunit_bus_device))
62+
return;
63+
64+
bus_unregister(&kunit_bus_type);
65+
66+
root_device_unregister(kunit_bus_device);
67+
68+
kunit_bus_device = NULL;
69+
}
70+
5771
/* Release a 'fake' KUnit device. */
5872
static void kunit_device_release(struct device *d)
5973
{

lib/kunit/test.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -928,6 +928,9 @@ static void __exit kunit_exit(void)
928928
#ifdef CONFIG_MODULES
929929
unregister_module_notifier(&kunit_mod_nb);
930930
#endif
931+
932+
kunit_bus_shutdown();
933+
931934
kunit_debugfs_cleanup();
932935
}
933936
module_exit(kunit_exit);

0 commit comments

Comments
 (0)