1
linux/lib/kunit/device-impl.h
David Gow 829388b725 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>
2024-02-06 17:07:37 -07:00

20 lines
484 B
C

/* SPDX-License-Identifier: GPL-2.0 */
/*
* KUnit internal header for device helpers
*
* Header for KUnit-internal driver / bus management.
*
* Copyright (C) 2023, Google LLC.
* Author: David Gow <davidgow@google.com>
*/
#ifndef _KUNIT_DEVICE_IMPL_H
#define _KUNIT_DEVICE_IMPL_H
// 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