summaryrefslogtreecommitdiff
path: root/drivers/base/core.c
diff options
context:
space:
mode:
authorGreg Kroah-Hartman <gregkh@linuxfoundation.org>2023-02-09 10:35:56 +0100
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2023-02-10 10:16:42 +0100
commit8c99377e614f8abfd881c34611002b2af5ab1ee8 (patch)
tree2122c752dc8c47b6be963a18fcfecab2f8735417 /drivers/base/core.c
parentad8685d0f61a6fc1dc2e5874f4924ff5028c5954 (diff)
downloadlwn-8c99377e614f8abfd881c34611002b2af5ab1ee8.tar.gz
lwn-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/core.c')
-rw-r--r--drivers/base/core.c14
1 files changed, 11 insertions, 3 deletions
diff --git a/drivers/base/core.c b/drivers/base/core.c
index 2712a1a1e959..f9297c68214a 100644
--- a/drivers/base/core.c
+++ b/drivers/base/core.c
@@ -3173,8 +3173,9 @@ static DEFINE_MUTEX(gdp_mutex);
static struct kobject *get_device_parent(struct device *dev,
struct device *parent)
{
+ struct kobject *kobj = NULL;
+
if (dev->class) {
- struct kobject *kobj = NULL;
struct kobject *parent_kobj;
struct kobject *k;
@@ -3222,8 +3223,15 @@ static struct kobject *get_device_parent(struct device *dev,
}
/* subsystems can specify a default root directory for their devices */
- if (!parent && dev->bus && dev->bus->dev_root)
- return &dev->bus->dev_root->kobj;
+ if (!parent && dev->bus) {
+ struct device *dev_root = bus_get_dev_root(dev->bus);
+
+ if (dev_root) {
+ kobj = &dev_root->kobj;
+ put_device(dev_root);
+ return kobj;
+ }
+ }
if (parent)
return &parent->kobj;