Commit c6f7e72a authored by Greg Kroah-Hartman's avatar Greg Kroah-Hartman

driver core: remove fields from struct bus_type

struct bus_type is static everywhere in the kernel.  This moves the
kobject in the structure out of it, and a bunch of other private only to
the driver core fields are now moved to a private structure.  This lets
us dynamically create the backing kobject properly and gives us the
chance to be able to document to users exactly how to use the struct
bus_type as there are no fields they can improperly access.

Thanks to Kay for the build fixes on this patch.

Cc: Kay Sievers <kay.sievers@vrfy.org>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
parent b249072e
/* initialisation functions */ /**
* struct bus_type_private - structure to hold the private to the driver core portions of the bus_type structure.
*
* @subsys - the struct kset that defines this bus. This is the main kobject
* @drivers_kset - the list of drivers associated with this bus
* @devices_kset - the list of devices associated with this bus
* @klist_devices - the klist to iterate over the @devices_kset
* @klist_drivers - the klist to iterate over the @drivers_kset
* @bus_notifier - the bus notifier list for anything that cares about things
* on this bus.
* @bus - pointer back to the struct bus_type that this structure is associated
* with.
*
* This structure is the one that is the actual kobject allowing struct
* bus_type to be statically allocated safely. Nothing outside of the driver
* core should ever touch these fields.
*/
struct bus_type_private {
struct kset subsys;
struct kset *drivers_kset;
struct kset *devices_kset;
struct klist klist_devices;
struct klist klist_drivers;
struct blocking_notifier_head bus_notifier;
unsigned int drivers_autoprobe:1;
struct bus_type *bus;
};
/* initialisation functions */
extern int devices_init(void); extern int devices_init(void);
extern int buses_init(void); extern int buses_init(void);
extern int classes_init(void); extern int classes_init(void);
......
This diff is collapsed.
...@@ -769,7 +769,7 @@ int device_add(struct device *dev) ...@@ -769,7 +769,7 @@ int device_add(struct device *dev)
/* notify clients of device entry (new way) */ /* notify clients of device entry (new way) */
if (dev->bus) if (dev->bus)
blocking_notifier_call_chain(&dev->bus->bus_notifier, blocking_notifier_call_chain(&dev->bus->p->bus_notifier,
BUS_NOTIFY_ADD_DEVICE, dev); BUS_NOTIFY_ADD_DEVICE, dev);
error = device_create_file(dev, &uevent_attr); error = device_create_file(dev, &uevent_attr);
...@@ -820,7 +820,7 @@ int device_add(struct device *dev) ...@@ -820,7 +820,7 @@ int device_add(struct device *dev)
dpm_sysfs_remove(dev); dpm_sysfs_remove(dev);
PMError: PMError:
if (dev->bus) if (dev->bus)
blocking_notifier_call_chain(&dev->bus->bus_notifier, blocking_notifier_call_chain(&dev->bus->p->bus_notifier,
BUS_NOTIFY_DEL_DEVICE, dev); BUS_NOTIFY_DEL_DEVICE, dev);
device_remove_attrs(dev); device_remove_attrs(dev);
AttrsError: AttrsError:
...@@ -999,7 +999,7 @@ void device_del(struct device * dev) ...@@ -999,7 +999,7 @@ void device_del(struct device * dev)
if (platform_notify_remove) if (platform_notify_remove)
platform_notify_remove(dev); platform_notify_remove(dev);
if (dev->bus) if (dev->bus)
blocking_notifier_call_chain(&dev->bus->bus_notifier, blocking_notifier_call_chain(&dev->bus->p->bus_notifier,
BUS_NOTIFY_DEL_DEVICE, dev); BUS_NOTIFY_DEL_DEVICE, dev);
kobject_uevent(&dev->kobj, KOBJ_REMOVE); kobject_uevent(&dev->kobj, KOBJ_REMOVE);
kobject_del(&dev->kobj); kobject_del(&dev->kobj);
......
...@@ -38,7 +38,7 @@ static void driver_bound(struct device *dev) ...@@ -38,7 +38,7 @@ static void driver_bound(struct device *dev)
dev->bus_id, dev->driver->name); dev->bus_id, dev->driver->name);
if (dev->bus) if (dev->bus)
blocking_notifier_call_chain(&dev->bus->bus_notifier, blocking_notifier_call_chain(&dev->bus->p->bus_notifier,
BUS_NOTIFY_BOUND_DRIVER, dev); BUS_NOTIFY_BOUND_DRIVER, dev);
klist_add_tail(&dev->knode_driver, &dev->driver->klist_devices); klist_add_tail(&dev->knode_driver, &dev->driver->klist_devices);
...@@ -296,7 +296,7 @@ static void __device_release_driver(struct device * dev) ...@@ -296,7 +296,7 @@ static void __device_release_driver(struct device * dev)
klist_remove(&dev->knode_driver); klist_remove(&dev->knode_driver);
if (dev->bus) if (dev->bus)
blocking_notifier_call_chain(&dev->bus->bus_notifier, blocking_notifier_call_chain(&dev->bus->p->bus_notifier,
BUS_NOTIFY_UNBIND_DRIVER, BUS_NOTIFY_UNBIND_DRIVER,
dev); dev);
......
...@@ -185,7 +185,7 @@ void driver_unregister(struct device_driver * drv) ...@@ -185,7 +185,7 @@ void driver_unregister(struct device_driver * drv)
*/ */
struct device_driver *driver_find(const char *name, struct bus_type *bus) struct device_driver *driver_find(const char *name, struct bus_type *bus)
{ {
struct kobject *k = kset_find_obj(bus->drivers_kset, name); struct kobject *k = kset_find_obj(bus->p->drivers_kset, name);
if (k) if (k)
return to_drv(k); return to_drv(k);
return NULL; return NULL;
......
...@@ -497,12 +497,12 @@ int __init_or_module platform_driver_probe(struct platform_driver *drv, ...@@ -497,12 +497,12 @@ int __init_or_module platform_driver_probe(struct platform_driver *drv,
* if the probe was successful, and make sure any forced probes of * if the probe was successful, and make sure any forced probes of
* new devices fail. * new devices fail.
*/ */
spin_lock(&platform_bus_type.klist_drivers.k_lock); spin_lock(&platform_bus_type.p->klist_drivers.k_lock);
drv->probe = NULL; drv->probe = NULL;
if (code == 0 && list_empty(&drv->driver.klist_devices.k_list)) if (code == 0 && list_empty(&drv->driver.klist_devices.k_list))
retval = -ENODEV; retval = -ENODEV;
drv->driver.probe = platform_drv_probe_fail; drv->driver.probe = platform_drv_probe_fail;
spin_unlock(&platform_bus_type.klist_drivers.k_lock); spin_unlock(&platform_bus_type.p->klist_drivers.k_lock);
if (code != retval) if (code != retval)
platform_driver_unregister(drv); platform_driver_unregister(drv);
......
...@@ -35,6 +35,7 @@ struct device_driver; ...@@ -35,6 +35,7 @@ struct device_driver;
struct class; struct class;
struct class_device; struct class_device;
struct bus_type; struct bus_type;
struct bus_type_private;
struct bus_attribute { struct bus_attribute {
struct attribute attr; struct attribute attr;
...@@ -51,15 +52,6 @@ extern void bus_remove_file(struct bus_type *, struct bus_attribute *); ...@@ -51,15 +52,6 @@ extern void bus_remove_file(struct bus_type *, struct bus_attribute *);
struct bus_type { struct bus_type {
const char * name; const char * name;
struct kset subsys;
struct kset *drivers_kset;
struct kset *devices_kset;
struct klist klist_devices;
struct klist klist_drivers;
struct blocking_notifier_head bus_notifier;
struct bus_attribute * bus_attrs; struct bus_attribute * bus_attrs;
struct device_attribute * dev_attrs; struct device_attribute * dev_attrs;
struct driver_attribute * drv_attrs; struct driver_attribute * drv_attrs;
...@@ -75,7 +67,7 @@ struct bus_type { ...@@ -75,7 +67,7 @@ struct bus_type {
int (*resume_early)(struct device * dev); int (*resume_early)(struct device * dev);
int (*resume)(struct device * dev); int (*resume)(struct device * dev);
unsigned int drivers_autoprobe:1; struct bus_type_private *p;
}; };
extern int __must_check bus_register(struct bus_type * bus); extern int __must_check bus_register(struct bus_type * bus);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment