Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

driver core: bus: move dev_root out of struct bus_type

Now that all accesses of dev_root is through the bus_get_dev_root()
call, move the pointer out of struct bus_type and into the private
dynamic structure, subsys_private.

With this change, there is no modifiable portions of struct bus_type so
it can be marked as a constant structure and moved to read-only memory.

Cc: "Rafael J. Wysocki" <rafael@kernel.org>
Link: https://lore.kernel.org/r/20230313182918.1312597-22-gregkh@linuxfoundation.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

+24 -8
+2
drivers/base/base.h
··· 27 27 * on this bus. 28 28 * @bus - pointer back to the struct bus_type that this structure is associated 29 29 * with. 30 + * @dev_root: Default device to use as the parent. 30 31 * 31 32 * @glue_dirs - "glue" directory to put in-between the parent device to 32 33 * avoid namespace conflicts ··· 50 49 struct blocking_notifier_head bus_notifier; 51 50 unsigned int drivers_autoprobe:1; 52 51 struct bus_type *bus; 52 + struct device *dev_root; 53 53 54 54 struct kset glue_dirs; 55 55 struct class *class;
+22 -6
drivers/base/bus.c
··· 935 935 return; 936 936 937 937 pr_debug("bus: '%s': unregistering\n", bus->name); 938 - if (bus->dev_root) 939 - device_unregister(bus->dev_root); 938 + if (sp->dev_root) 939 + device_unregister(sp->dev_root); 940 940 941 941 bus_kobj = &sp->subsys.kobj; 942 942 sysfs_remove_groups(bus_kobj, bus->bus_groups); ··· 1198 1198 const struct attribute_group **groups, 1199 1199 struct kobject *parent_of_root) 1200 1200 { 1201 + struct subsys_private *sp; 1201 1202 struct device *dev; 1202 1203 int err; 1203 1204 1204 1205 err = bus_register(subsys); 1205 1206 if (err < 0) 1206 1207 return err; 1208 + 1209 + sp = bus_to_subsys(subsys); 1210 + if (!sp) { 1211 + err = -EINVAL; 1212 + goto err_sp; 1213 + } 1207 1214 1208 1215 dev = kzalloc(sizeof(struct device), GFP_KERNEL); 1209 1216 if (!dev) { ··· 1230 1223 if (err < 0) 1231 1224 goto err_dev_reg; 1232 1225 1233 - subsys->dev_root = dev; 1226 + sp->dev_root = dev; 1227 + subsys_put(sp); 1234 1228 return 0; 1235 1229 1236 1230 err_dev_reg: ··· 1240 1232 err_name: 1241 1233 kfree(dev); 1242 1234 err_dev: 1235 + subsys_put(sp); 1236 + err_sp: 1243 1237 bus_unregister(subsys); 1244 1238 return err; 1245 1239 } ··· 1359 1349 */ 1360 1350 struct device *bus_get_dev_root(const struct bus_type *bus) 1361 1351 { 1362 - if (bus) 1363 - return get_device(bus->dev_root); 1364 - return NULL; 1352 + struct subsys_private *sp = bus_to_subsys(bus); 1353 + struct device *dev_root; 1354 + 1355 + if (!sp) 1356 + return NULL; 1357 + 1358 + dev_root = get_device(sp->dev_root); 1359 + subsys_put(sp); 1360 + return dev_root; 1365 1361 } 1366 1362 EXPORT_SYMBOL_GPL(bus_get_dev_root); 1367 1363
-2
include/linux/device/bus.h
··· 26 26 * 27 27 * @name: The name of the bus. 28 28 * @dev_name: Used for subsystems to enumerate devices like ("foo%u", dev->id). 29 - * @dev_root: Default device to use as the parent. 30 29 * @bus_groups: Default attributes of the bus. 31 30 * @dev_groups: Default attributes of the devices on the bus. 32 31 * @drv_groups: Default attributes of the device drivers on the bus. ··· 81 82 struct bus_type { 82 83 const char *name; 83 84 const char *dev_name; 84 - struct device *dev_root; 85 85 const struct attribute_group **bus_groups; 86 86 const struct attribute_group **dev_groups; 87 87 const struct attribute_group **drv_groups;