diff options
author | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2023-02-09 10:35:56 +0100 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2023-02-10 10:16:42 +0100 |
commit | 8c99377e614f8abfd881c34611002b2af5ab1ee8 (patch) | |
tree | 2122c752dc8c47b6be963a18fcfecab2f8735417 /drivers/base/bus.c | |
parent | driver core: bus: constify bus_unregister() (diff) | |
download | linux-8c99377e614f8abfd881c34611002b2af5ab1ee8.tar.xz linux-8c99377e614f8abfd881c34611002b2af5ab1ee8.zip |
driver core: bus: add bus_get_dev_root() function
Instead of poking around in the struct bus_type directly for the
dev_root pointer, provide a function to return it properly reference
counted, if it is present in the bus. This will be needed to move the
pointer out of struct bus_type in the future.
Use the function in the driver core code at the same time it is
introduced to verify that it works properly.
Cc: "Rafael J. Wysocki" <rafael@kernel.org>
Link: https://lore.kernel.org/r/20230209093556.19132-1-gregkh@linuxfoundation.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/base/bus.c')
-rw-r--r-- | drivers/base/bus.c | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/drivers/base/bus.c b/drivers/base/bus.c index 301b9c6ece86..def1e009ad9d 100644 --- a/drivers/base/bus.c +++ b/drivers/base/bus.c @@ -1334,6 +1334,26 @@ bool bus_is_registered(const struct bus_type *bus) return is_initialized; } +/** + * bus_get_dev_root - return a pointer to the "device root" of a bus + * @bus: bus to return the device root of. + * + * If a bus has a "device root" structure, return it, WITH THE REFERENCE + * COUNT INCREMENTED. + * + * Note, when finished with the device, a call to put_device() is required. + * + * If the device root is not present (or bus is not a valid pointer), NULL + * will be returned. + */ +struct device *bus_get_dev_root(const struct bus_type *bus) +{ + if (bus) + return get_device(bus->dev_root); + return NULL; +} +EXPORT_SYMBOL_GPL(bus_get_dev_root); + int __init buses_init(void) { bus_kset = kset_create_and_add("bus", &bus_uevent_ops, NULL); |