kunit: device: Unregister the kunit_bus on shutdown
authorDavid Gow <davidgow@google.com>
Thu, 1 Feb 2024 06:04:36 +0000 (14:04 +0800)
committerShuah Khan <skhan@linuxfoundation.org>
Wed, 7 Feb 2024 00:07:37 +0000 (17:07 -0700)
commit829388b725f8d266ccec32a2f446717d8693eaba
treee78cc7504880a13c161d8e7b6d50706277499470
parent1a9f2c776d1416c4ea6cb0d0b9917778c41a1a7d
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: d03c720e03bd ("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>
lib/kunit/device-impl.h
lib/kunit/device.c
lib/kunit/test.c