aboutsummaryrefslogtreecommitdiff
path: root/drivers/base/bus.c
diff options
context:
space:
mode:
authorGravatar Greg Kroah-Hartman <gregkh@linuxfoundation.org> 2023-02-08 12:13:13 +0100
committerGravatar Greg Kroah-Hartman <gregkh@linuxfoundation.org> 2023-02-09 10:43:12 +0100
commit0396f2863f7af3c588033d270f7d979d11cd4708 (patch)
tree205ffa763fbf9ce03ac55073f9f194d1de4af184 /drivers/base/bus.c
parentdriver core: bus: constantify the bus_find_* functions (diff)
downloadlinux-0396f2863f7af3c588033d270f7d979d11cd4708.tar.gz
linux-0396f2863f7af3c588033d270f7d979d11cd4708.tar.bz2
linux-0396f2863f7af3c588033d270f7d979d11cd4708.zip
driver core: bus: convert bus_create/remove_file to be constant
bus_create_file() and bus_remove_file() can be made to take a constant bus pointer, as it should not be modifying anything in the bus structure. Make this change and move the functions to use the internal subsys_get/put() logic as well, to prevent the use of the back-pointer in struct bus_type. Cc: "Rafael J. Wysocki" <rafael@kernel.org> Link: https://lore.kernel.org/r/20230208111330.439504-5-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.c28
1 files changed, 17 insertions, 11 deletions
diff --git a/drivers/base/bus.c b/drivers/base/bus.c
index b27ddf957f8b..6552d385fcb9 100644
--- a/drivers/base/bus.c
+++ b/drivers/base/bus.c
@@ -175,24 +175,30 @@ static const struct sysfs_ops bus_sysfs_ops = {
.store = bus_attr_store,
};
-int bus_create_file(struct bus_type *bus, struct bus_attribute *attr)
+int bus_create_file(const struct bus_type *bus, struct bus_attribute *attr)
{
+ struct subsys_private *sp = bus_to_subsys(bus);
int error;
- if (bus_get(bus)) {
- error = sysfs_create_file(&bus->p->subsys.kobj, &attr->attr);
- bus_put(bus);
- } else
- error = -EINVAL;
+
+ if (!sp)
+ return -EINVAL;
+
+ error = sysfs_create_file(&sp->subsys.kobj, &attr->attr);
+
+ subsys_put(sp);
return error;
}
EXPORT_SYMBOL_GPL(bus_create_file);
-void bus_remove_file(struct bus_type *bus, struct bus_attribute *attr)
+void bus_remove_file(const struct bus_type *bus, struct bus_attribute *attr)
{
- if (bus_get(bus)) {
- sysfs_remove_file(&bus->p->subsys.kobj, &attr->attr);
- bus_put(bus);
- }
+ struct subsys_private *sp = bus_to_subsys(bus);
+
+ if (!sp)
+ return;
+
+ sysfs_remove_file(&sp->subsys.kobj, &attr->attr);
+ subsys_put(sp);
}
EXPORT_SYMBOL_GPL(bus_remove_file);