From 775b64d2b6ca37697de925f70799c710aab5849a Mon Sep 17 00:00:00 2001 From: "Rafael J. Wysocki" Date: Sat, 12 Jan 2008 20:40:46 +0100 Subject: PM: Acquire device locks on suspend This patch reorganizes the way suspend and resume notifications are sent to drivers. The major changes are that now the PM core acquires every device semaphore before calling the methods, and calls to device_add() during suspends will fail, while calls to device_del() during suspends will block. It also provides a way to safely remove a suspended device with the help of the PM core, by using the device_pm_schedule_removal() callback introduced specifically for this purpose, and updates two drivers (msr and cpuid) that need to use it. Signed-off-by: Alan Stern Signed-off-by: Rafael J. Wysocki Signed-off-by: Greg Kroah-Hartman --- drivers/base/core.c | 65 +++++- drivers/base/power/main.c | 502 +++++++++++++++++++++++++++++---------------- drivers/base/power/power.h | 12 ++ 3 files changed, 399 insertions(+), 180 deletions(-) (limited to 'drivers/base') diff --git a/drivers/base/core.c b/drivers/base/core.c index 2683eac..ce6b64c 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c @@ -726,11 +726,20 @@ int device_add(struct device *dev) { struct device *parent = NULL; struct class_interface *class_intf; - int error = -EINVAL; + int error; + + error = pm_sleep_lock(); + if (error) { + dev_warn(dev, "Suspicious %s during suspend\n", __FUNCTION__); + dump_stack(); + return error; + } dev = get_device(dev); - if (!dev || !strlen(dev->bus_id)) + if (!dev || !strlen(dev->bus_id)) { + error = -EINVAL; goto Error; + } pr_debug("DEV: registering device: ID = '%s'\n", dev->bus_id); @@ -795,6 +804,7 @@ int device_add(struct device *dev) } Done: put_device(dev); + pm_sleep_unlock(); return error; BusError: device_pm_remove(dev); @@ -905,6 +915,7 @@ void device_del(struct device * dev) struct device * parent = dev->parent; struct class_interface *class_intf; + device_pm_remove(dev); if (parent) klist_del(&dev->knode_parent); if (MAJOR(dev->devt)) @@ -981,7 +992,6 @@ void device_del(struct device * dev) if (dev->bus) blocking_notifier_call_chain(&dev->bus->bus_notifier, BUS_NOTIFY_DEL_DEVICE, dev); - device_pm_remove(dev); kobject_uevent(&dev->kobj, KOBJ_REMOVE); kobject_del(&dev->kobj); if (parent) @@ -1156,14 +1166,11 @@ error: EXPORT_SYMBOL_GPL(device_create); /** - * device_destroy - removes a device that was created with device_create() + * find_device - finds a device that was created with device_create() * @class: pointer to the struct class that this device was registered with * @devt: the dev_t of the device that was previously registered - * - * This call unregisters and cleans up a device that was created with a - * call to device_create(). */ -void device_destroy(struct class *class, dev_t devt) +static struct device *find_device(struct class *class, dev_t devt) { struct device *dev = NULL; struct device *dev_tmp; @@ -1176,12 +1183,54 @@ void device_destroy(struct class *class, dev_t devt) } } up(&class->sem); + return dev; +} +/** + * device_destroy - removes a device that was created with device_create() + * @class: pointer to the struct class that this device was registered with + * @devt: the dev_t of the device that was previously registered + * + * This call unregisters and cleans up a device that was created with a + * call to device_create(). + */ +void device_destroy(struct class *class, dev_t devt) +{ + struct device *dev; + + dev = find_device(class, devt); if (dev) device_unregister(dev); } EXPORT_SYMBOL_GPL(device_destroy); +#ifdef CONFIG_PM_SLEEP +/** + * destroy_suspended_device - asks the PM core to remove a suspended device + * @class: pointer to the struct class that this device was registered with + * @devt: the dev_t of the device that was previously registered + * + * This call notifies the PM core of the necessity to unregister a suspended + * device created with a call to device_create() (devices cannot be + * unregistered directly while suspended, since the PM core holds their + * semaphores at that time). + * + * It can only be called within the scope of a system sleep transition. In + * practice this means it has to be directly or indirectly invoked either by + * a suspend or resume method, or by the PM core (e.g. via + * disable_nonboot_cpus() or enable_nonboot_cpus()). + */ +void destroy_suspended_device(struct class *class, dev_t devt) +{ + struct device *dev; + + dev = find_device(class, devt); + if (dev) + device_pm_schedule_removal(dev); +} +EXPORT_SYMBOL_GPL(destroy_suspended_device); +#endif /* CONFIG_PM_SLEEP */ + /** * device_rename - renames a device * @dev: the pointer to the struct device to be renamed diff --git a/drivers/base/power/main.c b/drivers/base/power/main.c index 691ffb6..200ed5f 100644 --- a/drivers/base/power/main.c +++ b/drivers/base/power/main.c @@ -24,20 +24,45 @@ #include #include #include +#include #include "../base.h" #include "power.h" +/* + * The entries in the dpm_active list are in a depth first order, simply + * because children are guaranteed to be discovered after parents, and + * are inserted at the back of the list on discovery. + * + * All the other lists are kept in the same order, for consistency. + * However the lists aren't always traversed in the same order. + * Semaphores must be acquired from the top (i.e., front) down + * and released in the opposite order. Devices must be suspended + * from the bottom (i.e., end) up and resumed in the opposite order. + * That way no parent will be suspended while it still has an active + * child. + * + * Since device_pm_add() may be called with a device semaphore held, + * we must never try to acquire a device semaphore while holding + * dpm_list_mutex. + */ + LIST_HEAD(dpm_active); +static LIST_HEAD(dpm_locked); static LIST_HEAD(dpm_off); static LIST_HEAD(dpm_off_irq); +static LIST_HEAD(dpm_destroy); -static DEFINE_MUTEX(dpm_mtx); static DEFINE_MUTEX(dpm_list_mtx); -int (*platform_enable_wakeup)(struct device *dev, int is_on); +static DECLARE_RWSEM(pm_sleep_rwsem); +int (*platform_enable_wakeup)(struct device *dev, int is_on); +/** + * device_pm_add - add a device to the list of active devices + * @dev: Device to be added to the list + */ void device_pm_add(struct device *dev) { pr_debug("PM: Adding info for %s:%s\n", @@ -48,8 +73,36 @@ void device_pm_add(struct device *dev) mutex_unlock(&dpm_list_mtx); } +/** + * device_pm_remove - remove a device from the list of active devices + * @dev: Device to be removed from the list + * + * This function also removes the device's PM-related sysfs attributes. + */ void device_pm_remove(struct device *dev) { + /* + * If this function is called during a suspend, it will be blocked, + * because we're holding the device's semaphore at that time, which may + * lead to a deadlock. In that case we want to print a warning. + * However, it may also be called by unregister_dropped_devices() with + * the device's semaphore released, in which case the warning should + * not be printed. + */ + if (down_trylock(&dev->sem)) { + if (down_read_trylock(&pm_sleep_rwsem)) { + /* No suspend in progress, wait on dev->sem */ + down(&dev->sem); + up_read(&pm_sleep_rwsem); + } else { + /* Suspend in progress, we may deadlock */ + dev_warn(dev, "Suspicious %s during suspend\n", + __FUNCTION__); + dump_stack(); + /* The user has been warned ... */ + down(&dev->sem); + } + } pr_debug("PM: Removing info for %s:%s\n", dev->bus ? dev->bus->name : "No Bus", kobject_name(&dev->kobj)); @@ -57,25 +110,124 @@ void device_pm_remove(struct device *dev) dpm_sysfs_remove(dev); list_del_init(&dev->power.entry); mutex_unlock(&dpm_list_mtx); + up(&dev->sem); +} + +/** + * device_pm_schedule_removal - schedule the removal of a suspended device + * @dev: Device to destroy + * + * Moves the device to the dpm_destroy list for further processing by + * unregister_dropped_devices(). + */ +void device_pm_schedule_removal(struct device *dev) +{ + pr_debug("PM: Preparing for removal: %s:%s\n", + dev->bus ? dev->bus->name : "No Bus", + kobject_name(&dev->kobj)); + mutex_lock(&dpm_list_mtx); + list_move_tail(&dev->power.entry, &dpm_destroy); + mutex_unlock(&dpm_list_mtx); +} + +/** + * pm_sleep_lock - mutual exclusion for registration and suspend + * + * Returns 0 if no suspend is underway and device registration + * may proceed, otherwise -EBUSY. + */ +int pm_sleep_lock(void) +{ + if (down_read_trylock(&pm_sleep_rwsem)) + return 0; + + return -EBUSY; +} + +/** + * pm_sleep_unlock - mutual exclusion for registration and suspend + * + * This routine undoes the effect of device_pm_add_lock + * when a device's registration is complete. + */ +void pm_sleep_unlock(void) +{ + up_read(&pm_sleep_rwsem); } /*------------------------- Resume routines -------------------------*/ /** - * resume_device - Restore state for one device. + * resume_device_early - Power on one device (early resume). * @dev: Device. * + * Must be called with interrupts disabled. */ - -static int resume_device(struct device * dev) +static int resume_device_early(struct device *dev) { int error = 0; TRACE_DEVICE(dev); TRACE_RESUME(0); - down(&dev->sem); + if (dev->bus && dev->bus->resume_early) { + dev_dbg(dev, "EARLY resume\n"); + error = dev->bus->resume_early(dev); + } + + TRACE_RESUME(error); + return error; +} + +/** + * dpm_power_up - Power on all regular (non-sysdev) devices. + * + * Walk the dpm_off_irq list and power each device up. This + * is used for devices that required they be powered down with + * interrupts disabled. As devices are powered on, they are moved + * to the dpm_off list. + * + * Must be called with interrupts disabled and only one CPU running. + */ +static void dpm_power_up(void) +{ + + while (!list_empty(&dpm_off_irq)) { + struct list_head *entry = dpm_off_irq.next; + struct device *dev = to_device(entry); + + list_move_tail(entry, &dpm_off); + resume_device_early(dev); + } +} + +/** + * device_power_up - Turn on all devices that need special attention. + * + * Power on system devices, then devices that required we shut them down + * with interrupts disabled. + * + * Must be called with interrupts disabled. + */ +void device_power_up(void) +{ + sysdev_resume(); + dpm_power_up(); +} +EXPORT_SYMBOL_GPL(device_power_up); + +/** + * resume_device - Restore state for one device. + * @dev: Device. + * + */ +static int resume_device(struct device *dev) +{ + int error = 0; + + TRACE_DEVICE(dev); + TRACE_RESUME(0); if (dev->bus && dev->bus->resume) { dev_dbg(dev,"resuming\n"); @@ -92,126 +244,94 @@ static int resume_device(struct device * dev) error = dev->class->resume(dev); } - up(&dev->sem); - TRACE_RESUME(error); return error; } - -static int resume_device_early(struct device * dev) -{ - int error = 0; - - TRACE_DEVICE(dev); - TRACE_RESUME(0); - if (dev->bus && dev->bus->resume_early) { - dev_dbg(dev,"EARLY resume\n"); - error = dev->bus->resume_early(dev); - } - TRACE_RESUME(error); - return error; -} - -/* - * Resume the devices that have either not gone through - * the late suspend, or that did go through it but also - * went through the early resume +/** + * dpm_resume - Resume every device. + * + * Resume the devices that have either not gone through + * the late suspend, or that did go through it but also + * went through the early resume. + * + * Take devices from the dpm_off_list, resume them, + * and put them on the dpm_locked list. */ static void dpm_resume(void) { mutex_lock(&dpm_list_mtx); while(!list_empty(&dpm_off)) { - struct list_head * entry = dpm_off.next; - struct device * dev = to_device(entry); - - get_device(dev); - list_move_tail(entry, &dpm_active); + struct list_head *entry = dpm_off.next; + struct device *dev = to_device(entry); + list_move_tail(entry, &dpm_locked); mutex_unlock(&dpm_list_mtx); resume_device(dev); mutex_lock(&dpm_list_mtx); - put_device(dev); } mutex_unlock(&dpm_list_mtx); } - /** - * device_resume - Restore state of each device in system. + * unlock_all_devices - Release each device's semaphore * - * Walk the dpm_off list, remove each entry, resume the device, - * then add it to the dpm_active list. + * Go through the dpm_off list. Put each device on the dpm_active + * list and unlock it. */ - -void device_resume(void) +static void unlock_all_devices(void) { - might_sleep(); - mutex_lock(&dpm_mtx); - dpm_resume(); - mutex_unlock(&dpm_mtx); -} - -EXPORT_SYMBOL_GPL(device_resume); + mutex_lock(&dpm_list_mtx); + while (!list_empty(&dpm_locked)) { + struct list_head *entry = dpm_locked.prev; + struct device *dev = to_device(entry); + list_move(entry, &dpm_active); + up(&dev->sem); + } + mutex_unlock(&dpm_list_mtx); +} /** - * dpm_power_up - Power on some devices. - * - * Walk the dpm_off_irq list and power each device up. This - * is used for devices that required they be powered down with - * interrupts disabled. As devices are powered on, they are moved - * to the dpm_active list. + * unregister_dropped_devices - Unregister devices scheduled for removal * - * Interrupts must be disabled when calling this. + * Unregister all devices on the dpm_destroy list. */ - -static void dpm_power_up(void) +static void unregister_dropped_devices(void) { - while(!list_empty(&dpm_off_irq)) { - struct list_head * entry = dpm_off_irq.next; - struct device * dev = to_device(entry); + mutex_lock(&dpm_list_mtx); + while (!list_empty(&dpm_destroy)) { + struct list_head *entry = dpm_destroy.next; + struct device *dev = to_device(entry); - list_move_tail(entry, &dpm_off); - resume_device_early(dev); + up(&dev->sem); + mutex_unlock(&dpm_list_mtx); + /* This also removes the device from the list */ + device_unregister(dev); + mutex_lock(&dpm_list_mtx); } + mutex_unlock(&dpm_list_mtx); } - /** - * device_power_up - Turn on all devices that need special attention. + * device_resume - Restore state of each device in system. * - * Power on system devices then devices that required we shut them down - * with interrupts disabled. - * Called with interrupts disabled. + * Resume all the devices, unlock them all, and allow new + * devices to be registered once again. */ - -void device_power_up(void) +void device_resume(void) { - sysdev_resume(); - dpm_power_up(); + might_sleep(); + dpm_resume(); + unlock_all_devices(); + unregister_dropped_devices(); + up_write(&pm_sleep_rwsem); } - -EXPORT_SYMBOL_GPL(device_power_up); +EXPORT_SYMBOL_GPL(device_resume); /*------------------------- Suspend routines -------------------------*/ -/* - * The entries in the dpm_active list are in a depth first order, simply - * because children are guaranteed to be discovered after parents, and - * are inserted at the back of the list on discovery. - * - * All list on the suspend path are done in reverse order, so we operate - * on the leaves of the device tree (or forests, depending on how you want - * to look at it ;) first. As nodes are removed from the back of the list, - * they are inserted into the front of their destintation lists. - * - * Things are the reverse on the resume path - iterations are done in - * forward order, and nodes are inserted at the back of their destination - * lists. This way, the ancestors will be accessed before their descendents. - */ - static inline char *suspend_verb(u32 event) { switch (event) { @@ -222,7 +342,6 @@ static inline char *suspend_verb(u32 event) } } - static void suspend_device_dbg(struct device *dev, pm_message_t state, char *info) { @@ -232,16 +351,73 @@ suspend_device_dbg(struct device *dev, pm_message_t state, char *info) } /** - * suspend_device - Save state of one device. + * suspend_device_late - Shut down one device (late suspend). * @dev: Device. * @state: Power state device is entering. + * + * This is called with interrupts off and only a single CPU running. */ +static int suspend_device_late(struct device *dev, pm_message_t state) +{ + int error = 0; -static int suspend_device(struct device * dev, pm_message_t state) + if (dev->bus && dev->bus->suspend_late) { + suspend_device_dbg(dev, state, "LATE "); + error = dev->bus->suspend_late(dev, state); + suspend_report_result(dev->bus->suspend_late, error); + } + return error; +} + +/** + * device_power_down - Shut down special devices. + * @state: Power state to enter. + * + * Power down devices that require interrupts to be disabled + * and move them from the dpm_off list to the dpm_off_irq list. + * Then power down system devices. + * + * Must be called with interrupts disabled and only one CPU running. + */ +int device_power_down(pm_message_t state) +{ + int error = 0; + + while (!list_empty(&dpm_off)) { + struct list_head *entry = dpm_off.prev; + struct device *dev = to_device(entry); + + list_del_init(&dev->power.entry); + error = suspend_device_late(dev, state); + if (error) { + printk(KERN_ERR "Could not power down device %s: " + "error %d\n", + kobject_name(&dev->kobj), error); + if (list_empty(&dev->power.entry)) + list_add(&dev->power.entry, &dpm_off); + break; + } + if (list_empty(&dev->power.entry)) + list_add(&dev->power.entry, &dpm_off_irq); + } + + if (!error) + error = sysdev_suspend(state); + if (error) + dpm_power_up(); + return error; +} +EXPORT_SYMBOL_GPL(device_power_down); + +/** + * suspend_device - Save state of one device. + * @dev: Device. + * @state: Power state device is entering. + */ +int suspend_device(struct device *dev, pm_message_t state) { int error = 0; - down(&dev->sem); if (dev->power.power_state.event) { dev_dbg(dev, "PM: suspend %d-->%d\n", dev->power.power_state.event, state.event); @@ -264,123 +440,105 @@ static int suspend_device(struct device * dev, pm_message_t state) error = dev->bus->suspend(dev, state); suspend_report_result(dev->bus->suspend, error); } - up(&dev->sem); - return error; -} - - -/* - * This is called with interrupts off, only a single CPU - * running. We can't acquire a mutex or semaphore (and we don't - * need the protection) - */ -static int suspend_device_late(struct device *dev, pm_message_t state) -{ - int error = 0; - - if (dev->bus && dev->bus->suspend_late) { - suspend_device_dbg(dev, state, "LATE "); - error = dev->bus->suspend_late(dev, state); - suspend_report_result(dev->bus->suspend_late, error); - } return error; } /** - * device_suspend - Save state and stop all devices in system. - * @state: Power state to put each device in. + * dpm_suspend - Suspend every device. + * @state: Power state to put each device in. * - * Walk the dpm_active list, call ->suspend() for each device, and move - * it to the dpm_off list. + * Walk the dpm_locked list. Suspend each device and move it + * to the dpm_off list. * * (For historical reasons, if it returns -EAGAIN, that used to mean * that the device would be called again with interrupts disabled. * These days, we use the "suspend_late()" callback for that, so we * print a warning and consider it an error). - * - * If we get a different error, try and back out. - * - * If we hit a failure with any of the devices, call device_resume() - * above to bring the suspended devices back to life. - * */ - -int device_suspend(pm_message_t state) +static int dpm_suspend(pm_message_t state) { int error = 0; - might_sleep(); - mutex_lock(&dpm_mtx); mutex_lock(&dpm_list_mtx); - while (!list_empty(&dpm_active) && error == 0) { - struct list_head * entry = dpm_active.prev; - struct device * dev = to_device(entry); + while (!list_empty(&dpm_locked)) { + struct list_head *entry = dpm_locked.prev; + struct device *dev = to_device(entry); - get_device(dev); + list_del_init(&dev->power.entry); mutex_unlock(&dpm_list_mtx); - error = suspend_device(dev, state); - - mutex_lock(&dpm_list_mtx); - - /* Check if the device got removed */ - if (!list_empty(&dev->power.entry)) { - /* Move it to the dpm_off list */ - if (!error) - list_move(&dev->power.entry, &dpm_off); - } - if (error) + if (error) { printk(KERN_ERR "Could not suspend device %s: " - "error %d%s\n", - kobject_name(&dev->kobj), error, - error == -EAGAIN ? " (please convert to suspend_late)" : ""); - put_device(dev); + "error %d%s\n", + kobject_name(&dev->kobj), + error, + (error == -EAGAIN ? + " (please convert to suspend_late)" : + "")); + mutex_lock(&dpm_list_mtx); + if (list_empty(&dev->power.entry)) + list_add(&dev->power.entry, &dpm_locked); + mutex_unlock(&dpm_list_mtx); + break; + } + mutex_lock(&dpm_list_mtx); + if (list_empty(&dev->power.entry)) + list_add(&dev->power.entry, &dpm_off); } mutex_unlock(&dpm_list_mtx); - if (error) - dpm_resume(); - mutex_unlock(&dpm_mtx); return error; } -EXPORT_SYMBOL_GPL(device_suspend); - /** - * device_power_down - Shut down special devices. - * @state: Power state to enter. + * lock_all_devices - Acquire every device's semaphore * - * Walk the dpm_off_irq list, calling ->power_down() for each device that - * couldn't power down the device with interrupts enabled. When we're - * done, power down system devices. + * Go through the dpm_active list. Carefully lock each device's + * semaphore and put it in on the dpm_locked list. */ - -int device_power_down(pm_message_t state) +static void lock_all_devices(void) { - int error = 0; - struct device * dev; + mutex_lock(&dpm_list_mtx); + while (!list_empty(&dpm_active)) { + struct list_head *entry = dpm_active.next; + struct device *dev = to_device(entry); - while (!list_empty(&dpm_off)) { - struct list_head * entry = dpm_off.prev; + /* Required locking order is dev->sem first, + * then dpm_list_mutex. Hence this awkward code. + */ + get_device(dev); + mutex_unlock(&dpm_list_mtx); + down(&dev->sem); + mutex_lock(&dpm_list_mtx); - dev = to_device(entry); - error = suspend_device_late(dev, state); - if (error) - goto Error; - list_move(&dev->power.entry, &dpm_off_irq); + if (list_empty(entry)) + up(&dev->sem); /* Device was removed */ + else + list_move_tail(entry, &dpm_locked); + put_device(dev); } + mutex_unlock(&dpm_list_mtx); +} + +/** + * device_suspend - Save state and stop all devices in system. + * + * Prevent new devices from being registered, then lock all devices + * and suspend them. + */ +int device_suspend(pm_message_t state) +{ + int error; - error = sysdev_suspend(state); - Done: + might_sleep(); + down_write(&pm_sleep_rwsem); + lock_all_devices(); + error = dpm_suspend(state); + if (error) + device_resume(); return error; - Error: - printk(KERN_ERR "Could not power down device %s: " - "error %d\n", kobject_name(&dev->kobj), error); - dpm_power_up(); - goto Done; } - -EXPORT_SYMBOL_GPL(device_power_down); +EXPORT_SYMBOL_GPL(device_suspend); void __suspend_report_result(const char *function, void *fn, int ret) { diff --git a/drivers/base/power/power.h b/drivers/base/power/power.h index 379da4e..10c2084 100644 --- a/drivers/base/power/power.h +++ b/drivers/base/power/power.h @@ -20,6 +20,9 @@ static inline struct device *to_device(struct list_head *entry) extern void device_pm_add(struct device *); extern void device_pm_remove(struct device *); +extern void device_pm_schedule_removal(struct device *); +extern int pm_sleep_lock(void); +extern void pm_sleep_unlock(void); #else /* CONFIG_PM_SLEEP */ @@ -32,6 +35,15 @@ static inline void device_pm_remove(struct device *dev) { } +static inline int pm_sleep_lock(void) +{ + return 0; +} + +static inline void pm_sleep_unlock(void) +{ +} + #endif #ifdef CONFIG_PM -- cgit v1.1 From 3514faca19a6fdc209734431c509631ea92b094e Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Tue, 16 Oct 2007 10:11:44 -0600 Subject: kobject: remove struct kobj_type from struct kset We don't need a "default" ktype for a kset. We should set this explicitly every time for each kset. This change is needed so that we can make ksets dynamic, and cleans up one of the odd, undocumented assumption that the kset/kobject/ktype model has. This patch is based on a lot of help from Kay Sievers. Nasty bug in the block code was found by Dave Young Cc: Kay Sievers Cc: Dave Young Signed-off-by: Greg Kroah-Hartman --- drivers/base/bus.c | 5 +++-- drivers/base/class.c | 8 +++++--- drivers/base/core.c | 5 +++-- drivers/base/firmware.c | 5 +++-- drivers/base/hypervisor.c | 2 +- drivers/base/sys.c | 3 ++- 6 files changed, 17 insertions(+), 11 deletions(-) (limited to 'drivers/base') diff --git a/drivers/base/bus.c b/drivers/base/bus.c index 9a19b07..6309560 100644 --- a/drivers/base/bus.c +++ b/drivers/base/bus.c @@ -166,7 +166,7 @@ static struct kset_uevent_ops bus_uevent_ops = { .filter = bus_uevent_filter, }; -static decl_subsys(bus, &bus_ktype, &bus_uevent_ops); +static decl_subsys(bus, &bus_uevent_ops); #ifdef CONFIG_HOTPLUG @@ -639,6 +639,7 @@ int bus_add_driver(struct device_driver *drv) if (error) goto out_put_bus; drv->kobj.kset = &bus->drivers; + drv->kobj.ktype = &driver_ktype; error = kobject_register(&drv->kobj); if (error) goto out_put_bus; @@ -851,6 +852,7 @@ int bus_register(struct bus_type * bus) goto out; bus->subsys.kobj.kset = &bus_subsys; + bus->subsys.kobj.ktype = &bus_ktype; retval = subsystem_register(&bus->subsys); if (retval) @@ -868,7 +870,6 @@ int bus_register(struct bus_type * bus) kobject_set_name(&bus->drivers.kobj, "drivers"); bus->drivers.kobj.parent = &bus->subsys.kobj; - bus->drivers.ktype = &driver_ktype; retval = kset_register(&bus->drivers); if (retval) goto bus_drivers_fail; diff --git a/drivers/base/class.c b/drivers/base/class.c index a863bb0..8ad9892 100644 --- a/drivers/base/class.c +++ b/drivers/base/class.c @@ -71,7 +71,7 @@ static struct kobj_type class_ktype = { }; /* Hotplug events for classes go to the class_obj subsys */ -static decl_subsys(class, &class_ktype, NULL); +static decl_subsys(class, NULL); int class_create_file(struct class * cls, const struct class_attribute * attr) @@ -150,6 +150,7 @@ int class_register(struct class * cls) return error; cls->subsys.kobj.kset = &class_subsys; + cls->subsys.kobj.ktype = &class_ktype; error = subsystem_register(&cls->subsys); if (!error) { @@ -452,7 +453,7 @@ static struct kset_uevent_ops class_uevent_ops = { .uevent = class_uevent, }; -static decl_subsys(class_obj, &class_device_ktype, &class_uevent_ops); +static decl_subsys(class_obj, &class_uevent_ops); static int class_device_add_attrs(struct class_device * cd) @@ -537,7 +538,8 @@ static struct class_device_attribute class_uevent_attr = void class_device_initialize(struct class_device *class_dev) { - kobj_set_kset_s(class_dev, class_obj_subsys); + class_dev->kobj.kset = &class_obj_subsys; + class_dev->kobj.ktype = &class_device_ktype; kobject_init(&class_dev->kobj); INIT_LIST_HEAD(&class_dev->node); } diff --git a/drivers/base/core.c b/drivers/base/core.c index ce6b64c..c8f2ac0 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c @@ -405,7 +405,7 @@ static struct device_attribute devt_attr = * devices_subsys - structure to be registered with kobject core. */ -decl_subsys(devices, &device_ktype, &device_uevent_ops); +decl_subsys(devices, &device_uevent_ops); /** @@ -525,7 +525,8 @@ static void klist_children_put(struct klist_node *n) void device_initialize(struct device *dev) { - kobj_set_kset_s(dev, devices_subsys); + dev->kobj.kset = &devices_subsys; + dev->kobj.ktype = &device_ktype; kobject_init(&dev->kobj); klist_init(&dev->klist_children, klist_children_get, klist_children_put); diff --git a/drivers/base/firmware.c b/drivers/base/firmware.c index 90c8629..336be04 100644 --- a/drivers/base/firmware.c +++ b/drivers/base/firmware.c @@ -15,11 +15,12 @@ #include "base.h" -static decl_subsys(firmware, NULL, NULL); +static decl_subsys(firmware, NULL); int firmware_register(struct kset *s) { - kobj_set_kset_s(s, firmware_subsys); + s->kobj.kset = &firmware_subsys; + s->kobj.ktype = NULL; return subsystem_register(s); } diff --git a/drivers/base/hypervisor.c b/drivers/base/hypervisor.c index 7080b41..14e75e9 100644 --- a/drivers/base/hypervisor.c +++ b/drivers/base/hypervisor.c @@ -11,7 +11,7 @@ #include "base.h" -decl_subsys(hypervisor, NULL, NULL); +decl_subsys(hypervisor, NULL); EXPORT_SYMBOL_GPL(hypervisor_subsys); int __init hypervisor_init(void) diff --git a/drivers/base/sys.c b/drivers/base/sys.c index ac7ff6d..7cf19fc 100644 --- a/drivers/base/sys.c +++ b/drivers/base/sys.c @@ -131,7 +131,7 @@ EXPORT_SYMBOL_GPL(sysdev_class_remove_file); /* * declare system_subsys */ -static decl_subsys(system, &ktype_sysdev_class, NULL); +static decl_subsys(system, NULL); int sysdev_class_register(struct sysdev_class * cls) { @@ -139,6 +139,7 @@ int sysdev_class_register(struct sysdev_class * cls) kobject_name(&cls->kset.kobj)); INIT_LIST_HEAD(&cls->drivers); cls->kset.kobj.parent = &system_subsys.kobj; + cls->kset.kobj.ktype = &ktype_sysdev_class; cls->kset.kobj.kset = &system_subsys; return kset_register(&cls->kset); } -- cgit v1.1 From 4ff6abff832fbc6cb1d769f6106c841bc2b09f63 Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Mon, 5 Nov 2007 22:24:43 -0800 Subject: kobject: get rid of kobject_add_dir kobject_create_and_add is the same as kobject_add_dir, so drop kobject_add_dir. Cc: Kay Sievers Signed-off-by: Greg Kroah-Hartman --- drivers/base/core.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'drivers/base') diff --git a/drivers/base/core.c b/drivers/base/core.c index c8f2ac0..992eba3 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c @@ -562,7 +562,8 @@ static struct kobject *virtual_device_parent(struct device *dev) static struct kobject *virtual_dir = NULL; if (!virtual_dir) - virtual_dir = kobject_add_dir(&devices_subsys.kobj, "virtual"); + virtual_dir = kobject_create_and_add("virtual", + &devices_subsys.kobj); return virtual_dir; } -- cgit v1.1 From 43968d2f1648f4dc92437dc0363a3e88377445b3 Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Mon, 5 Nov 2007 22:24:43 -0800 Subject: kobject: get rid of kobject_kset_add_dir kobject_kset_add_dir is only called in one place so remove it and use kobject_create() instead. Cc: Kay Sievers Signed-off-by: Greg Kroah-Hartman --- drivers/base/core.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'drivers/base') diff --git a/drivers/base/core.c b/drivers/base/core.c index 992eba3..7762ee8 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c @@ -571,6 +571,8 @@ static struct kobject *virtual_device_parent(struct device *dev) static struct kobject * get_device_parent(struct device *dev, struct device *parent) { + int retval; + if (dev->class) { struct kobject *kobj = NULL; struct kobject *parent_kobj; @@ -600,8 +602,18 @@ static struct kobject * get_device_parent(struct device *dev, return kobj; /* or create a new class-directory at the parent device */ - return kobject_kset_add_dir(&dev->class->class_dirs, - parent_kobj, dev->class->name); + k = kobject_create(); + if (!k) + return NULL; + k->kset = &dev->class->class_dirs; + retval = kobject_add_ng(k, parent_kobj, "%s", dev->class->name); + if (retval < 0) { + kobject_put(k); + return NULL; + } + /* Do not emit a uevent, as it's not needed for this + * "class glue" directory. */ + return k; } if (parent) -- cgit v1.1 From 59a548338ac6c9d7549c54278d0f724088585928 Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Mon, 29 Oct 2007 23:22:26 -0500 Subject: kset: convert drivers/base/bus.c to use kset_create Dynamically create the kset instead of declaring it statically. Cc: Kay Sievers Signed-off-by: Greg Kroah-Hartman --- drivers/base/bus.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'drivers/base') diff --git a/drivers/base/bus.c b/drivers/base/bus.c index 6309560..e3b1010 100644 --- a/drivers/base/bus.c +++ b/drivers/base/bus.c @@ -166,7 +166,7 @@ static struct kset_uevent_ops bus_uevent_ops = { .filter = bus_uevent_filter, }; -static decl_subsys(bus, &bus_uevent_ops); +static struct kset *bus_kset; #ifdef CONFIG_HOTPLUG @@ -767,7 +767,7 @@ EXPORT_SYMBOL_GPL(device_reprobe); #if 0 struct bus_type * find_bus(char * name) { - struct kobject * k = kset_find_obj(&bus_subsys.kset, name); + struct kobject * k = kset_find_obj(bus_kset, name); return k ? to_bus(k) : NULL; } #endif /* 0 */ @@ -851,7 +851,7 @@ int bus_register(struct bus_type * bus) if (retval) goto out; - bus->subsys.kobj.kset = &bus_subsys; + bus->subsys.kobj.kset = bus_kset; bus->subsys.kobj.ktype = &bus_ktype; retval = subsystem_register(&bus->subsys); @@ -935,7 +935,10 @@ EXPORT_SYMBOL_GPL(bus_unregister_notifier); int __init buses_init(void) { - return subsystem_register(&bus_subsys); + bus_kset = kset_create_and_add("bus", &bus_uevent_ops, NULL); + if (!bus_kset) + return -ENOMEM; + return 0; } -- cgit v1.1 From 443dbf9007854ef2892226615e23b60a35b89697 Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Mon, 29 Oct 2007 23:22:26 -0500 Subject: kset: convert drivers/base/class.c to use kset_create Dynamically create the kset instead of declaring it statically. The class_obj subsystem is not yet converted as it is more complex and should be going away soon with the removal of class_device from the kernel tree. Cc: Kay Sievers Signed-off-by: Greg Kroah-Hartman --- drivers/base/class.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) (limited to 'drivers/base') diff --git a/drivers/base/class.c b/drivers/base/class.c index 8ad9892..d8a92c6 100644 --- a/drivers/base/class.c +++ b/drivers/base/class.c @@ -71,7 +71,7 @@ static struct kobj_type class_ktype = { }; /* Hotplug events for classes go to the class_obj subsys */ -static decl_subsys(class, NULL); +static struct kset *class_kset; int class_create_file(struct class * cls, const struct class_attribute * attr) @@ -149,7 +149,7 @@ int class_register(struct class * cls) if (error) return error; - cls->subsys.kobj.kset = &class_subsys; + cls->subsys.kobj.kset = class_kset; cls->subsys.kobj.ktype = &class_ktype; error = subsystem_register(&cls->subsys); @@ -855,11 +855,9 @@ void class_interface_unregister(struct class_interface *class_intf) int __init classes_init(void) { - int retval; - - retval = subsystem_register(&class_subsys); - if (retval) - return retval; + class_kset = kset_create_and_add("class", NULL, NULL); + if (!class_kset) + return -ENOMEM; /* ick, this is ugly, the things we go through to keep from showing up * in sysfs... */ -- cgit v1.1 From b0d78e5549b44b3d64bf8b3ffe95280025ed102e Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Mon, 29 Oct 2007 23:22:26 -0500 Subject: kset: convert drivers/base/firmware.c to use kset_create Dynamically create the kset instead of declaring it statically. Cc: Kay Sievers Signed-off-by: Greg Kroah-Hartman --- drivers/base/firmware.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'drivers/base') diff --git a/drivers/base/firmware.c b/drivers/base/firmware.c index 336be04..6a4e494 100644 --- a/drivers/base/firmware.c +++ b/drivers/base/firmware.c @@ -15,11 +15,11 @@ #include "base.h" -static decl_subsys(firmware, NULL); +static struct kset *firmware_kset; int firmware_register(struct kset *s) { - s->kobj.kset = &firmware_subsys; + s->kobj.kset = firmware_kset; s->kobj.ktype = NULL; return subsystem_register(s); } @@ -31,7 +31,10 @@ void firmware_unregister(struct kset *s) int __init firmware_init(void) { - return subsystem_register(&firmware_subsys); + firmware_kset = kset_create_and_add("firmware", NULL, NULL); + if (!firmware_kset) + return -ENOMEM; + return 0; } EXPORT_SYMBOL_GPL(firmware_register); -- cgit v1.1 From 881c6cfd7c5edfe6129006e2404654bfe5911050 Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Thu, 1 Nov 2007 09:29:06 -0600 Subject: kset: convert /sys/devices to use kset_create Dynamically create the kset instead of declaring it statically. We also rename devices_subsys to devices_kset to catch all users of the variable. Cc: Kay Sievers Signed-off-by: Greg Kroah-Hartman --- drivers/base/base.h | 2 +- drivers/base/core.c | 16 ++++++++-------- drivers/base/power/shutdown.c | 2 +- drivers/base/sys.c | 4 +--- 4 files changed, 11 insertions(+), 13 deletions(-) (limited to 'drivers/base') diff --git a/drivers/base/base.h b/drivers/base/base.h index 10b2fb6..7e309a4 100644 --- a/drivers/base/base.h +++ b/drivers/base/base.h @@ -44,4 +44,4 @@ extern char *make_class_name(const char *name, struct kobject *kobj); extern int devres_release_all(struct device *dev); -extern struct kset devices_subsys; +extern struct kset *devices_kset; diff --git a/drivers/base/core.c b/drivers/base/core.c index 7762ee8..d2de2d5 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c @@ -401,11 +401,8 @@ static ssize_t show_dev(struct device *dev, struct device_attribute *attr, static struct device_attribute devt_attr = __ATTR(dev, S_IRUGO, show_dev, NULL); -/* - * devices_subsys - structure to be registered with kobject core. - */ - -decl_subsys(devices, &device_uevent_ops); +/* kset to create /sys/devices/ */ +struct kset *devices_kset; /** @@ -525,7 +522,7 @@ static void klist_children_put(struct klist_node *n) void device_initialize(struct device *dev) { - dev->kobj.kset = &devices_subsys; + dev->kobj.kset = devices_kset; dev->kobj.ktype = &device_ktype; kobject_init(&dev->kobj); klist_init(&dev->klist_children, klist_children_get, @@ -563,7 +560,7 @@ static struct kobject *virtual_device_parent(struct device *dev) if (!virtual_dir) virtual_dir = kobject_create_and_add("virtual", - &devices_subsys.kobj); + &devices_kset->kobj); return virtual_dir; } @@ -1097,7 +1094,10 @@ struct device * device_find_child(struct device *parent, void *data, int __init devices_init(void) { - return subsystem_register(&devices_subsys); + devices_kset = kset_create_and_add("devices", &device_uevent_ops, NULL); + if (!devices_kset) + return -ENOMEM; + return 0; } EXPORT_SYMBOL_GPL(device_for_each_child); diff --git a/drivers/base/power/shutdown.c b/drivers/base/power/shutdown.c index 56e8eaa..f51cbc1d 100644 --- a/drivers/base/power/shutdown.c +++ b/drivers/base/power/shutdown.c @@ -34,7 +34,7 @@ void device_shutdown(void) { struct device * dev, *devn; - list_for_each_entry_safe_reverse(dev, devn, &devices_subsys.list, + list_for_each_entry_safe_reverse(dev, devn, &devices_kset->list, kobj.entry) { if (dev->bus && dev->bus->shutdown) { dev_dbg(dev, "shutdown\n"); diff --git a/drivers/base/sys.c b/drivers/base/sys.c index 7cf19fc..7693c95 100644 --- a/drivers/base/sys.c +++ b/drivers/base/sys.c @@ -25,8 +25,6 @@ #include "base.h" -extern struct kset devices_subsys; - #define to_sysdev(k) container_of(k, struct sys_device, kobj) #define to_sysdev_attr(a) container_of(a, struct sysdev_attribute, attr) @@ -459,7 +457,7 @@ int sysdev_resume(void) int __init system_bus_init(void) { - system_subsys.kobj.parent = &devices_subsys.kobj; + system_subsys.kobj.parent = &devices_kset->kobj; return subsystem_register(&system_subsys); } -- cgit v1.1 From 2d72fc00a1fb055e6127ccd30cac3f0eafaa98d0 Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Thu, 1 Nov 2007 09:29:06 -0600 Subject: kobject: convert /sys/hypervisor to use kobject_create We don't need a kset here, a simple kobject will do just fine, so dynamically create the kobject and use it. We also rename hypervisor_subsys to hypervisor_kset to catch all users of the variable. Cc: Kay Sievers Signed-off-by: Greg Kroah-Hartman --- drivers/base/hypervisor.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'drivers/base') diff --git a/drivers/base/hypervisor.c b/drivers/base/hypervisor.c index 14e75e9..6428cba 100644 --- a/drivers/base/hypervisor.c +++ b/drivers/base/hypervisor.c @@ -2,19 +2,23 @@ * hypervisor.c - /sys/hypervisor subsystem. * * Copyright (C) IBM Corp. 2006 + * Copyright (C) 2007 Greg Kroah-Hartman + * Copyright (C) 2007 Novell Inc. * * This file is released under the GPLv2 */ #include #include - #include "base.h" -decl_subsys(hypervisor, NULL); -EXPORT_SYMBOL_GPL(hypervisor_subsys); +struct kobject *hypervisor_kobj; +EXPORT_SYMBOL_GPL(hypervisor_kobj); int __init hypervisor_init(void) { - return subsystem_register(&hypervisor_subsys); + hypervisor_kobj = kobject_create_and_add("hypervisor", NULL); + if (!hypervisor_kobj) + return -ENOMEM; + return 0; } -- cgit v1.1 From aade4041aa60a3ed335391ba308458e26f2dbc0a Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Thu, 1 Nov 2007 09:29:06 -0600 Subject: kset: convert /sys/devices/system to use kset_create Dynamically create the kset instead of declaring it statically. Cc: Kay Sievers Signed-off-by: Greg Kroah-Hartman --- drivers/base/sys.c | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) (limited to 'drivers/base') diff --git a/drivers/base/sys.c b/drivers/base/sys.c index 7693c95..29eadc6 100644 --- a/drivers/base/sys.c +++ b/drivers/base/sys.c @@ -126,19 +126,16 @@ void sysdev_class_remove_file(struct sysdev_class *c, } EXPORT_SYMBOL_GPL(sysdev_class_remove_file); -/* - * declare system_subsys - */ -static decl_subsys(system, NULL); +static struct kset *system_kset; int sysdev_class_register(struct sysdev_class * cls) { pr_debug("Registering sysdev class '%s'\n", kobject_name(&cls->kset.kobj)); INIT_LIST_HEAD(&cls->drivers); - cls->kset.kobj.parent = &system_subsys.kobj; + cls->kset.kobj.parent = &system_kset->kobj; cls->kset.kobj.ktype = &ktype_sysdev_class; - cls->kset.kobj.kset = &system_subsys; + cls->kset.kobj.kset = system_kset; return kset_register(&cls->kset); } @@ -297,8 +294,7 @@ void sysdev_shutdown(void) pr_debug("Shutting Down System Devices\n"); mutex_lock(&sysdev_drivers_lock); - list_for_each_entry_reverse(cls, &system_subsys.list, - kset.kobj.entry) { + list_for_each_entry_reverse(cls, &system_kset->list, kset.kobj.entry) { struct sys_device * sysdev; pr_debug("Shutting down type '%s':\n", @@ -360,9 +356,7 @@ int sysdev_suspend(pm_message_t state) pr_debug("Suspending System Devices\n"); - list_for_each_entry_reverse(cls, &system_subsys.list, - kset.kobj.entry) { - + list_for_each_entry_reverse(cls, &system_kset->list, kset.kobj.entry) { pr_debug("Suspending type '%s':\n", kobject_name(&cls->kset.kobj)); @@ -413,8 +407,7 @@ aux_driver: } /* resume other classes */ - list_for_each_entry_continue(cls, &system_subsys.list, - kset.kobj.entry) { + list_for_each_entry_continue(cls, &system_kset->list, kset.kobj.entry) { list_for_each_entry(err_dev, &cls->kset.list, kobj.entry) { pr_debug(" %s\n", kobject_name(&err_dev->kobj)); __sysdev_resume(err_dev); @@ -439,7 +432,7 @@ int sysdev_resume(void) pr_debug("Resuming System Devices\n"); - list_for_each_entry(cls, &system_subsys.list, kset.kobj.entry) { + list_for_each_entry(cls, &system_kset->list, kset.kobj.entry) { struct sys_device * sysdev; pr_debug("Resuming type '%s':\n", @@ -457,8 +450,10 @@ int sysdev_resume(void) int __init system_bus_init(void) { - system_subsys.kobj.parent = &devices_kset->kobj; - return subsystem_register(&system_subsys); + system_kset = kset_create_and_add("system", NULL, &devices_kset->kobj); + if (!system_kset) + return -ENOMEM; + return 0; } EXPORT_SYMBOL_GPL(sysdev_register); -- cgit v1.1 From 3d8995963dfec66ef6270e729bf75903e9043f9d Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Thu, 1 Nov 2007 13:31:26 -0700 Subject: kset: convert struct bus_device->devices to use kset_create Dynamically create the kset instead of declaring it statically. Having 3 static kobjects in one structure is not only foolish, but ripe for nasty race conditions if handled improperly. We also rename the field to catch any potential users of it (not that there should be outside of the driver core...) Cc: Kay Sievers Signed-off-by: Greg Kroah-Hartman --- drivers/base/bus.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) (limited to 'drivers/base') diff --git a/drivers/base/bus.c b/drivers/base/bus.c index e3b1010..b23eeb2 100644 --- a/drivers/base/bus.c +++ b/drivers/base/bus.c @@ -449,7 +449,7 @@ int bus_add_device(struct device * dev) error = device_add_attrs(bus, dev); if (error) goto out_put; - error = sysfs_create_link(&bus->devices.kobj, + error = sysfs_create_link(&bus->devices_kset->kobj, &dev->kobj, dev->bus_id); if (error) goto out_id; @@ -466,7 +466,7 @@ int bus_add_device(struct device * dev) out_deprecated: sysfs_remove_link(&dev->kobj, "subsystem"); out_subsys: - sysfs_remove_link(&bus->devices.kobj, dev->bus_id); + sysfs_remove_link(&bus->devices_kset->kobj, dev->bus_id); out_id: device_remove_attrs(bus, dev); out_put: @@ -512,7 +512,7 @@ void bus_remove_device(struct device * dev) if (dev->bus) { sysfs_remove_link(&dev->kobj, "subsystem"); remove_deprecated_bus_links(dev); - sysfs_remove_link(&dev->bus->devices.kobj, dev->bus_id); + sysfs_remove_link(&dev->bus->devices_kset->kobj, dev->bus_id); device_remove_attrs(dev->bus, dev); if (dev->is_registered) { dev->is_registered = 0; @@ -862,11 +862,12 @@ int bus_register(struct bus_type * bus) if (retval) goto bus_uevent_fail; - kobject_set_name(&bus->devices.kobj, "devices"); - bus->devices.kobj.parent = &bus->subsys.kobj; - retval = kset_register(&bus->devices); - if (retval) + bus->devices_kset = kset_create_and_add("devices", NULL, + &bus->subsys.kobj); + if (!bus->devices_kset) { + retval = -ENOMEM; goto bus_devices_fail; + } kobject_set_name(&bus->drivers.kobj, "drivers"); bus->drivers.kobj.parent = &bus->subsys.kobj; @@ -894,7 +895,7 @@ bus_attrs_fail: bus_probe_files_fail: kset_unregister(&bus->drivers); bus_drivers_fail: - kset_unregister(&bus->devices); + kset_unregister(bus->devices_kset); bus_devices_fail: bus_remove_file(bus, &bus_attr_uevent); bus_uevent_fail: @@ -916,7 +917,7 @@ void bus_unregister(struct bus_type * bus) bus_remove_attrs(bus); remove_probe_files(bus); kset_unregister(&bus->drivers); - kset_unregister(&bus->devices); + kset_unregister(bus->devices_kset); bus_remove_file(bus, &bus_attr_uevent); subsystem_unregister(&bus->subsys); } -- cgit v1.1 From 6dcec2511ff55b4abaca7ad3433011a7c04c2430 Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Thu, 1 Nov 2007 13:31:26 -0700 Subject: kset: convert struct bus_device->drivers to use kset_create Dynamically create the kset instead of declaring it statically. Having 3 static kobjects in one structure is not only foolish, but ripe for nasty race conditions if handled improperly. We also rename the field to catch any potential users of it (not that there should be outside of the driver core...) Cc: Kay Sievers Signed-off-by: Greg Kroah-Hartman --- drivers/base/bus.c | 15 ++++++++------- drivers/base/driver.c | 2 +- 2 files changed, 9 insertions(+), 8 deletions(-) (limited to 'drivers/base') diff --git a/drivers/base/bus.c b/drivers/base/bus.c index b23eeb2..6796d3e 100644 --- a/drivers/base/bus.c +++ b/drivers/base/bus.c @@ -638,7 +638,7 @@ int bus_add_driver(struct device_driver *drv) error = kobject_set_name(&drv->kobj, "%s", drv->name); if (error) goto out_put_bus; - drv->kobj.kset = &bus->drivers; + drv->kobj.kset = bus->drivers_kset; drv->kobj.ktype = &driver_ktype; error = kobject_register(&drv->kobj); if (error) @@ -869,11 +869,12 @@ int bus_register(struct bus_type * bus) goto bus_devices_fail; } - kobject_set_name(&bus->drivers.kobj, "drivers"); - bus->drivers.kobj.parent = &bus->subsys.kobj; - retval = kset_register(&bus->drivers); - if (retval) + bus->drivers_kset = kset_create_and_add("drivers", NULL, + &bus->subsys.kobj); + if (!bus->drivers_kset) { + retval = -ENOMEM; goto bus_drivers_fail; + } klist_init(&bus->klist_devices, klist_devices_get, klist_devices_put); klist_init(&bus->klist_drivers, NULL, NULL); @@ -893,7 +894,7 @@ int bus_register(struct bus_type * bus) bus_attrs_fail: remove_probe_files(bus); bus_probe_files_fail: - kset_unregister(&bus->drivers); + kset_unregister(bus->drivers_kset); bus_drivers_fail: kset_unregister(bus->devices_kset); bus_devices_fail: @@ -916,7 +917,7 @@ void bus_unregister(struct bus_type * bus) pr_debug("bus %s: unregistering\n", bus->name); bus_remove_attrs(bus); remove_probe_files(bus); - kset_unregister(&bus->drivers); + kset_unregister(bus->drivers_kset); kset_unregister(bus->devices_kset); bus_remove_file(bus, &bus_attr_uevent); subsystem_unregister(&bus->subsys); diff --git a/drivers/base/driver.c b/drivers/base/driver.c index eb11475..1c9770d 100644 --- a/drivers/base/driver.c +++ b/drivers/base/driver.c @@ -185,7 +185,7 @@ void driver_unregister(struct device_driver * drv) */ struct device_driver *driver_find(const char *name, struct bus_type *bus) { - struct kobject *k = kset_find_obj(&bus->drivers, name); + struct kobject *k = kset_find_obj(bus->drivers_kset, name); if (k) return to_drv(k); return NULL; -- cgit v1.1 From 9e5f7f9abe18a4f134585a2de016974cbda80539 Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Fri, 2 Nov 2007 13:20:40 -0700 Subject: firmware: export firmware_kset so that people can use that instead of the braindead firmware_register interface Needed for future firmware subsystem cleanups. In the end, the firmware_register/unregister functions will be deleted entirely, but we need this symbol so that subsystems can migrate over. Cc: Kay Sievers Cc: Matt Domsch Cc: Matt Tolentino Signed-off-by: Greg Kroah-Hartman --- drivers/base/firmware.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'drivers/base') diff --git a/drivers/base/firmware.c b/drivers/base/firmware.c index 6a4e494..c7f635b 100644 --- a/drivers/base/firmware.c +++ b/drivers/base/firmware.c @@ -15,7 +15,8 @@ #include "base.h" -static struct kset *firmware_kset; +struct kset *firmware_kset; +EXPORT_SYMBOL_GPL(firmware_kset); int firmware_register(struct kset *s) { -- cgit v1.1 From 15f2f9b3a9db65aaf908fe7ee17bbe262ae3550f Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Fri, 2 Nov 2007 16:19:59 -0700 Subject: firmware: remove firmware_(un)register() These functions are no longer called or needed, so we can remove them. As I rewrote the whole firmware.c file, add my copyright. Cc: Kay Sievers Signed-off-by: Greg Kroah-Hartman --- drivers/base/firmware.c | 19 ++----------------- 1 file changed, 2 insertions(+), 17 deletions(-) (limited to 'drivers/base') diff --git a/drivers/base/firmware.c b/drivers/base/firmware.c index c7f635b..9efff48 100644 --- a/drivers/base/firmware.c +++ b/drivers/base/firmware.c @@ -3,11 +3,11 @@ * * Copyright (c) 2002-3 Patrick Mochel * Copyright (c) 2002-3 Open Source Development Labs + * Copyright (c) 2007 Greg Kroah-Hartman + * Copyright (c) 2007 Novell Inc. * * This file is released under the GPLv2 - * */ - #include #include #include @@ -18,18 +18,6 @@ struct kset *firmware_kset; EXPORT_SYMBOL_GPL(firmware_kset); -int firmware_register(struct kset *s) -{ - s->kobj.kset = firmware_kset; - s->kobj.ktype = NULL; - return subsystem_register(s); -} - -void firmware_unregister(struct kset *s) -{ - subsystem_unregister(s); -} - int __init firmware_init(void) { firmware_kset = kset_create_and_add("firmware", NULL, NULL); @@ -37,6 +25,3 @@ int __init firmware_init(void) return -ENOMEM; return 0; } - -EXPORT_SYMBOL_GPL(firmware_register); -EXPORT_SYMBOL_GPL(firmware_unregister); -- cgit v1.1 From f62ed9e33b3ccff54d66b08f82d11940bb9e269b Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Mon, 5 Nov 2007 13:16:15 -0800 Subject: firmware: change firmware_kset to firmware_kobj There is no firmware "subsystem" it's just a directory in /sys that other portions of the kernel want to hook into. So make it a kobject not a kset to help alivate anyone who tries to do some odd kset-like things with this. Cc: Kay Sievers Cc: Cornelia Huck Signed-off-by: Greg Kroah-Hartman --- drivers/base/firmware.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'drivers/base') diff --git a/drivers/base/firmware.c b/drivers/base/firmware.c index 9efff48..1138155 100644 --- a/drivers/base/firmware.c +++ b/drivers/base/firmware.c @@ -15,13 +15,13 @@ #include "base.h" -struct kset *firmware_kset; -EXPORT_SYMBOL_GPL(firmware_kset); +struct kobject *firmware_kobj; +EXPORT_SYMBOL_GPL(firmware_kobj); int __init firmware_init(void) { - firmware_kset = kset_create_and_add("firmware", NULL, NULL); - if (!firmware_kset) + firmware_kobj = kobject_create_and_add("firmware", NULL); + if (!firmware_kobj) return -ENOMEM; return 0; } -- cgit v1.1 From 5c03c7ab886859eb195440dbb6ccb8c30c4e84cc Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Fri, 2 Nov 2007 16:19:59 -0700 Subject: kset: remove decl_subsys macro This macro is no longer used. ksets should be created dynamically with a call to kset_create_and_add() not declared statically. Yes, there are 5 remaining static struct kset usages in the kernel tree, but they will be fixed up soon. Cc: Kay Sievers Signed-off-by: Greg Kroah-Hartman --- drivers/base/class.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'drivers/base') diff --git a/drivers/base/class.c b/drivers/base/class.c index d8a92c6..304f90e 100644 --- a/drivers/base/class.c +++ b/drivers/base/class.c @@ -453,8 +453,15 @@ static struct kset_uevent_ops class_uevent_ops = { .uevent = class_uevent, }; -static decl_subsys(class_obj, &class_uevent_ops); - +/* + * DO NOT copy how this is created, kset_create_and_add() should be + * called, but this is a hold-over from the old-way and will be deleted + * entirely soon. + */ +static struct kset class_obj_subsys = { + .kobj = { .k_name = "class_obj", }, + .uevent_ops = &class_uevent_ops, +}; static int class_device_add_attrs(struct class_device * cd) { -- cgit v1.1 From 2fb9113b974c3c7c43e76647bd5077238e274e1c Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Tue, 6 Nov 2007 15:03:30 -0800 Subject: kobject: remove subsystem_(un)register functions These functions are no longer used and are the last remants of the old subsystem crap. So delete them for good. Cc: Kay Sievers Signed-off-by: Greg Kroah-Hartman --- drivers/base/bus.c | 6 +++--- drivers/base/class.c | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'drivers/base') diff --git a/drivers/base/bus.c b/drivers/base/bus.c index 6796d3e..871607b 100644 --- a/drivers/base/bus.c +++ b/drivers/base/bus.c @@ -854,7 +854,7 @@ int bus_register(struct bus_type * bus) bus->subsys.kobj.kset = bus_kset; bus->subsys.kobj.ktype = &bus_ktype; - retval = subsystem_register(&bus->subsys); + retval = kset_register(&bus->subsys); if (retval) goto out; @@ -900,7 +900,7 @@ bus_drivers_fail: bus_devices_fail: bus_remove_file(bus, &bus_attr_uevent); bus_uevent_fail: - subsystem_unregister(&bus->subsys); + kset_unregister(&bus->subsys); out: return retval; } @@ -920,7 +920,7 @@ void bus_unregister(struct bus_type * bus) kset_unregister(bus->drivers_kset); kset_unregister(bus->devices_kset); bus_remove_file(bus, &bus_attr_uevent); - subsystem_unregister(&bus->subsys); + kset_unregister(&bus->subsys); } int bus_register_notifier(struct bus_type *bus, struct notifier_block *nb) diff --git a/drivers/base/class.c b/drivers/base/class.c index 304f90e..3ffcda7 100644 --- a/drivers/base/class.c +++ b/drivers/base/class.c @@ -152,7 +152,7 @@ int class_register(struct class * cls) cls->subsys.kobj.kset = class_kset; cls->subsys.kobj.ktype = &class_ktype; - error = subsystem_register(&cls->subsys); + error = kset_register(&cls->subsys); if (!error) { error = add_class_attrs(class_get(cls)); class_put(cls); @@ -164,7 +164,7 @@ void class_unregister(struct class * cls) { pr_debug("device class '%s': unregistering\n", cls->name); remove_class_attrs(cls); - subsystem_unregister(&cls->subsys); + kset_unregister(&cls->subsys); } static void class_create_release(struct class *cls) -- cgit v1.1 From 822a89ed1ea0f7a2d8079307426fbeeac0370138 Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Tue, 20 Nov 2007 13:56:21 -0800 Subject: driver core: clean up shutdown.c shutdown.c had some stuff it did not need, including a duplicate extern in the power.h file. This cleans up all of that. Signed-off-by: Greg Kroah-Hartman --- drivers/base/power/power.h | 7 ------- drivers/base/power/shutdown.c | 5 ----- 2 files changed, 12 deletions(-) (limited to 'drivers/base') diff --git a/drivers/base/power/power.h b/drivers/base/power/power.h index 10c2084..6f0dfca 100644 --- a/drivers/base/power/power.h +++ b/drivers/base/power/power.h @@ -1,10 +1,3 @@ -/* - * shutdown.c - */ - -extern void device_shutdown(void); - - #ifdef CONFIG_PM_SLEEP /* diff --git a/drivers/base/power/shutdown.c b/drivers/base/power/shutdown.c index f51cbc1d..5b6bc16 100644 --- a/drivers/base/power/shutdown.c +++ b/drivers/base/power/shutdown.c @@ -12,10 +12,6 @@ #include #include "../base.h" -#include "power.h" - -#define to_dev(node) container_of(node, struct device, kobj.entry) - /** * We handle system devices differently - we suspend and shut them @@ -45,4 +41,3 @@ void device_shutdown(void) } } } - -- cgit v1.1 From 37b0c020343080241984d978981d6caf877b278a Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Mon, 26 Nov 2007 22:11:55 -0800 Subject: driver core: clean up device_shutdown device_shutdown does not need to be in a separate file. Move it into the driver core file where it belongs. This also moves us one more step closer to making devices_kset static, now only the crazy sysdevs are keeping that from happening... Signed-off-by: Greg Kroah-Hartman --- drivers/base/core.c | 20 +++++++++++++++++++- drivers/base/power/Makefile | 1 - drivers/base/power/shutdown.c | 43 ------------------------------------------- 3 files changed, 19 insertions(+), 45 deletions(-) delete mode 100644 drivers/base/power/shutdown.c (limited to 'drivers/base') diff --git a/drivers/base/core.c b/drivers/base/core.c index d2de2d5..b3a931f 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c @@ -1415,5 +1415,23 @@ out: put_device(dev); return error; } - EXPORT_SYMBOL_GPL(device_move); + +/** + * device_shutdown - call ->shutdown() on each device to shutdown. + */ +void device_shutdown(void) +{ + struct device * dev, *devn; + + list_for_each_entry_safe_reverse(dev, devn, &devices_kset->list, + kobj.entry) { + if (dev->bus && dev->bus->shutdown) { + dev_dbg(dev, "shutdown\n"); + dev->bus->shutdown(dev); + } else if (dev->driver && dev->driver->shutdown) { + dev_dbg(dev, "shutdown\n"); + dev->driver->shutdown(dev); + } + } +} diff --git a/drivers/base/power/Makefile b/drivers/base/power/Makefile index 44504e6..06a86fe 100644 --- a/drivers/base/power/Makefile +++ b/drivers/base/power/Makefile @@ -1,4 +1,3 @@ -obj-y := shutdown.o obj-$(CONFIG_PM) += sysfs.o obj-$(CONFIG_PM_SLEEP) += main.o obj-$(CONFIG_PM_TRACE) += trace.o diff --git a/drivers/base/power/shutdown.c b/drivers/base/power/shutdown.c deleted file mode 100644 index 5b6bc16..0000000 --- a/drivers/base/power/shutdown.c +++ /dev/null @@ -1,43 +0,0 @@ -/* - * shutdown.c - power management functions for the device tree. - * - * Copyright (c) 2002-3 Patrick Mochel - * 2002-3 Open Source Development Lab - * - * This file is released under the GPLv2 - * - */ - -#include -#include - -#include "../base.h" - -/** - * We handle system devices differently - we suspend and shut them - * down last and resume them first. That way, we don't do anything stupid like - * shutting down the interrupt controller before any devices.. - * - * Note that there are not different stages for power management calls - - * they only get one called once when interrupts are disabled. - */ - - -/** - * device_shutdown - call ->shutdown() on each device to shutdown. - */ -void device_shutdown(void) -{ - struct device * dev, *devn; - - list_for_each_entry_safe_reverse(dev, devn, &devices_kset->list, - kobj.entry) { - if (dev->bus && dev->bus->shutdown) { - dev_dbg(dev, "shutdown\n"); - dev->bus->shutdown(dev); - } else if (dev->driver && dev->driver->shutdown) { - dev_dbg(dev, "shutdown\n"); - dev->driver->shutdown(dev); - } - } -} -- cgit v1.1 From 61030bfb79148b12b661580c8e3c2adfe1d9fc9e Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Mon, 17 Dec 2007 15:54:39 -0400 Subject: Kobject: change drivers/base/sys.c to use kobject_init_and_add Stop using kobject_register, as this way we can control the sending of the uevent properly, after everything is properly initialized. Cc: Kay Sievers Signed-off-by: Greg Kroah-Hartman --- drivers/base/sys.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) (limited to 'drivers/base') diff --git a/drivers/base/sys.c b/drivers/base/sys.c index 29eadc6..47fc6eb 100644 --- a/drivers/base/sys.c +++ b/drivers/base/sys.c @@ -224,20 +224,15 @@ int sysdev_register(struct sys_device * sysdev) if (!cls) return -EINVAL; + pr_debug("Registering sys device '%s'\n", kobject_name(&sysdev->kobj)); + /* Make sure the kset is set */ sysdev->kobj.kset = &cls->kset; - /* But make sure we point to the right type for sysfs translation */ - sysdev->kobj.ktype = &ktype_sysdev; - error = kobject_set_name(&sysdev->kobj, "%s%d", - kobject_name(&cls->kset.kobj), sysdev->id); - if (error) - return error; - - pr_debug("Registering sys device '%s'\n", kobject_name(&sysdev->kobj)); - /* Register the object */ - error = kobject_register(&sysdev->kobj); + error = kobject_init_and_add(&sysdev->kobj, &ktype_sysdev, NULL, + "%s%d", kobject_name(&cls->kset.kobj), + sysdev->id); if (!error) { struct sysdev_driver * drv; @@ -254,6 +249,7 @@ int sysdev_register(struct sys_device * sysdev) } mutex_unlock(&sysdev_drivers_lock); } + kobject_uevent(&sysdev->kobj, KOBJ_ADD); return error; } -- cgit v1.1 From 60728d62e4d273776e9ef9704f9ff8e8a248a8a1 Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Mon, 17 Dec 2007 23:05:35 -0700 Subject: Kobject: convert drivers/base/class.c to use kobject_init/add_ng() This converts the code to use the new kobject functions, cleaning up the logic in doing so. Cc: Kay Sievers Signed-off-by: Greg Kroah-Hartman --- drivers/base/class.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) (limited to 'drivers/base') diff --git a/drivers/base/class.c b/drivers/base/class.c index 3ffcda7..ba6745b 100644 --- a/drivers/base/class.c +++ b/drivers/base/class.c @@ -546,8 +546,7 @@ static struct class_device_attribute class_uevent_attr = void class_device_initialize(struct class_device *class_dev) { class_dev->kobj.kset = &class_obj_subsys; - class_dev->kobj.ktype = &class_device_ktype; - kobject_init(&class_dev->kobj); + kobject_init_ng(&class_dev->kobj, &class_device_ktype); INIT_LIST_HEAD(&class_dev->node); } @@ -575,16 +574,13 @@ int class_device_add(struct class_device *class_dev) class_dev->class_id); /* first, register with generic layer. */ - error = kobject_set_name(&class_dev->kobj, "%s", class_dev->class_id); - if (error) - goto out2; - if (parent_class_dev) class_dev->kobj.parent = &parent_class_dev->kobj; else class_dev->kobj.parent = &parent_class->subsys.kobj; - error = kobject_add(&class_dev->kobj); + error = kobject_add_ng(&class_dev->kobj, class_dev->kobj.parent, + "%s", class_dev->class_id); if (error) goto out2; -- cgit v1.1 From 9990513c1ef040528c4e38163a073089d39c7903 Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Mon, 17 Dec 2007 23:05:35 -0700 Subject: Kobject: convert drivers/base/core.c to use kobject_init/add_ng() This converts the code to use the new kobject functions, cleaning up the logic in doing so. Cc: Kay Sievers Signed-off-by: Greg Kroah-Hartman --- drivers/base/core.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'drivers/base') diff --git a/drivers/base/core.c b/drivers/base/core.c index b3a931f..beb3516 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c @@ -523,8 +523,7 @@ static void klist_children_put(struct klist_node *n) void device_initialize(struct device *dev) { dev->kobj.kset = devices_kset; - dev->kobj.ktype = &device_ktype; - kobject_init(&dev->kobj); + kobject_init_ng(&dev->kobj, &device_ktype); klist_init(&dev->klist_children, klist_children_get, klist_children_put); INIT_LIST_HEAD(&dev->dma_pools); @@ -729,7 +728,7 @@ static void device_remove_class_symlinks(struct device *dev) * This is part 2 of device_register(), though may be called * separately _iff_ device_initialize() has been called separately. * - * This adds it to the kobject hierarchy via kobject_add(), adds it + * This adds it to the kobject hierarchy via kobject_add_ng(), adds it * to the global and sibling lists for the device, then * adds it to the other relevant subsystems of the driver model. */ @@ -760,8 +759,7 @@ int device_add(struct device *dev) goto Error; /* first, register with generic layer. */ - kobject_set_name(&dev->kobj, "%s", dev->bus_id); - error = kobject_add(&dev->kobj); + error = kobject_add_ng(&dev->kobj, dev->kobj.parent, "%s", dev->bus_id); if (error) goto Error; -- cgit v1.1 From 0fed80f7a63abd7168907267af69ee31f6bcf301 Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Thu, 1 Nov 2007 19:41:16 -0700 Subject: driver core: add way to get to bus kset This allows an easier way to get to the kset associated with a struct bus_type (you have three to choose from...) This will make it easier to move these fields to be dynamic in a future patch. Cc: Kay Sievers Signed-off-by: Greg Kroah-Hartman --- drivers/base/bus.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'drivers/base') diff --git a/drivers/base/bus.c b/drivers/base/bus.c index 871607b..8335a10 100644 --- a/drivers/base/bus.c +++ b/drivers/base/bus.c @@ -935,6 +935,12 @@ int bus_unregister_notifier(struct bus_type *bus, struct notifier_block *nb) } EXPORT_SYMBOL_GPL(bus_unregister_notifier); +struct kset *bus_get_kset(struct bus_type *bus) +{ + return &bus->subsys; +} +EXPORT_SYMBOL_GPL(bus_get_kset); + int __init buses_init(void) { bus_kset = kset_create_and_add("bus", &bus_uevent_ops, NULL); -- cgit v1.1 From b249072ee6897fe4f8d461c7bb4b926223263c28 Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Thu, 1 Nov 2007 19:41:16 -0700 Subject: driver core: add way to get to bus device klist This allows an easier way to get to the device klist associated with a struct bus_type (you have three to choose from...) This will make it easier to move these fields to be dynamic in a future patch. The only user of this is the PCI core which horribly abuses this interface to rearrange the order of the pci devices. This should be done using the existing bus device walking functions, but that's left for future patches. Cc: Kay Sievers Signed-off-by: Greg Kroah-Hartman --- drivers/base/bus.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'drivers/base') diff --git a/drivers/base/bus.c b/drivers/base/bus.c index 8335a10..9c9027b 100644 --- a/drivers/base/bus.c +++ b/drivers/base/bus.c @@ -941,6 +941,12 @@ struct kset *bus_get_kset(struct bus_type *bus) } EXPORT_SYMBOL_GPL(bus_get_kset); +struct klist *bus_get_device_klist(struct bus_type *bus) +{ + return &bus->klist_devices; +} +EXPORT_SYMBOL_GPL(bus_get_device_klist); + int __init buses_init(void) { bus_kset = kset_create_and_add("bus", &bus_uevent_ops, NULL); -- cgit v1.1 From c6f7e72a3f4641095ade9ded287d910c980c6148 Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Thu, 1 Nov 2007 19:41:16 -0700 Subject: 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 Signed-off-by: Greg Kroah-Hartman --- drivers/base/base.h | 30 ++++++++++++- drivers/base/bus.c | 116 +++++++++++++++++++++++++++--------------------- drivers/base/core.c | 6 +-- drivers/base/dd.c | 4 +- drivers/base/driver.c | 2 +- drivers/base/platform.c | 4 +- 6 files changed, 102 insertions(+), 60 deletions(-) (limited to 'drivers/base') diff --git a/drivers/base/base.h b/drivers/base/base.h index 7e309a4..ca6d273 100644 --- a/drivers/base/base.h +++ b/drivers/base/base.h @@ -1,6 +1,34 @@ -/* 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 buses_init(void); extern int classes_init(void); diff --git a/drivers/base/bus.c b/drivers/base/bus.c index 9c9027b..04d3850 100644 --- a/drivers/base/bus.c +++ b/drivers/base/bus.c @@ -17,7 +17,7 @@ #include "power/power.h" #define to_bus_attr(_attr) container_of(_attr, struct bus_attribute, attr) -#define to_bus(obj) container_of(obj, struct bus_type, subsys.kobj) +#define to_bus(obj) container_of(obj, struct bus_type_private, subsys.kobj) /* * sysfs bindings for drivers @@ -32,13 +32,17 @@ static int __must_check bus_rescan_devices_helper(struct device *dev, static struct bus_type *bus_get(struct bus_type *bus) { - return bus ? container_of(kset_get(&bus->subsys), - struct bus_type, subsys) : NULL; + if (bus) { + kset_get(&bus->p->subsys); + return bus; + } + return NULL; } static void bus_put(struct bus_type *bus) { - kset_put(&bus->subsys); + if (bus) + kset_put(&bus->p->subsys); } static ssize_t @@ -104,11 +108,11 @@ static ssize_t bus_attr_show(struct kobject * kobj, struct attribute * attr, char * buf) { struct bus_attribute * bus_attr = to_bus_attr(attr); - struct bus_type * bus = to_bus(kobj); + struct bus_type_private *bus_priv = to_bus(kobj); ssize_t ret = 0; if (bus_attr->show) - ret = bus_attr->show(bus, buf); + ret = bus_attr->show(bus_priv->bus, buf); return ret; } @@ -117,11 +121,11 @@ bus_attr_store(struct kobject * kobj, struct attribute * attr, const char * buf, size_t count) { struct bus_attribute * bus_attr = to_bus_attr(attr); - struct bus_type * bus = to_bus(kobj); + struct bus_type_private *bus_priv = to_bus(kobj); ssize_t ret = 0; if (bus_attr->store) - ret = bus_attr->store(bus, buf, count); + ret = bus_attr->store(bus_priv->bus, buf, count); return ret; } @@ -134,7 +138,7 @@ int bus_create_file(struct bus_type * bus, struct bus_attribute * attr) { int error; if (bus_get(bus)) { - error = sysfs_create_file(&bus->subsys.kobj, &attr->attr); + error = sysfs_create_file(&bus->p->subsys.kobj, &attr->attr); bus_put(bus); } else error = -EINVAL; @@ -144,7 +148,7 @@ int bus_create_file(struct bus_type * bus, struct bus_attribute * attr) void bus_remove_file(struct bus_type * bus, struct bus_attribute * attr) { if (bus_get(bus)) { - sysfs_remove_file(&bus->subsys.kobj, &attr->attr); + sysfs_remove_file(&bus->p->subsys.kobj, &attr->attr); bus_put(bus); } } @@ -237,16 +241,16 @@ static DRIVER_ATTR(bind, S_IWUSR, NULL, driver_bind); static ssize_t show_drivers_autoprobe(struct bus_type *bus, char *buf) { - return sprintf(buf, "%d\n", bus->drivers_autoprobe); + return sprintf(buf, "%d\n", bus->p->drivers_autoprobe); } static ssize_t store_drivers_autoprobe(struct bus_type *bus, const char *buf, size_t count) { if (buf[0] == '0') - bus->drivers_autoprobe = 0; + bus->p->drivers_autoprobe = 0; else - bus->drivers_autoprobe = 1; + bus->p->drivers_autoprobe = 1; return count; } @@ -300,7 +304,7 @@ int bus_for_each_dev(struct bus_type * bus, struct device * start, if (!bus) return -EINVAL; - klist_iter_init_node(&bus->klist_devices, &i, + klist_iter_init_node(&bus->p->klist_devices, &i, (start ? &start->knode_bus : NULL)); while ((dev = next_device(&i)) && !error) error = fn(dev, data); @@ -333,7 +337,7 @@ struct device * bus_find_device(struct bus_type *bus, if (!bus) return NULL; - klist_iter_init_node(&bus->klist_devices, &i, + klist_iter_init_node(&bus->p->klist_devices, &i, (start ? &start->knode_bus : NULL)); while ((dev = next_device(&i))) if (match(dev, data) && get_device(dev)) @@ -379,7 +383,7 @@ int bus_for_each_drv(struct bus_type * bus, struct device_driver * start, if (!bus) return -EINVAL; - klist_iter_init_node(&bus->klist_drivers, &i, + klist_iter_init_node(&bus->p->klist_drivers, &i, start ? &start->knode_bus : NULL); while ((drv = next_driver(&i)) && !error) error = fn(drv, data); @@ -420,7 +424,7 @@ static void device_remove_attrs(struct bus_type * bus, struct device * dev) static int make_deprecated_bus_links(struct device *dev) { return sysfs_create_link(&dev->kobj, - &dev->bus->subsys.kobj, "bus"); + &dev->bus->p->subsys.kobj, "bus"); } static void remove_deprecated_bus_links(struct device *dev) @@ -449,12 +453,12 @@ int bus_add_device(struct device * dev) error = device_add_attrs(bus, dev); if (error) goto out_put; - error = sysfs_create_link(&bus->devices_kset->kobj, + error = sysfs_create_link(&bus->p->devices_kset->kobj, &dev->kobj, dev->bus_id); if (error) goto out_id; error = sysfs_create_link(&dev->kobj, - &dev->bus->subsys.kobj, "subsystem"); + &dev->bus->p->subsys.kobj, "subsystem"); if (error) goto out_subsys; error = make_deprecated_bus_links(dev); @@ -466,7 +470,7 @@ int bus_add_device(struct device * dev) out_deprecated: sysfs_remove_link(&dev->kobj, "subsystem"); out_subsys: - sysfs_remove_link(&bus->devices_kset->kobj, dev->bus_id); + sysfs_remove_link(&bus->p->devices_kset->kobj, dev->bus_id); out_id: device_remove_attrs(bus, dev); out_put: @@ -488,11 +492,11 @@ void bus_attach_device(struct device * dev) if (bus) { dev->is_registered = 1; - if (bus->drivers_autoprobe) + if (bus->p->drivers_autoprobe) ret = device_attach(dev); WARN_ON(ret < 0); if (ret >= 0) - klist_add_tail(&dev->knode_bus, &bus->klist_devices); + klist_add_tail(&dev->knode_bus, &bus->p->klist_devices); else dev->is_registered = 0; } @@ -512,7 +516,7 @@ void bus_remove_device(struct device * dev) if (dev->bus) { sysfs_remove_link(&dev->kobj, "subsystem"); remove_deprecated_bus_links(dev); - sysfs_remove_link(&dev->bus->devices_kset->kobj, dev->bus_id); + sysfs_remove_link(&dev->bus->p->devices_kset->kobj, dev->bus_id); device_remove_attrs(dev->bus, dev); if (dev->is_registered) { dev->is_registered = 0; @@ -638,18 +642,18 @@ int bus_add_driver(struct device_driver *drv) error = kobject_set_name(&drv->kobj, "%s", drv->name); if (error) goto out_put_bus; - drv->kobj.kset = bus->drivers_kset; + drv->kobj.kset = bus->p->drivers_kset; drv->kobj.ktype = &driver_ktype; error = kobject_register(&drv->kobj); if (error) goto out_put_bus; - if (drv->bus->drivers_autoprobe) { + if (drv->bus->p->drivers_autoprobe) { error = driver_attach(drv); if (error) goto out_unregister; } - klist_add_tail(&drv->knode_bus, &bus->klist_drivers); + klist_add_tail(&drv->knode_bus, &bus->p->klist_drivers); module_add_driver(drv->owner, drv); error = driver_create_file(drv, &driver_attr_uevent); @@ -828,7 +832,7 @@ static ssize_t bus_uevent_store(struct bus_type *bus, enum kobject_action action; if (kobject_action_type(buf, count, &action) == 0) - kobject_uevent(&bus->subsys.kobj, action); + kobject_uevent(&bus->p->subsys.kobj, action); return count; } static BUS_ATTR(uevent, S_IWUSR, NULL, bus_uevent_store); @@ -844,17 +848,26 @@ static BUS_ATTR(uevent, S_IWUSR, NULL, bus_uevent_store); int bus_register(struct bus_type * bus) { int retval; + struct bus_type_private *priv; + + priv = kzalloc(sizeof(struct bus_type_private), GFP_KERNEL); + if (!priv) + return -ENOMEM; + + priv->bus = bus; + bus->p = priv; - BLOCKING_INIT_NOTIFIER_HEAD(&bus->bus_notifier); + BLOCKING_INIT_NOTIFIER_HEAD(&priv->bus_notifier); - retval = kobject_set_name(&bus->subsys.kobj, "%s", bus->name); + retval = kobject_set_name(&priv->subsys.kobj, "%s", bus->name); if (retval) goto out; - bus->subsys.kobj.kset = bus_kset; - bus->subsys.kobj.ktype = &bus_ktype; + priv->subsys.kobj.kset = bus_kset; + priv->subsys.kobj.ktype = &bus_ktype; + priv->drivers_autoprobe = 1; - retval = kset_register(&bus->subsys); + retval = kset_register(&priv->subsys); if (retval) goto out; @@ -862,24 +875,23 @@ int bus_register(struct bus_type * bus) if (retval) goto bus_uevent_fail; - bus->devices_kset = kset_create_and_add("devices", NULL, - &bus->subsys.kobj); - if (!bus->devices_kset) { + priv->devices_kset = kset_create_and_add("devices", NULL, + &priv->subsys.kobj); + if (!priv->devices_kset) { retval = -ENOMEM; goto bus_devices_fail; } - bus->drivers_kset = kset_create_and_add("drivers", NULL, - &bus->subsys.kobj); - if (!bus->drivers_kset) { + priv->drivers_kset = kset_create_and_add("drivers", NULL, + &priv->subsys.kobj); + if (!priv->drivers_kset) { retval = -ENOMEM; goto bus_drivers_fail; } - klist_init(&bus->klist_devices, klist_devices_get, klist_devices_put); - klist_init(&bus->klist_drivers, NULL, NULL); + klist_init(&priv->klist_devices, klist_devices_get, klist_devices_put); + klist_init(&priv->klist_drivers, NULL, NULL); - bus->drivers_autoprobe = 1; retval = add_probe_files(bus); if (retval) goto bus_probe_files_fail; @@ -894,13 +906,14 @@ int bus_register(struct bus_type * bus) bus_attrs_fail: remove_probe_files(bus); bus_probe_files_fail: - kset_unregister(bus->drivers_kset); + kset_unregister(bus->p->drivers_kset); bus_drivers_fail: - kset_unregister(bus->devices_kset); + kset_unregister(bus->p->devices_kset); bus_devices_fail: bus_remove_file(bus, &bus_attr_uevent); bus_uevent_fail: - kset_unregister(&bus->subsys); + kset_unregister(&bus->p->subsys); + kfree(bus->p); out: return retval; } @@ -917,33 +930,34 @@ void bus_unregister(struct bus_type * bus) pr_debug("bus %s: unregistering\n", bus->name); bus_remove_attrs(bus); remove_probe_files(bus); - kset_unregister(bus->drivers_kset); - kset_unregister(bus->devices_kset); + kset_unregister(bus->p->drivers_kset); + kset_unregister(bus->p->devices_kset); bus_remove_file(bus, &bus_attr_uevent); - kset_unregister(&bus->subsys); + kset_unregister(&bus->p->subsys); + kfree(bus->p); } int bus_register_notifier(struct bus_type *bus, struct notifier_block *nb) { - return blocking_notifier_chain_register(&bus->bus_notifier, nb); + return blocking_notifier_chain_register(&bus->p->bus_notifier, nb); } EXPORT_SYMBOL_GPL(bus_register_notifier); int bus_unregister_notifier(struct bus_type *bus, struct notifier_block *nb) { - return blocking_notifier_chain_unregister(&bus->bus_notifier, nb); + return blocking_notifier_chain_unregister(&bus->p->bus_notifier, nb); } EXPORT_SYMBOL_GPL(bus_unregister_notifier); struct kset *bus_get_kset(struct bus_type *bus) { - return &bus->subsys; + return &bus->p->subsys; } EXPORT_SYMBOL_GPL(bus_get_kset); struct klist *bus_get_device_klist(struct bus_type *bus) { - return &bus->klist_devices; + return &bus->p->klist_devices; } EXPORT_SYMBOL_GPL(bus_get_device_klist); diff --git a/drivers/base/core.c b/drivers/base/core.c index beb3516..414a480 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c @@ -769,7 +769,7 @@ int device_add(struct device *dev) /* notify clients of device entry (new way) */ 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); error = device_create_file(dev, &uevent_attr); @@ -820,7 +820,7 @@ int device_add(struct device *dev) dpm_sysfs_remove(dev); PMError: 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); device_remove_attrs(dev); AttrsError: @@ -999,7 +999,7 @@ void device_del(struct device * dev) if (platform_notify_remove) platform_notify_remove(dev); 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); kobject_uevent(&dev->kobj, KOBJ_REMOVE); kobject_del(&dev->kobj); diff --git a/drivers/base/dd.c b/drivers/base/dd.c index 7ac474d..7bf0e67 100644 --- a/drivers/base/dd.c +++ b/drivers/base/dd.c @@ -38,7 +38,7 @@ static void driver_bound(struct device *dev) dev->bus_id, dev->driver->name); 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); klist_add_tail(&dev->knode_driver, &dev->driver->klist_devices); @@ -296,7 +296,7 @@ static void __device_release_driver(struct device * dev) klist_remove(&dev->knode_driver); if (dev->bus) - blocking_notifier_call_chain(&dev->bus->bus_notifier, + blocking_notifier_call_chain(&dev->bus->p->bus_notifier, BUS_NOTIFY_UNBIND_DRIVER, dev); diff --git a/drivers/base/driver.c b/drivers/base/driver.c index 1c9770d..f94be40 100644 --- a/drivers/base/driver.c +++ b/drivers/base/driver.c @@ -185,7 +185,7 @@ void driver_unregister(struct device_driver * drv) */ 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) return to_drv(k); return NULL; diff --git a/drivers/base/platform.c b/drivers/base/platform.c index fb56092..d56a05f 100644 --- a/drivers/base/platform.c +++ b/drivers/base/platform.c @@ -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 * 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; if (code == 0 && list_empty(&drv->driver.klist_devices.k_list)) retval = -ENODEV; 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) platform_driver_unregister(drv); -- cgit v1.1 From 57c745340a60c51d2b9af3d4dcf7e0ede284855b Mon Sep 17 00:00:00 2001 From: Cornelia Huck Date: Wed, 5 Dec 2007 12:50:23 +0100 Subject: driver core: Introduce default attribute groups. This is lot like default attributes for devices (and indeed, a lot of the code is lifted from there). Signed-off-by: Cornelia Huck Signed-off-by: Greg Kroah-Hartman --- drivers/base/driver.c | 42 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) (limited to 'drivers/base') diff --git a/drivers/base/driver.c b/drivers/base/driver.c index f94be40..e3b5840 100644 --- a/drivers/base/driver.c +++ b/drivers/base/driver.c @@ -142,6 +142,37 @@ void put_driver(struct device_driver * drv) kobject_put(&drv->kobj); } +static int driver_add_groups(struct device_driver *drv, + struct attribute_group **groups) +{ + int error = 0; + int i; + + if (groups) { + for (i = 0; groups[i]; i++) { + error = sysfs_create_group(&drv->kobj, groups[i]); + if (error) { + while (--i >= 0) + sysfs_remove_group(&drv->kobj, + groups[i]); + break; + } + } + } + return error; +} + +static void driver_remove_groups(struct device_driver *drv, + struct attribute_group **groups) +{ + int i; + + if (groups) + for (i = 0; groups[i]; i++) + sysfs_remove_group(&drv->kobj, groups[i]); +} + + /** * driver_register - register driver with bus * @drv: driver to register @@ -152,13 +183,21 @@ void put_driver(struct device_driver * drv) */ int driver_register(struct device_driver * drv) { + int ret; + if ((drv->bus->probe && drv->probe) || (drv->bus->remove && drv->remove) || (drv->bus->shutdown && drv->shutdown)) { printk(KERN_WARNING "Driver '%s' needs updating - please use bus_type methods\n", drv->name); } klist_init(&drv->klist_devices, NULL, NULL); - return bus_add_driver(drv); + ret = bus_add_driver(drv); + if (ret) + return ret; + ret = driver_add_groups(drv, drv->groups); + if (ret) + bus_remove_driver(drv); + return ret; } /** @@ -170,6 +209,7 @@ int driver_register(struct device_driver * drv) void driver_unregister(struct device_driver * drv) { + driver_remove_groups(drv, drv->groups); bus_remove_driver(drv); } -- cgit v1.1 From cbe9c595f1de2e2a98403be2c14bfbc2486e84c4 Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Wed, 19 Dec 2007 15:54:39 -0400 Subject: Driver: add driver_add_kobj for looney iseries_veth driver The iseries driver wants to hang kobjects off of its driver, so, to preserve backwards compatibility, we need to add a call to the driver core to allow future changes to work properly. Hopefully no one uses this function in the future and the iseries_veth driver authors come to their senses so I can remove this hack... Cc: Dave Larson Cc: Santiago Leon Cc: Kay Sievers Signed-off-by: Greg Kroah-Hartman --- drivers/base/driver.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'drivers/base') diff --git a/drivers/base/driver.c b/drivers/base/driver.c index e3b5840..633ae1d 100644 --- a/drivers/base/driver.c +++ b/drivers/base/driver.c @@ -124,6 +124,30 @@ void driver_remove_file(struct device_driver * drv, struct driver_attribute * at /** + * driver_add_kobj - add a kobject below the specified driver + * + * You really don't want to do this, this is only here due to one looney + * iseries driver, go poke those developers if you are annoyed about + * this... + */ +int driver_add_kobj(struct device_driver *drv, struct kobject *kobj, + const char *fmt, ...) +{ + va_list args; + char *name; + + va_start(args, fmt); + name = kvasprintf(GFP_KERNEL, fmt, args); + va_end(args); + + if (!name) + return -ENOMEM; + + return kobject_add_ng(kobj, &drv->kobj, "%s", name); +} +EXPORT_SYMBOL_GPL(driver_add_kobj); + +/** * get_driver - increment driver reference count. * @drv: driver. */ -- cgit v1.1 From c63469a3985a9771c18a916b8d42845d044ea0b1 Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Wed, 28 Nov 2007 12:23:18 -0800 Subject: Driver core: move the driver specific module code into the driver core The module driver specific code should belong in the driver core, not in the kernel/ directory. So move this code. This is done in preparation for some struct device_driver rework that should be confined to the driver core code only. This also lets us keep from exporting these functions, as no external code should ever be calling it. Thanks to Andrew Morton for the !CONFIG_MODULES fix. Signed-off-by: Greg Kroah-Hartman --- drivers/base/Makefile | 1 + drivers/base/base.h | 9 +++++ drivers/base/module.c | 94 +++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 104 insertions(+) create mode 100644 drivers/base/module.c (limited to 'drivers/base') diff --git a/drivers/base/Makefile b/drivers/base/Makefile index b39ea3f..ff26968 100644 --- a/drivers/base/Makefile +++ b/drivers/base/Makefile @@ -11,6 +11,7 @@ obj-$(CONFIG_FW_LOADER) += firmware_class.o obj-$(CONFIG_NUMA) += node.o obj-$(CONFIG_MEMORY_HOTPLUG_SPARSE) += memory.o obj-$(CONFIG_SMP) += topology.o +obj-$(CONFIG_MODULES) += module.o obj-$(CONFIG_SYS_HYPERVISOR) += hypervisor.o ifeq ($(CONFIG_DEBUG_DRIVER),y) diff --git a/drivers/base/base.h b/drivers/base/base.h index ca6d273..0547236 100644 --- a/drivers/base/base.h +++ b/drivers/base/base.h @@ -73,3 +73,12 @@ extern char *make_class_name(const char *name, struct kobject *kobj); extern int devres_release_all(struct device *dev); extern struct kset *devices_kset; + +#ifdef CONFIG_MODULES +extern void module_add_driver(struct module *mod, struct device_driver *drv); +extern void module_remove_driver(struct device_driver *drv); +#else +static inline void module_add_driver(struct module *mod, + struct device_driver *drv) { } +static inline void module_remove_driver(struct device_driver *drv) { } +#endif diff --git a/drivers/base/module.c b/drivers/base/module.c new file mode 100644 index 0000000..cad07be --- /dev/null +++ b/drivers/base/module.c @@ -0,0 +1,94 @@ +/* + * module.c - module sysfs fun for drivers + * + * This file is released under the GPLv2 + * + */ +#include +#include +#include +#include +#include "base.h" + +static char *make_driver_name(struct device_driver *drv) +{ + char *driver_name; + + driver_name = kmalloc(strlen(drv->name) + strlen(drv->bus->name) + 2, + GFP_KERNEL); + if (!driver_name) + return NULL; + + sprintf(driver_name, "%s:%s", drv->bus->name, drv->name); + return driver_name; +} + +static void module_create_drivers_dir(struct module_kobject *mk) +{ + if (!mk || mk->drivers_dir) + return; + + mk->drivers_dir = kobject_create_and_add("drivers", &mk->kobj); +} + +void module_add_driver(struct module *mod, struct device_driver *drv) +{ + char *driver_name; + int no_warn; + struct module_kobject *mk = NULL; + + if (!drv) + return; + + if (mod) + mk = &mod->mkobj; + else if (drv->mod_name) { + struct kobject *mkobj; + + /* Lookup built-in module entry in /sys/modules */ + mkobj = kset_find_obj(module_kset, drv->mod_name); + if (mkobj) { + mk = container_of(mkobj, struct module_kobject, kobj); + /* remember our module structure */ + drv->mkobj = mk; + /* kset_find_obj took a reference */ + kobject_put(mkobj); + } + } + + if (!mk) + return; + + /* Don't check return codes; these calls are idempotent */ + no_warn = sysfs_create_link(&drv->kobj, &mk->kobj, "module"); + driver_name = make_driver_name(drv); + if (driver_name) { + module_create_drivers_dir(mk); + no_warn = sysfs_create_link(mk->drivers_dir, &drv->kobj, + driver_name); + kfree(driver_name); + } +} + +void module_remove_driver(struct device_driver *drv) +{ + struct module_kobject *mk = NULL; + char *driver_name; + + if (!drv) + return; + + sysfs_remove_link(&drv->kobj, "module"); + + if (drv->owner) + mk = &drv->owner->mkobj; + else if (drv->mkobj) + mk = drv->mkobj; + if (mk && mk->drivers_dir) { + driver_name = make_driver_name(drv); + if (driver_name) { + sysfs_remove_link(mk->drivers_dir, driver_name); + kfree(driver_name); + } + } +} -- cgit v1.1 From e5dd12784617f0f1fae5f96a7fac1ec4c49fadbe Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Wed, 28 Nov 2007 15:59:15 -0800 Subject: Driver core: move the static kobject out of struct driver This patch removes the kobject, and a few other driver-core-only fields out of struct driver and into the driver core only. Now drivers can be safely create on the stack or statically (like they currently are.) Cc: Kay Sievers Signed-off-by: Greg Kroah-Hartman --- drivers/base/base.h | 8 ++++++ drivers/base/bus.c | 71 +++++++++++++++++++++++++++---------------------- drivers/base/dd.c | 24 ++++++++--------- drivers/base/driver.c | 40 ++++++++++++++++++---------- drivers/base/module.c | 12 ++++----- drivers/base/platform.c | 2 +- 6 files changed, 92 insertions(+), 65 deletions(-) (limited to 'drivers/base') diff --git a/drivers/base/base.h b/drivers/base/base.h index 0547236..3b0f395 100644 --- a/drivers/base/base.h +++ b/drivers/base/base.h @@ -27,6 +27,14 @@ struct bus_type_private { struct bus_type *bus; }; +struct driver_private { + struct kobject kobj; + struct klist klist_devices; + struct klist_node knode_bus; + struct module_kobject *mkobj; + struct device_driver *driver; +}; +#define to_driver(obj) container_of(obj, struct driver_private, kobj) /* initialisation functions */ extern int devices_init(void); diff --git a/drivers/base/bus.c b/drivers/base/bus.c index 04d3850..aa0c986 100644 --- a/drivers/base/bus.c +++ b/drivers/base/bus.c @@ -3,6 +3,8 @@ * * Copyright (c) 2002-3 Patrick Mochel * Copyright (c) 2002-3 Open Source Development Labs + * Copyright (c) 2007 Greg Kroah-Hartman + * Copyright (c) 2007 Novell Inc. * * This file is released under the GPLv2 * @@ -24,7 +26,6 @@ */ #define to_drv_attr(_attr) container_of(_attr, struct driver_attribute, attr) -#define to_driver(obj) container_of(obj, struct device_driver, kobj) static int __must_check bus_rescan_devices_helper(struct device *dev, @@ -49,11 +50,11 @@ static ssize_t drv_attr_show(struct kobject * kobj, struct attribute * attr, char * buf) { struct driver_attribute * drv_attr = to_drv_attr(attr); - struct device_driver * drv = to_driver(kobj); + struct driver_private *drv_priv = to_driver(kobj); ssize_t ret = -EIO; if (drv_attr->show) - ret = drv_attr->show(drv, buf); + ret = drv_attr->show(drv_priv->driver, buf); return ret; } @@ -62,11 +63,11 @@ drv_attr_store(struct kobject * kobj, struct attribute * attr, const char * buf, size_t count) { struct driver_attribute * drv_attr = to_drv_attr(attr); - struct device_driver * drv = to_driver(kobj); + struct driver_private *drv_priv = to_driver(kobj); ssize_t ret = -EIO; if (drv_attr->store) - ret = drv_attr->store(drv, buf, count); + ret = drv_attr->store(drv_priv->driver, buf, count); return ret; } @@ -75,22 +76,12 @@ static struct sysfs_ops driver_sysfs_ops = { .store = drv_attr_store, }; - -static void driver_release(struct kobject * kobj) +static void driver_release(struct kobject *kobj) { - /* - * Yes this is an empty release function, it is this way because struct - * device is always a static object, not a dynamic one. Yes, this is - * not nice and bad, but remember, drivers are code, reference counted - * by the module count, not a device, which is really data. And yes, - * in the future I do want to have all drivers be created dynamically, - * and am working toward that goal, but it will take a bit longer... - * - * But do not let this example give _anyone_ the idea that they can - * create a release function without any code in it at all, to do that - * is almost always wrong. If you have any questions about this, - * please send an email to - */ + struct driver_private *drv_priv = to_driver(kobj); + + pr_debug("%s: freeing %s\n", __FUNCTION__, kobject_name(kobj)); + kfree(drv_priv); } static struct kobj_type driver_ktype = { @@ -350,7 +341,13 @@ struct device * bus_find_device(struct bus_type *bus, static struct device_driver * next_driver(struct klist_iter * i) { struct klist_node * n = klist_next(i); - return n ? container_of(n, struct device_driver, knode_bus) : NULL; + struct driver_private *drv_priv; + + if (n) { + drv_priv = container_of(n, struct driver_private, knode_bus); + return drv_priv->driver; + } + return NULL; } /** @@ -384,7 +381,7 @@ int bus_for_each_drv(struct bus_type * bus, struct device_driver * start, return -EINVAL; klist_iter_init_node(&bus->p->klist_drivers, &i, - start ? &start->knode_bus : NULL); + start ? &start->p->knode_bus : NULL); while ((drv = next_driver(&i)) && !error) error = fn(drv, data); klist_iter_exit(&i); @@ -620,7 +617,7 @@ static ssize_t driver_uevent_store(struct device_driver *drv, enum kobject_action action; if (kobject_action_type(buf, count, &action) == 0) - kobject_uevent(&drv->kobj, action); + kobject_uevent(&drv->p->kobj, action); return count; } static DRIVER_ATTR(uevent, S_IWUSR, NULL, driver_uevent_store); @@ -632,19 +629,29 @@ static DRIVER_ATTR(uevent, S_IWUSR, NULL, driver_uevent_store); */ int bus_add_driver(struct device_driver *drv) { - struct bus_type * bus = bus_get(drv->bus); + struct bus_type *bus; + struct driver_private *priv; int error = 0; + bus = bus_get(drv->bus); if (!bus) return -EINVAL; pr_debug("bus %s: add driver %s\n", bus->name, drv->name); - error = kobject_set_name(&drv->kobj, "%s", drv->name); + + priv = kzalloc(sizeof(*priv), GFP_KERNEL); + if (!priv) + return -ENOMEM; + + error = kobject_set_name(&priv->kobj, "%s", drv->name); if (error) goto out_put_bus; - drv->kobj.kset = bus->p->drivers_kset; - drv->kobj.ktype = &driver_ktype; - error = kobject_register(&drv->kobj); + priv->kobj.kset = bus->p->drivers_kset; + priv->kobj.ktype = &driver_ktype; + klist_init(&priv->klist_devices, NULL, NULL); + priv->driver = drv; + drv->p = priv; + error = kobject_register(&priv->kobj); if (error) goto out_put_bus; @@ -653,7 +660,7 @@ int bus_add_driver(struct device_driver *drv) if (error) goto out_unregister; } - klist_add_tail(&drv->knode_bus, &bus->p->klist_drivers); + klist_add_tail(&priv->knode_bus, &bus->p->klist_drivers); module_add_driver(drv->owner, drv); error = driver_create_file(drv, &driver_attr_uevent); @@ -676,7 +683,7 @@ int bus_add_driver(struct device_driver *drv) return error; out_unregister: - kobject_unregister(&drv->kobj); + kobject_unregister(&priv->kobj); out_put_bus: bus_put(bus); return error; @@ -699,11 +706,11 @@ void bus_remove_driver(struct device_driver * drv) remove_bind_files(drv); driver_remove_attrs(drv->bus, drv); driver_remove_file(drv, &driver_attr_uevent); - klist_remove(&drv->knode_bus); + klist_remove(&drv->p->knode_bus); pr_debug("bus %s: remove driver %s\n", drv->bus->name, drv->name); driver_detach(drv); module_remove_driver(drv); - kobject_unregister(&drv->kobj); + kobject_unregister(&drv->p->kobj); bus_put(drv->bus); } diff --git a/drivers/base/dd.c b/drivers/base/dd.c index 7bf0e67..87a348c 100644 --- a/drivers/base/dd.c +++ b/drivers/base/dd.c @@ -11,6 +11,8 @@ * * Copyright (c) 2002-5 Patrick Mochel * Copyright (c) 2002-3 Open Source Development Labs + * Copyright (c) 2007 Greg Kroah-Hartman + * Copyright (c) 2007 Novell Inc. * * This file is released under the GPLv2 */ @@ -23,8 +25,6 @@ #include "base.h" #include "power/power.h" -#define to_drv(node) container_of(node, struct device_driver, kobj.entry) - static void driver_bound(struct device *dev) { @@ -41,20 +41,20 @@ static void driver_bound(struct device *dev) blocking_notifier_call_chain(&dev->bus->p->bus_notifier, BUS_NOTIFY_BOUND_DRIVER, dev); - klist_add_tail(&dev->knode_driver, &dev->driver->klist_devices); + klist_add_tail(&dev->knode_driver, &dev->driver->p->klist_devices); } static int driver_sysfs_add(struct device *dev) { int ret; - ret = sysfs_create_link(&dev->driver->kobj, &dev->kobj, + ret = sysfs_create_link(&dev->driver->p->kobj, &dev->kobj, kobject_name(&dev->kobj)); if (ret == 0) { - ret = sysfs_create_link(&dev->kobj, &dev->driver->kobj, + ret = sysfs_create_link(&dev->kobj, &dev->driver->p->kobj, "driver"); if (ret) - sysfs_remove_link(&dev->driver->kobj, + sysfs_remove_link(&dev->driver->p->kobj, kobject_name(&dev->kobj)); } return ret; @@ -65,7 +65,7 @@ static void driver_sysfs_remove(struct device *dev) struct device_driver *drv = dev->driver; if (drv) { - sysfs_remove_link(&drv->kobj, kobject_name(&dev->kobj)); + sysfs_remove_link(&drv->p->kobj, kobject_name(&dev->kobj)); sysfs_remove_link(&dev->kobj, "driver"); } } @@ -339,15 +339,15 @@ void driver_detach(struct device_driver * drv) struct device * dev; for (;;) { - spin_lock(&drv->klist_devices.k_lock); - if (list_empty(&drv->klist_devices.k_list)) { - spin_unlock(&drv->klist_devices.k_lock); + spin_lock(&drv->p->klist_devices.k_lock); + if (list_empty(&drv->p->klist_devices.k_list)) { + spin_unlock(&drv->p->klist_devices.k_lock); break; } - dev = list_entry(drv->klist_devices.k_list.prev, + dev = list_entry(drv->p->klist_devices.k_list.prev, struct device, knode_driver.n_node); get_device(dev); - spin_unlock(&drv->klist_devices.k_lock); + spin_unlock(&drv->p->klist_devices.k_lock); if (dev->parent) /* Needed for USB */ down(&dev->parent->sem); diff --git a/drivers/base/driver.c b/drivers/base/driver.c index 633ae1d..5aacff2 100644 --- a/drivers/base/driver.c +++ b/drivers/base/driver.c @@ -3,6 +3,8 @@ * * Copyright (c) 2002-3 Patrick Mochel * Copyright (c) 2002-3 Open Source Development Labs + * Copyright (c) 2007 Greg Kroah-Hartman + * Copyright (c) 2007 Novell Inc. * * This file is released under the GPLv2 * @@ -15,7 +17,6 @@ #include "base.h" #define to_dev(node) container_of(node, struct device, driver_list) -#define to_drv(obj) container_of(obj, struct device_driver, kobj) static struct device * next_device(struct klist_iter * i) @@ -44,7 +45,7 @@ int driver_for_each_device(struct device_driver * drv, struct device * start, if (!drv) return -EINVAL; - klist_iter_init_node(&drv->klist_devices, &i, + klist_iter_init_node(&drv->p->klist_devices, &i, start ? &start->knode_driver : NULL); while ((dev = next_device(&i)) && !error) error = fn(dev, data); @@ -80,7 +81,7 @@ struct device * driver_find_device(struct device_driver *drv, if (!drv) return NULL; - klist_iter_init_node(&drv->klist_devices, &i, + klist_iter_init_node(&drv->p->klist_devices, &i, (start ? &start->knode_driver : NULL)); while ((dev = next_device(&i))) if (match(dev, data) && get_device(dev)) @@ -100,7 +101,7 @@ int driver_create_file(struct device_driver * drv, struct driver_attribute * att { int error; if (get_driver(drv)) { - error = sysfs_create_file(&drv->kobj, &attr->attr); + error = sysfs_create_file(&drv->p->kobj, &attr->attr); put_driver(drv); } else error = -EINVAL; @@ -117,7 +118,7 @@ int driver_create_file(struct device_driver * drv, struct driver_attribute * att void driver_remove_file(struct device_driver * drv, struct driver_attribute * attr) { if (get_driver(drv)) { - sysfs_remove_file(&drv->kobj, &attr->attr); + sysfs_remove_file(&drv->p->kobj, &attr->attr); put_driver(drv); } } @@ -143,7 +144,7 @@ int driver_add_kobj(struct device_driver *drv, struct kobject *kobj, if (!name) return -ENOMEM; - return kobject_add_ng(kobj, &drv->kobj, "%s", name); + return kobject_add_ng(kobj, &drv->p->kobj, "%s", name); } EXPORT_SYMBOL_GPL(driver_add_kobj); @@ -153,7 +154,15 @@ EXPORT_SYMBOL_GPL(driver_add_kobj); */ struct device_driver * get_driver(struct device_driver * drv) { - return drv ? to_drv(kobject_get(&drv->kobj)) : NULL; + if (drv) { + struct driver_private *priv; + struct kobject *kobj; + + kobj = kobject_get(&drv->p->kobj); + priv = to_driver(kobj); + return priv->driver; + } + return NULL; } @@ -163,7 +172,7 @@ struct device_driver * get_driver(struct device_driver * drv) */ void put_driver(struct device_driver * drv) { - kobject_put(&drv->kobj); + kobject_put(&drv->p->kobj); } static int driver_add_groups(struct device_driver *drv, @@ -174,10 +183,10 @@ static int driver_add_groups(struct device_driver *drv, if (groups) { for (i = 0; groups[i]; i++) { - error = sysfs_create_group(&drv->kobj, groups[i]); + error = sysfs_create_group(&drv->p->kobj, groups[i]); if (error) { while (--i >= 0) - sysfs_remove_group(&drv->kobj, + sysfs_remove_group(&drv->p->kobj, groups[i]); break; } @@ -193,7 +202,7 @@ static void driver_remove_groups(struct device_driver *drv, if (groups) for (i = 0; groups[i]; i++) - sysfs_remove_group(&drv->kobj, groups[i]); + sysfs_remove_group(&drv->p->kobj, groups[i]); } @@ -214,7 +223,6 @@ int driver_register(struct device_driver * drv) (drv->bus->shutdown && drv->shutdown)) { printk(KERN_WARNING "Driver '%s' needs updating - please use bus_type methods\n", drv->name); } - klist_init(&drv->klist_devices, NULL, NULL); ret = bus_add_driver(drv); if (ret) return ret; @@ -250,8 +258,12 @@ void driver_unregister(struct device_driver * drv) struct device_driver *driver_find(const char *name, struct bus_type *bus) { struct kobject *k = kset_find_obj(bus->p->drivers_kset, name); - if (k) - return to_drv(k); + struct driver_private *priv; + + if (k) { + priv = to_driver(k); + return priv->driver; + } return NULL; } diff --git a/drivers/base/module.c b/drivers/base/module.c index cad07be..103be9c 100644 --- a/drivers/base/module.c +++ b/drivers/base/module.c @@ -50,7 +50,7 @@ void module_add_driver(struct module *mod, struct device_driver *drv) if (mkobj) { mk = container_of(mkobj, struct module_kobject, kobj); /* remember our module structure */ - drv->mkobj = mk; + drv->p->mkobj = mk; /* kset_find_obj took a reference */ kobject_put(mkobj); } @@ -60,11 +60,11 @@ void module_add_driver(struct module *mod, struct device_driver *drv) return; /* Don't check return codes; these calls are idempotent */ - no_warn = sysfs_create_link(&drv->kobj, &mk->kobj, "module"); + no_warn = sysfs_create_link(&drv->p->kobj, &mk->kobj, "module"); driver_name = make_driver_name(drv); if (driver_name) { module_create_drivers_dir(mk); - no_warn = sysfs_create_link(mk->drivers_dir, &drv->kobj, + no_warn = sysfs_create_link(mk->drivers_dir, &drv->p->kobj, driver_name); kfree(driver_name); } @@ -78,12 +78,12 @@ void module_remove_driver(struct device_driver *drv) if (!drv) return; - sysfs_remove_link(&drv->kobj, "module"); + sysfs_remove_link(&drv->p->kobj, "module"); if (drv->owner) mk = &drv->owner->mkobj; - else if (drv->mkobj) - mk = drv->mkobj; + else if (drv->p->mkobj) + mk = drv->p->mkobj; if (mk && mk->drivers_dir) { driver_name = make_driver_name(drv); if (driver_name) { diff --git a/drivers/base/platform.c b/drivers/base/platform.c index d56a05f..bdd59e8 100644 --- a/drivers/base/platform.c +++ b/drivers/base/platform.c @@ -499,7 +499,7 @@ int __init_or_module platform_driver_probe(struct platform_driver *drv, */ spin_lock(&platform_bus_type.p->klist_drivers.k_lock); drv->probe = NULL; - if (code == 0 && list_empty(&drv->driver.klist_devices.k_list)) + if (code == 0 && list_empty(&drv->driver.p->klist_devices.k_list)) retval = -ENODEV; drv->driver.probe = platform_drv_probe_fail; spin_unlock(&platform_bus_type.p->klist_drivers.k_lock); -- cgit v1.1 From 7dc72b2842381684b864750af31a5fb168dec764 Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Wed, 28 Nov 2007 23:49:41 -0800 Subject: Driver core: clean up debugging messages The driver core debugging messages are a mess. This provides a unified message that makes them actually useful. The format for new kobject debug messages should be: driver/bus/class: 'OBJECT_NAME': FUNCTION_NAME: message.\n Note, the class code is not changed in this patch due to pending patches in my queue that this would conflict with. A later patch will clean them up. Cc: Kay Sievers Signed-off-by: Greg Kroah-Hartman --- drivers/base/bus.c | 14 +++++++------- drivers/base/core.c | 23 +++++++++++++---------- drivers/base/dd.c | 16 ++++++++-------- 3 files changed, 28 insertions(+), 25 deletions(-) (limited to 'drivers/base') diff --git a/drivers/base/bus.c b/drivers/base/bus.c index aa0c986..937fc10 100644 --- a/drivers/base/bus.c +++ b/drivers/base/bus.c @@ -80,7 +80,7 @@ static void driver_release(struct kobject *kobj) { struct driver_private *drv_priv = to_driver(kobj); - pr_debug("%s: freeing %s\n", __FUNCTION__, kobject_name(kobj)); + pr_debug("driver: '%s': %s\n", kobject_name(kobj), __FUNCTION__); kfree(drv_priv); } @@ -446,7 +446,7 @@ int bus_add_device(struct device * dev) int error = 0; if (bus) { - pr_debug("bus %s: add device %s\n", bus->name, dev->bus_id); + pr_debug("bus: '%s': add device %s\n", bus->name, dev->bus_id); error = device_add_attrs(bus, dev); if (error) goto out_put; @@ -519,7 +519,7 @@ void bus_remove_device(struct device * dev) dev->is_registered = 0; klist_del(&dev->knode_bus); } - pr_debug("bus %s: remove device %s\n", dev->bus->name, dev->bus_id); + pr_debug("bus: '%s': remove device %s\n", dev->bus->name, dev->bus_id); device_release_driver(dev); bus_put(dev->bus); } @@ -637,7 +637,7 @@ int bus_add_driver(struct device_driver *drv) if (!bus) return -EINVAL; - pr_debug("bus %s: add driver %s\n", bus->name, drv->name); + pr_debug("bus: '%s': add driver %s\n", bus->name, drv->name); priv = kzalloc(sizeof(*priv), GFP_KERNEL); if (!priv) @@ -707,7 +707,7 @@ void bus_remove_driver(struct device_driver * drv) driver_remove_attrs(drv->bus, drv); driver_remove_file(drv, &driver_attr_uevent); klist_remove(&drv->p->knode_bus); - pr_debug("bus %s: remove driver %s\n", drv->bus->name, drv->name); + pr_debug("bus: '%s': remove driver %s\n", drv->bus->name, drv->name); driver_detach(drv); module_remove_driver(drv); kobject_unregister(&drv->p->kobj); @@ -907,7 +907,7 @@ int bus_register(struct bus_type * bus) if (retval) goto bus_attrs_fail; - pr_debug("bus type '%s' registered\n", bus->name); + pr_debug("bus: '%s': registered\n", bus->name); return 0; bus_attrs_fail: @@ -934,7 +934,7 @@ out: */ void bus_unregister(struct bus_type * bus) { - pr_debug("bus %s: unregistering\n", bus->name); + pr_debug("bus: '%s': unregistering\n", bus->name); bus_remove_attrs(bus); remove_probe_files(bus); kset_unregister(bus->p->drivers_kset); diff --git a/drivers/base/core.c b/drivers/base/core.c index 414a480..22fdf32 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c @@ -193,15 +193,16 @@ static int dev_uevent(struct kset *kset, struct kobject *kobj, if (dev->bus && dev->bus->uevent) { retval = dev->bus->uevent(dev, env); if (retval) - pr_debug ("%s: bus uevent() returned %d\n", - __FUNCTION__, retval); + pr_debug("device: '%s': %s: bus uevent() returned %d\n", + dev->bus_id, __FUNCTION__, retval); } /* have the class specific function add its stuff */ if (dev->class && dev->class->dev_uevent) { retval = dev->class->dev_uevent(dev, env); if (retval) - pr_debug("%s: class uevent() returned %d\n", + pr_debug("device: '%s': %s: class uevent() " + "returned %d\n", dev->bus_id, __FUNCTION__, retval); } @@ -209,7 +210,8 @@ static int dev_uevent(struct kset *kset, struct kobject *kobj, if (dev->type && dev->type->uevent) { retval = dev->type->uevent(dev, env); if (retval) - pr_debug("%s: dev_type uevent() returned %d\n", + pr_debug("device: '%s': %s: dev_type uevent() " + "returned %d\n", dev->bus_id, __FUNCTION__, retval); } @@ -751,7 +753,7 @@ int device_add(struct device *dev) goto Error; } - pr_debug("DEV: registering device: ID = '%s'\n", dev->bus_id); + pr_debug("device: '%s': %s\n", dev->bus_id, __FUNCTION__); parent = get_device(dev->parent); error = setup_parent(dev, parent); @@ -1020,7 +1022,7 @@ void device_del(struct device * dev) */ void device_unregister(struct device * dev) { - pr_debug("DEV: Unregistering device. ID = '%s'\n", dev->bus_id); + pr_debug("device: '%s': %s\n", dev->bus_id, __FUNCTION__); device_del(dev); put_device(dev); } @@ -1116,7 +1118,7 @@ EXPORT_SYMBOL_GPL(device_remove_file); static void device_create_release(struct device *dev) { - pr_debug("%s called for %s\n", __FUNCTION__, dev->bus_id); + pr_debug("device: '%s': %s\n", dev->bus_id, __FUNCTION__); kfree(dev); } @@ -1259,7 +1261,8 @@ int device_rename(struct device *dev, char *new_name) if (!dev) return -EINVAL; - pr_debug("DEVICE: renaming '%s' to '%s'\n", dev->bus_id, new_name); + pr_debug("device: '%s': %s: renaming to '%s'\n", dev->bus_id, + __FUNCTION__, new_name); #ifdef CONFIG_SYSFS_DEPRECATED if ((dev->class) && (dev->parent)) @@ -1378,8 +1381,8 @@ int device_move(struct device *dev, struct device *new_parent) put_device(new_parent); goto out; } - pr_debug("DEVICE: moving '%s' to '%s'\n", dev->bus_id, - new_parent ? new_parent->bus_id : ""); + pr_debug("device: '%s': %s: moving to '%s'\n", dev->bus_id, + __FUNCTION__, new_parent ? new_parent->bus_id : ""); error = kobject_move(&dev->kobj, new_parent_kobj); if (error) { put_device(new_parent); diff --git a/drivers/base/dd.c b/drivers/base/dd.c index 87a348c..5492264 100644 --- a/drivers/base/dd.c +++ b/drivers/base/dd.c @@ -34,8 +34,8 @@ static void driver_bound(struct device *dev) return; } - pr_debug("bound device '%s' to driver '%s'\n", - dev->bus_id, dev->driver->name); + pr_debug("driver: '%s': %s: bound to device '%s'\n", dev->bus_id, + __FUNCTION__, dev->driver->name); if (dev->bus) blocking_notifier_call_chain(&dev->bus->p->bus_notifier, @@ -102,8 +102,8 @@ static int really_probe(struct device *dev, struct device_driver *drv) int ret = 0; atomic_inc(&probe_count); - pr_debug("%s: Probing driver %s with device %s\n", - drv->bus->name, drv->name, dev->bus_id); + pr_debug("bus: '%s': %s: probing driver %s with device %s\n", + drv->bus->name, __FUNCTION__, drv->name, dev->bus_id); WARN_ON(!list_empty(&dev->devres_head)); dev->driver = drv; @@ -125,8 +125,8 @@ static int really_probe(struct device *dev, struct device_driver *drv) driver_bound(dev); ret = 1; - pr_debug("%s: Bound Device %s to Driver %s\n", - drv->bus->name, dev->bus_id, drv->name); + pr_debug("bus: '%s': %s: bound device %s to driver %s\n", + drv->bus->name, __FUNCTION__, dev->bus_id, drv->name); goto done; probe_failed: @@ -192,8 +192,8 @@ int driver_probe_device(struct device_driver * drv, struct device * dev) if (drv->bus->match && !drv->bus->match(dev, drv)) goto done; - pr_debug("%s: Matched Device %s with Driver %s\n", - drv->bus->name, dev->bus_id, drv->name); + pr_debug("bus: '%s': %s: matched device %s with driver %s\n", + drv->bus->name, __FUNCTION__, dev->bus_id, drv->name); ret = really_probe(dev, drv); -- cgit v1.1 From c8e90d822bff3e0502d004facedb05859f98055f Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Mon, 17 Dec 2007 15:54:39 -0400 Subject: Kobject: change drivers/base/bus to use kobject_init_and_add Stop using kobject_register, as this way we can control the sending of the uevent properly, after everything is properly initialized. Cc: Kay Sievers Signed-off-by: Greg Kroah-Hartman --- drivers/base/bus.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'drivers/base') diff --git a/drivers/base/bus.c b/drivers/base/bus.c index 937fc10..aea5793 100644 --- a/drivers/base/bus.c +++ b/drivers/base/bus.c @@ -643,15 +643,12 @@ int bus_add_driver(struct device_driver *drv) if (!priv) return -ENOMEM; - error = kobject_set_name(&priv->kobj, "%s", drv->name); - if (error) - goto out_put_bus; - priv->kobj.kset = bus->p->drivers_kset; - priv->kobj.ktype = &driver_ktype; klist_init(&priv->klist_devices, NULL, NULL); priv->driver = drv; drv->p = priv; - error = kobject_register(&priv->kobj); + priv->kobj.kset = bus->p->drivers_kset; + error = kobject_init_and_add(&priv->kobj, &driver_ktype, NULL, + "%s", drv->name); if (error) goto out_put_bus; @@ -681,6 +678,7 @@ int bus_add_driver(struct device_driver *drv) __FUNCTION__, drv->name); } + kobject_uevent(&priv->kobj, KOBJ_ADD); return error; out_unregister: kobject_unregister(&priv->kobj); -- cgit v1.1 From ef2c51746dc89c2326ce522f8fb8a57695780e75 Mon Sep 17 00:00:00 2001 From: Alan Stern Date: Fri, 16 Nov 2007 11:57:28 -0500 Subject: Driver core: fix race in __device_release_driver This patch (as1013) was suggested by David Woodhouse; it fixes a race in the driver core. If a device is unregistered at the same time as its driver is unloaded, the driver's code pages may be unmapped while the remove method is still running. The calls to get_driver() and put_driver() were intended to prevent this, but they don't work if the driver's module count has already dropped to 0. Instead, the patch keeps the device on the driver's list until after the remove method has returned. This forces the necessary synchronization to occur. Signed-off-by: Alan Stern Signed-off-by: David Woodhouse Signed-off-by: Greg Kroah-Hartman --- drivers/base/dd.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'drivers/base') diff --git a/drivers/base/dd.c b/drivers/base/dd.c index 5492264..b0726eb 100644 --- a/drivers/base/dd.c +++ b/drivers/base/dd.c @@ -289,11 +289,10 @@ static void __device_release_driver(struct device * dev) { struct device_driver * drv; - drv = get_driver(dev->driver); + drv = dev->driver; if (drv) { driver_sysfs_remove(dev); sysfs_remove_link(&dev->kobj, "driver"); - klist_remove(&dev->knode_driver); if (dev->bus) blocking_notifier_call_chain(&dev->bus->p->bus_notifier, @@ -306,7 +305,7 @@ static void __device_release_driver(struct device * dev) drv->remove(dev); devres_release_all(dev); dev->driver = NULL; - put_driver(drv); + klist_remove(&dev->knode_driver); } } -- cgit v1.1 From da231fd5d113ab6da5dab7a2d2c38d0a540f939c Mon Sep 17 00:00:00 2001 From: Kay Sievers Date: Wed, 21 Nov 2007 17:29:15 +0100 Subject: Driver core: fix class glue dir cleanup logic We should remove the glue directory between the class and the bus device _after_ we sent out the 'remove' event for the device, otherwise the parent relationship is no longer valid, and composing the path with deleted sysfs entries will not work. Cc: Alan Stern Signed-off-by: Kay Sievers Signed-off-by: Greg Kroah-Hartman --- drivers/base/core.c | 206 ++++++++++++++++++++++++---------------------------- 1 file changed, 94 insertions(+), 112 deletions(-) (limited to 'drivers/base') diff --git a/drivers/base/core.c b/drivers/base/core.c index 22fdf32..13cae18 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c @@ -18,7 +18,7 @@ #include #include #include - +#include #include #include "base.h" @@ -538,22 +538,20 @@ void device_initialize(struct device *dev) } #ifdef CONFIG_SYSFS_DEPRECATED -static struct kobject * get_device_parent(struct device *dev, - struct device *parent) +static struct kobject *get_device_parent(struct device *dev, + struct device *parent) { - /* - * Set the parent to the class, not the parent device - * for topmost devices in class hierarchy. - * This keeps sysfs from having a symlink to make old - * udevs happy - */ + /* class devices without a parent live in /sys/class// */ if (dev->class && (!parent || parent->class != dev->class)) return &dev->class->subsys.kobj; + /* all other devices keep their parent */ else if (parent) return &parent->kobj; return NULL; } + +static inline void cleanup_device_parent(struct device *dev) {} #else static struct kobject *virtual_device_parent(struct device *dev) { @@ -566,8 +564,8 @@ static struct kobject *virtual_device_parent(struct device *dev) return virtual_dir; } -static struct kobject * get_device_parent(struct device *dev, - struct device *parent) +static struct kobject *get_device_parent(struct device *dev, + struct device *parent) { int retval; @@ -618,6 +616,34 @@ static struct kobject * get_device_parent(struct device *dev, return &parent->kobj; return NULL; } + +static void cleanup_device_parent(struct device *dev) +{ + struct device *d; + int other = 0; + + if (!dev->class) + return; + + /* see if we live in a parent class directory */ + if (dev->kobj.parent->kset != &dev->class->class_dirs) + return; + + /* if we are the last child of our class, delete the directory */ + down(&dev->class->sem); + list_for_each_entry(d, &dev->class->devices, node) { + if (d == dev) + continue; + if (d->kobj.parent == dev->kobj.parent) { + other = 1; + break; + } + } + if (!other) + kobject_del(dev->kobj.parent); + kobject_put(dev->kobj.parent); + up(&dev->class->sem); +} #endif static int setup_parent(struct device *dev, struct device *parent) @@ -637,65 +663,74 @@ static int device_add_class_symlinks(struct device *dev) if (!dev->class) return 0; + error = sysfs_create_link(&dev->kobj, &dev->class->subsys.kobj, "subsystem"); if (error) goto out; - /* - * If this is not a "fake" compatible device, then create the - * symlink from the class to the device. - */ + +#ifdef CONFIG_SYSFS_DEPRECATED + /* stacked class devices need a symlink in the class directory */ if (dev->kobj.parent != &dev->class->subsys.kobj) { error = sysfs_create_link(&dev->class->subsys.kobj, &dev->kobj, dev->bus_id); if (error) goto out_subsys; } + if (dev->parent) { -#ifdef CONFIG_SYSFS_DEPRECATED - { - struct device *parent = dev->parent; - char *class_name; - - /* - * In old sysfs stacked class devices had 'device' - * link pointing to real device instead of parent - */ - while (parent->class && !parent->bus && parent->parent) - parent = parent->parent; - - error = sysfs_create_link(&dev->kobj, - &parent->kobj, - "device"); - if (error) - goto out_busid; + struct device *parent = dev->parent; + char *class_name; - class_name = make_class_name(dev->class->name, - &dev->kobj); - if (class_name) - error = sysfs_create_link(&dev->parent->kobj, - &dev->kobj, class_name); - kfree(class_name); - if (error) - goto out_device; - } -#else - error = sysfs_create_link(&dev->kobj, &dev->parent->kobj, + /* + * stacked class devices have the 'device' link + * pointing to the bus device instead of the parent + */ + while (parent->class && !parent->bus && parent->parent) + parent = parent->parent; + + error = sysfs_create_link(&dev->kobj, + &parent->kobj, "device"); if (error) goto out_busid; -#endif + + class_name = make_class_name(dev->class->name, + &dev->kobj); + if (class_name) + error = sysfs_create_link(&dev->parent->kobj, + &dev->kobj, class_name); + kfree(class_name); + if (error) + goto out_device; } return 0; -#ifdef CONFIG_SYSFS_DEPRECATED out_device: if (dev->parent) sysfs_remove_link(&dev->kobj, "device"); -#endif out_busid: if (dev->kobj.parent != &dev->class->subsys.kobj) sysfs_remove_link(&dev->class->subsys.kobj, dev->bus_id); +#else + /* link in the class directory pointing to the device */ + error = sysfs_create_link(&dev->class->subsys.kobj, &dev->kobj, + dev->bus_id); + if (error) + goto out_subsys; + + if (dev->parent) { + error = sysfs_create_link(&dev->kobj, &dev->parent->kobj, + "device"); + if (error) + goto out_busid; + } + return 0; + +out_busid: + sysfs_remove_link(&dev->class->subsys.kobj, dev->bus_id); +#endif + out_subsys: sysfs_remove_link(&dev->kobj, "subsystem"); out: @@ -706,8 +741,9 @@ static void device_remove_class_symlinks(struct device *dev) { if (!dev->class) return; - if (dev->parent) { + #ifdef CONFIG_SYSFS_DEPRECATED + if (dev->parent) { char *class_name; class_name = make_class_name(dev->class->name, &dev->kobj); @@ -715,11 +751,18 @@ static void device_remove_class_symlinks(struct device *dev) sysfs_remove_link(&dev->parent->kobj, class_name); kfree(class_name); } -#endif sysfs_remove_link(&dev->kobj, "device"); } + if (dev->kobj.parent != &dev->class->subsys.kobj) sysfs_remove_link(&dev->class->subsys.kobj, dev->bus_id); +#else + if (dev->parent) + sysfs_remove_link(&dev->kobj, "device"); + + sysfs_remove_link(&dev->class->subsys.kobj, dev->bus_id); +#endif + sysfs_remove_link(&dev->kobj, "subsystem"); } @@ -830,26 +873,6 @@ int device_add(struct device *dev) SymlinkError: if (MAJOR(dev->devt)) device_remove_file(dev, &devt_attr); - - if (dev->class) { - sysfs_remove_link(&dev->kobj, "subsystem"); - /* If this is not a "fake" compatible device, remove the - * symlink from the class to the device. */ - if (dev->kobj.parent != &dev->class->subsys.kobj) - sysfs_remove_link(&dev->class->subsys.kobj, - dev->bus_id); - if (parent) { -#ifdef CONFIG_SYSFS_DEPRECATED - char *class_name = make_class_name(dev->class->name, - &dev->kobj); - if (class_name) - sysfs_remove_link(&dev->parent->kobj, - class_name); - kfree(class_name); -#endif - sysfs_remove_link(&dev->kobj, "device"); - } - } ueventattrError: device_remove_file(dev, &uevent_attr); attrError: @@ -932,23 +955,7 @@ void device_del(struct device * dev) if (MAJOR(dev->devt)) device_remove_file(dev, &devt_attr); if (dev->class) { - sysfs_remove_link(&dev->kobj, "subsystem"); - /* If this is not a "fake" compatible device, remove the - * symlink from the class to the device. */ - if (dev->kobj.parent != &dev->class->subsys.kobj) - sysfs_remove_link(&dev->class->subsys.kobj, - dev->bus_id); - if (parent) { -#ifdef CONFIG_SYSFS_DEPRECATED - char *class_name = make_class_name(dev->class->name, - &dev->kobj); - if (class_name) - sysfs_remove_link(&dev->parent->kobj, - class_name); - kfree(class_name); -#endif - sysfs_remove_link(&dev->kobj, "device"); - } + device_remove_class_symlinks(dev); down(&dev->class->sem); /* notify any interfaces that the device is now gone */ @@ -958,31 +965,6 @@ void device_del(struct device * dev) /* remove the device from the class list */ list_del_init(&dev->node); up(&dev->class->sem); - - /* If we live in a parent class-directory, unreference it */ - if (dev->kobj.parent->kset == &dev->class->class_dirs) { - struct device *d; - int other = 0; - - /* - * if we are the last child of our class, delete - * our class-directory at this parent - */ - down(&dev->class->sem); - list_for_each_entry(d, &dev->class->devices, node) { - if (d == dev) - continue; - if (d->kobj.parent == dev->kobj.parent) { - other = 1; - break; - } - } - if (!other) - kobject_del(dev->kobj.parent); - - kobject_put(dev->kobj.parent); - up(&dev->class->sem); - } } device_remove_file(dev, &uevent_attr); device_remove_attrs(dev); @@ -1004,9 +986,9 @@ void device_del(struct device * dev) blocking_notifier_call_chain(&dev->bus->p->bus_notifier, BUS_NOTIFY_DEL_DEVICE, dev); kobject_uevent(&dev->kobj, KOBJ_REMOVE); + cleanup_device_parent(dev); kobject_del(&dev->kobj); - if (parent) - put_device(parent); + put_device(parent); } /** -- cgit v1.1 From edfaa7c36574f1bf09c65ad602412db9da5f96bf Mon Sep 17 00:00:00 2001 From: Kay Sievers Date: Mon, 21 May 2007 22:08:01 +0200 Subject: Driver core: convert block from raw kobjects to core devices This moves the block devices to /sys/class/block. It will create a flat list of all block devices, with the disks and partitions in one directory. For compatibility /sys/block is created and contains symlinks to the disks. /sys/class/block |-- sda -> ../../devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda |-- sda1 -> ../../devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1 |-- sda10 -> ../../devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda10 |-- sda5 -> ../../devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5 |-- sda6 -> ../../devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda6 |-- sda7 -> ../../devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda7 |-- sda8 -> ../../devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda8 |-- sda9 -> ../../devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda9 `-- sr0 -> ../../devices/pci0000:00/0000:00:1f.2/host1/target1:0:0/1:0:0:0/block/sr0 /sys/block/ |-- sda -> ../devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda `-- sr0 -> ../devices/pci0000:00/0000:00:1f.2/host1/target1:0:0/1:0:0:0/block/sr0 Signed-off-by: Kay Sievers Signed-off-by: Greg Kroah-Hartman --- drivers/base/class.c | 7 +++++++ drivers/base/core.c | 20 ++++++++++++-------- 2 files changed, 19 insertions(+), 8 deletions(-) (limited to 'drivers/base') diff --git a/drivers/base/class.c b/drivers/base/class.c index ba6745b..624b331 100644 --- a/drivers/base/class.c +++ b/drivers/base/class.c @@ -17,6 +17,7 @@ #include #include #include +#include #include "base.h" #define to_class_attr(_attr) container_of(_attr, struct class_attribute, attr) @@ -149,7 +150,13 @@ int class_register(struct class * cls) if (error) return error; +#ifdef CONFIG_SYSFS_DEPRECATED + /* let the block class directory show up in the root of sysfs */ + if (cls != &block_class) + cls->subsys.kobj.kset = class_kset; +#else cls->subsys.kobj.kset = class_kset; +#endif cls->subsys.kobj.ktype = &class_ktype; error = kset_register(&cls->subsys); diff --git a/drivers/base/core.c b/drivers/base/core.c index 13cae18..06e8738 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c @@ -671,14 +671,15 @@ static int device_add_class_symlinks(struct device *dev) #ifdef CONFIG_SYSFS_DEPRECATED /* stacked class devices need a symlink in the class directory */ - if (dev->kobj.parent != &dev->class->subsys.kobj) { + if (dev->kobj.parent != &dev->class->subsys.kobj && + dev->type != &part_type) { error = sysfs_create_link(&dev->class->subsys.kobj, &dev->kobj, dev->bus_id); if (error) goto out_subsys; } - if (dev->parent) { + if (dev->parent && dev->type != &part_type) { struct device *parent = dev->parent; char *class_name; @@ -707,10 +708,11 @@ static int device_add_class_symlinks(struct device *dev) return 0; out_device: - if (dev->parent) + if (dev->parent && dev->type != &part_type) sysfs_remove_link(&dev->kobj, "device"); out_busid: - if (dev->kobj.parent != &dev->class->subsys.kobj) + if (dev->kobj.parent != &dev->class->subsys.kobj && + dev->type != &part_type) sysfs_remove_link(&dev->class->subsys.kobj, dev->bus_id); #else /* link in the class directory pointing to the device */ @@ -719,7 +721,7 @@ out_busid: if (error) goto out_subsys; - if (dev->parent) { + if (dev->parent && dev->type != &part_type) { error = sysfs_create_link(&dev->kobj, &dev->parent->kobj, "device"); if (error) @@ -743,7 +745,7 @@ static void device_remove_class_symlinks(struct device *dev) return; #ifdef CONFIG_SYSFS_DEPRECATED - if (dev->parent) { + if (dev->parent && dev->type != &part_type) { char *class_name; class_name = make_class_name(dev->class->name, &dev->kobj); @@ -754,10 +756,11 @@ static void device_remove_class_symlinks(struct device *dev) sysfs_remove_link(&dev->kobj, "device"); } - if (dev->kobj.parent != &dev->class->subsys.kobj) + if (dev->kobj.parent != &dev->class->subsys.kobj && + dev->type != &part_type) sysfs_remove_link(&dev->class->subsys.kobj, dev->bus_id); #else - if (dev->parent) + if (dev->parent && dev->type != &part_type) sysfs_remove_link(&dev->kobj, "device"); sysfs_remove_link(&dev->class->subsys.kobj, dev->bus_id); @@ -925,6 +928,7 @@ struct device * get_device(struct device * dev) */ void put_device(struct device * dev) { + /* might_sleep(); */ if (dev) kobject_put(&dev->kobj); } -- cgit v1.1 From b2d6db5878a0832659ed58476357eea2db915550 Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Mon, 17 Dec 2007 23:05:35 -0700 Subject: Kobject: rename kobject_add_ng() to kobject_add() Now that the old kobject_add() function is gone, rename kobject_add_ng() to kobject_add() to clean up the namespace. Cc: Kay Sievers Signed-off-by: Greg Kroah-Hartman --- drivers/base/class.c | 4 ++-- drivers/base/core.c | 6 +++--- drivers/base/driver.c | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) (limited to 'drivers/base') diff --git a/drivers/base/class.c b/drivers/base/class.c index 624b331..8e3cba2 100644 --- a/drivers/base/class.c +++ b/drivers/base/class.c @@ -586,8 +586,8 @@ int class_device_add(struct class_device *class_dev) else class_dev->kobj.parent = &parent_class->subsys.kobj; - error = kobject_add_ng(&class_dev->kobj, class_dev->kobj.parent, - "%s", class_dev->class_id); + error = kobject_add(&class_dev->kobj, class_dev->kobj.parent, + "%s", class_dev->class_id); if (error) goto out2; diff --git a/drivers/base/core.c b/drivers/base/core.c index 06e8738..e881702 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c @@ -602,7 +602,7 @@ static struct kobject *get_device_parent(struct device *dev, if (!k) return NULL; k->kset = &dev->class->class_dirs; - retval = kobject_add_ng(k, parent_kobj, "%s", dev->class->name); + retval = kobject_add(k, parent_kobj, "%s", dev->class->name); if (retval < 0) { kobject_put(k); return NULL; @@ -776,7 +776,7 @@ static void device_remove_class_symlinks(struct device *dev) * This is part 2 of device_register(), though may be called * separately _iff_ device_initialize() has been called separately. * - * This adds it to the kobject hierarchy via kobject_add_ng(), adds it + * This adds it to the kobject hierarchy via kobject_add(), adds it * to the global and sibling lists for the device, then * adds it to the other relevant subsystems of the driver model. */ @@ -807,7 +807,7 @@ int device_add(struct device *dev) goto Error; /* first, register with generic layer. */ - error = kobject_add_ng(&dev->kobj, dev->kobj.parent, "%s", dev->bus_id); + error = kobject_add(&dev->kobj, dev->kobj.parent, "%s", dev->bus_id); if (error) goto Error; diff --git a/drivers/base/driver.c b/drivers/base/driver.c index 5aacff2..94b697a 100644 --- a/drivers/base/driver.c +++ b/drivers/base/driver.c @@ -144,7 +144,7 @@ int driver_add_kobj(struct device_driver *drv, struct kobject *kobj, if (!name) return -ENOMEM; - return kobject_add_ng(kobj, &drv->p->kobj, "%s", name); + return kobject_add(kobj, &drv->p->kobj, "%s", name); } EXPORT_SYMBOL_GPL(driver_add_kobj); -- cgit v1.1 From f9cb074bff8e762ef24c44678a5a7d907f82fbeb Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Mon, 17 Dec 2007 23:05:35 -0700 Subject: Kobject: rename kobject_init_ng() to kobject_init() Now that the old kobject_init() function is gone, rename kobject_init_ng() to kobject_init() to clean up the namespace. Cc: Kay Sievers Signed-off-by: Greg Kroah-Hartman --- drivers/base/class.c | 2 +- drivers/base/core.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'drivers/base') diff --git a/drivers/base/class.c b/drivers/base/class.c index 8e3cba2..61fd26c 100644 --- a/drivers/base/class.c +++ b/drivers/base/class.c @@ -553,7 +553,7 @@ static struct class_device_attribute class_uevent_attr = void class_device_initialize(struct class_device *class_dev) { class_dev->kobj.kset = &class_obj_subsys; - kobject_init_ng(&class_dev->kobj, &class_device_ktype); + kobject_init(&class_dev->kobj, &class_device_ktype); INIT_LIST_HEAD(&class_dev->node); } diff --git a/drivers/base/core.c b/drivers/base/core.c index e881702..675a719 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c @@ -525,7 +525,7 @@ static void klist_children_put(struct klist_node *n) void device_initialize(struct device *dev) { dev->kobj.kset = devices_kset; - kobject_init_ng(&dev->kobj, &device_ktype); + kobject_init(&dev->kobj, &device_ktype); klist_init(&dev->klist_children, klist_children_get, klist_children_put); INIT_LIST_HEAD(&dev->dma_pools); -- cgit v1.1 From 0f4dafc0563c6c49e17fe14b3f5f356e4c4b8806 Mon Sep 17 00:00:00 2001 From: Kay Sievers Date: Wed, 19 Dec 2007 01:40:42 +0100 Subject: Kobject: auto-cleanup on final unref We save the current state in the object itself, so we can do proper cleanup when the last reference is dropped. If the initial reference is dropped, the object will be removed from sysfs if needed, if an "add" event was sent, "remove" will be send, and the allocated resources are released. This allows us to clean up some driver core usage as well as allowing us to do other such changes to the rest of the kernel. Signed-off-by: Kay Sievers Signed-off-by: Greg Kroah-Hartman --- drivers/base/core.c | 32 +++++++------------------------- 1 file changed, 7 insertions(+), 25 deletions(-) (limited to 'drivers/base') diff --git a/drivers/base/core.c b/drivers/base/core.c index 675a719..d5d542d 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c @@ -576,8 +576,8 @@ static struct kobject *get_device_parent(struct device *dev, /* * If we have no parent, we live in "virtual". - * Class-devices with a bus-device as parent, live - * in a class-directory to prevent namespace collisions. + * Class-devices with a non class-device as parent, live + * in a "glue" directory to prevent namespace collisions. */ if (parent == NULL) parent_kobj = virtual_device_parent(dev); @@ -607,8 +607,7 @@ static struct kobject *get_device_parent(struct device *dev, kobject_put(k); return NULL; } - /* Do not emit a uevent, as it's not needed for this - * "class glue" directory. */ + /* do not emit an uevent for this simple "glue" directory */ return k; } @@ -619,30 +618,13 @@ static struct kobject *get_device_parent(struct device *dev, static void cleanup_device_parent(struct device *dev) { - struct device *d; - int other = 0; + struct kobject *glue_dir = dev->kobj.parent; - if (!dev->class) - return; - - /* see if we live in a parent class directory */ - if (dev->kobj.parent->kset != &dev->class->class_dirs) + /* see if we live in a "glue" directory */ + if (!dev->class || glue_dir->kset != &dev->class->class_dirs) return; - /* if we are the last child of our class, delete the directory */ - down(&dev->class->sem); - list_for_each_entry(d, &dev->class->devices, node) { - if (d == dev) - continue; - if (d->kobj.parent == dev->kobj.parent) { - other = 1; - break; - } - } - if (!other) - kobject_del(dev->kobj.parent); - kobject_put(dev->kobj.parent); - up(&dev->class->sem); + kobject_put(glue_dir); } #endif -- cgit v1.1 From c10997f6575f476ff38442fa18fd4a0d80345f9d Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Thu, 20 Dec 2007 08:13:05 -0800 Subject: Kobject: convert drivers/* from kobject_unregister() to kobject_put() There is no need for kobject_unregister() anymore, thanks to Kay's kobject cleanup changes, so replace all instances of it with kobject_put(). Cc: Kay Sievers Signed-off-by: Greg Kroah-Hartman --- drivers/base/bus.c | 4 ++-- drivers/base/sys.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'drivers/base') diff --git a/drivers/base/bus.c b/drivers/base/bus.c index aea5793..a377b65 100644 --- a/drivers/base/bus.c +++ b/drivers/base/bus.c @@ -681,7 +681,7 @@ int bus_add_driver(struct device_driver *drv) kobject_uevent(&priv->kobj, KOBJ_ADD); return error; out_unregister: - kobject_unregister(&priv->kobj); + kobject_put(&priv->kobj); out_put_bus: bus_put(bus); return error; @@ -708,7 +708,7 @@ void bus_remove_driver(struct device_driver * drv) pr_debug("bus: '%s': remove driver %s\n", drv->bus->name, drv->name); driver_detach(drv); module_remove_driver(drv); - kobject_unregister(&drv->p->kobj); + kobject_put(&drv->p->kobj); bus_put(drv->bus); } diff --git a/drivers/base/sys.c b/drivers/base/sys.c index 47fc6eb..e666441 100644 --- a/drivers/base/sys.c +++ b/drivers/base/sys.c @@ -264,7 +264,7 @@ void sysdev_unregister(struct sys_device * sysdev) } mutex_unlock(&sysdev_drivers_lock); - kobject_unregister(&sysdev->kobj); + kobject_put(&sysdev->kobj); } -- cgit v1.1 From af5ca3f4ec5cc4432a42a73b050dd8898ce8fd00 Mon Sep 17 00:00:00 2001 From: Kay Sievers Date: Thu, 20 Dec 2007 02:09:39 +0100 Subject: Driver core: change sysdev classes to use dynamic kobject names All kobjects require a dynamically allocated name now. We no longer need to keep track if the name is statically assigned, we can just unconditionally free() all kobject names on cleanup. Signed-off-by: Kay Sievers Signed-off-by: Greg Kroah-Hartman --- drivers/base/class.c | 2 +- drivers/base/cpu.c | 2 +- drivers/base/memory.c | 2 +- drivers/base/node.c | 2 +- drivers/base/sys.c | 1 + 5 files changed, 5 insertions(+), 4 deletions(-) (limited to 'drivers/base') diff --git a/drivers/base/class.c b/drivers/base/class.c index 61fd26c..b962a76 100644 --- a/drivers/base/class.c +++ b/drivers/base/class.c @@ -466,7 +466,6 @@ static struct kset_uevent_ops class_uevent_ops = { * entirely soon. */ static struct kset class_obj_subsys = { - .kobj = { .k_name = "class_obj", }, .uevent_ops = &class_uevent_ops, }; @@ -872,6 +871,7 @@ int __init classes_init(void) /* ick, this is ugly, the things we go through to keep from showing up * in sysfs... */ kset_init(&class_obj_subsys); + kobject_set_name(&class_obj_subsys.kobj, "class_obj"); if (!class_obj_subsys.kobj.parent) class_obj_subsys.kobj.parent = &class_obj_subsys.kobj; return 0; diff --git a/drivers/base/cpu.c b/drivers/base/cpu.c index 4054507..c5885f5 100644 --- a/drivers/base/cpu.c +++ b/drivers/base/cpu.c @@ -14,7 +14,7 @@ #include "base.h" struct sysdev_class cpu_sysdev_class = { - set_kset_name("cpu"), + .name = "cpu", }; EXPORT_SYMBOL(cpu_sysdev_class); diff --git a/drivers/base/memory.c b/drivers/base/memory.c index 7868707..7ae413f 100644 --- a/drivers/base/memory.c +++ b/drivers/base/memory.c @@ -26,7 +26,7 @@ #define MEMORY_CLASS_NAME "memory" static struct sysdev_class memory_sysdev_class = { - set_kset_name(MEMORY_CLASS_NAME), + .name = MEMORY_CLASS_NAME, }; static const char *memory_uevent_name(struct kset *kset, struct kobject *kobj) diff --git a/drivers/base/node.c b/drivers/base/node.c index 88eeed7..e59861f 100644 --- a/drivers/base/node.c +++ b/drivers/base/node.c @@ -15,7 +15,7 @@ #include static struct sysdev_class node_class = { - set_kset_name("node"), + .name = "node", }; diff --git a/drivers/base/sys.c b/drivers/base/sys.c index e666441..2f79c55 100644 --- a/drivers/base/sys.c +++ b/drivers/base/sys.c @@ -136,6 +136,7 @@ int sysdev_class_register(struct sysdev_class * cls) cls->kset.kobj.parent = &system_kset->kobj; cls->kset.kobj.ktype = &ktype_sysdev_class; cls->kset.kobj.kset = system_kset; + kobject_set_name(&cls->kset.kobj, cls->name); return kset_register(&cls->kset); } -- cgit v1.1 From db1118a460c7bfd20278955cbf56c0b283a9701f Mon Sep 17 00:00:00 2001 From: Denis Cheng Date: Thu, 6 Dec 2007 02:24:40 +0800 Subject: Driver core: use LIST_HEAD instead of call to INIT_LIST_HEAD in __init LIST_HEAD has been widely used, so switch to this simpler method. Signed-off-by: Denis Cheng Signed-off-by: Greg Kroah-Hartman --- drivers/base/attribute_container.c | 9 +-------- drivers/base/base.h | 1 - drivers/base/init.c | 1 - 3 files changed, 1 insertion(+), 10 deletions(-) (limited to 'drivers/base') diff --git a/drivers/base/attribute_container.c b/drivers/base/attribute_container.c index 7370d7c..d4dfb97 100644 --- a/drivers/base/attribute_container.c +++ b/drivers/base/attribute_container.c @@ -61,7 +61,7 @@ attribute_container_classdev_to_container(struct class_device *classdev) } EXPORT_SYMBOL_GPL(attribute_container_classdev_to_container); -static struct list_head attribute_container_list; +static LIST_HEAD(attribute_container_list); static DEFINE_MUTEX(attribute_container_mutex); @@ -429,10 +429,3 @@ attribute_container_find_class_device(struct attribute_container *cont, return cdev; } EXPORT_SYMBOL_GPL(attribute_container_find_class_device); - -int __init -attribute_container_init(void) -{ - INIT_LIST_HEAD(&attribute_container_list); - return 0; -} diff --git a/drivers/base/base.h b/drivers/base/base.h index 3b0f395..a74ceda 100644 --- a/drivers/base/base.h +++ b/drivers/base/base.h @@ -49,7 +49,6 @@ static inline int hypervisor_init(void) { return 0; } extern int platform_bus_init(void); extern int system_bus_init(void); extern int cpu_dev_init(void); -extern int attribute_container_init(void); extern int bus_add_device(struct device * dev); extern void bus_attach_device(struct device * dev); diff --git a/drivers/base/init.c b/drivers/base/init.c index 3713815..1da88a1 100644 --- a/drivers/base/init.c +++ b/drivers/base/init.c @@ -36,5 +36,4 @@ void __init driver_init(void) system_bus_init(); cpu_dev_init(); memory_dev_init(); - attribute_container_init(); } -- cgit v1.1 From 92b421416f8194aec87b1439487b5544e9ac8187 Mon Sep 17 00:00:00 2001 From: Randy Dunlap Date: Mon, 31 Dec 2007 10:05:43 -0800 Subject: driver core: fix build with SYSFS=n When SYSFS=n and MODULES=y, build ends with: linux-2.6.24-rc6-mm1/drivers/base/module.c: In function 'module_add_driver': linux-2.6.24-rc6-mm1/drivers/base/module.c:49: error: 'module_kset' undeclared (first use in this function) make[3]: *** [drivers/base/module.o] Error 1 Below is one possible fix. Build-tested with all 4 config combinations of SYSFS & MODULES. Signed-off-by: Randy Dunlap Signed-off-by: Greg Kroah-Hartman --- drivers/base/Makefile | 2 ++ drivers/base/base.h | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) (limited to 'drivers/base') diff --git a/drivers/base/Makefile b/drivers/base/Makefile index ff26968..63e09c0 100644 --- a/drivers/base/Makefile +++ b/drivers/base/Makefile @@ -11,7 +11,9 @@ obj-$(CONFIG_FW_LOADER) += firmware_class.o obj-$(CONFIG_NUMA) += node.o obj-$(CONFIG_MEMORY_HOTPLUG_SPARSE) += memory.o obj-$(CONFIG_SMP) += topology.o +ifeq ($(CONFIG_SYSFS),y) obj-$(CONFIG_MODULES) += module.o +endif obj-$(CONFIG_SYS_HYPERVISOR) += hypervisor.o ifeq ($(CONFIG_DEBUG_DRIVER),y) diff --git a/drivers/base/base.h b/drivers/base/base.h index a74ceda..f7ad65a 100644 --- a/drivers/base/base.h +++ b/drivers/base/base.h @@ -81,7 +81,7 @@ extern int devres_release_all(struct device *dev); extern struct kset *devices_kset; -#ifdef CONFIG_MODULES +#if defined(CONFIG_MODULES) && defined(CONFIG_SYSFS) extern void module_add_driver(struct module *mod, struct device_driver *drv); extern void module_remove_driver(struct device_driver *drv); #else -- cgit v1.1 From ae72cddb2338bc36b991674a56a7bf70ae104d9e Mon Sep 17 00:00:00 2001 From: Stephen Rothwell Date: Fri, 11 Jan 2008 17:24:53 +1100 Subject: Driver Core: constify the name passed to platform_device_register_simple This name is just passed to platform_device_alloc which has its parameter declared const. Signed-off-by: Stephen Rothwell Signed-off-by: Greg Kroah-Hartman --- drivers/base/platform.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'drivers/base') diff --git a/drivers/base/platform.c b/drivers/base/platform.c index bdd59e8..48d5db4 100644 --- a/drivers/base/platform.c +++ b/drivers/base/platform.c @@ -360,7 +360,7 @@ EXPORT_SYMBOL_GPL(platform_device_unregister); * the Linux driver model. In particular, when such drivers are built * as modules, they can't be "hotplugged". */ -struct platform_device *platform_device_register_simple(char *name, int id, +struct platform_device *platform_device_register_simple(const char *name, int id, struct resource *res, unsigned int num) { struct platform_device *pdev; -- cgit v1.1 From 63b6971a0876b744e2fcf3c9df15d130501e1deb Mon Sep 17 00:00:00 2001 From: Cornelia Huck Date: Mon, 21 Jan 2008 16:09:44 +0100 Subject: Driver core: Cleanup get_device_parent() in device_add() and device_move() Make setup_parent() void as get_device_parent() will always return either a valid kobject or NULL. Introduce cleanup_glue_dir() to drop reference grabbed on "glue" directory by get_device_parent(). Use it for cleanup in device_move() and device_add() on errors. This should fix the refcounting problem reported in http://marc.info/?l=linux-kernel&m=120052487909200&w=2 Signed-off-by: Cornelia Huck Cc: Dave Young Cc: Gabor Gombas Cc: Tejun Heo Cc: Al Viro Cc: Marcel Holtmann Cc: David Miller Cc: Kay Sievers Signed-off-by: Greg Kroah-Hartman --- drivers/base/core.c | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) (limited to 'drivers/base') diff --git a/drivers/base/core.c b/drivers/base/core.c index d5d542d..f09dde3 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c @@ -552,6 +552,8 @@ static struct kobject *get_device_parent(struct device *dev, } static inline void cleanup_device_parent(struct device *dev) {} +static inline void cleanup_glue_dir(struct device *dev, + struct kobject *glue_dir) {} #else static struct kobject *virtual_device_parent(struct device *dev) { @@ -616,27 +618,27 @@ static struct kobject *get_device_parent(struct device *dev, return NULL; } -static void cleanup_device_parent(struct device *dev) +static void cleanup_glue_dir(struct device *dev, struct kobject *glue_dir) { - struct kobject *glue_dir = dev->kobj.parent; - /* see if we live in a "glue" directory */ if (!dev->class || glue_dir->kset != &dev->class->class_dirs) return; kobject_put(glue_dir); } + +static void cleanup_device_parent(struct device *dev) +{ + cleanup_glue_dir(dev, dev->kobj.parent); +} #endif -static int setup_parent(struct device *dev, struct device *parent) +static void setup_parent(struct device *dev, struct device *parent) { struct kobject *kobj; kobj = get_device_parent(dev, parent); - if (IS_ERR(kobj)) - return PTR_ERR(kobj); if (kobj) dev->kobj.parent = kobj; - return 0; } static int device_add_class_symlinks(struct device *dev) @@ -784,9 +786,7 @@ int device_add(struct device *dev) pr_debug("device: '%s': %s\n", dev->bus_id, __FUNCTION__); parent = get_device(dev->parent); - error = setup_parent(dev, parent); - if (error) - goto Error; + setup_parent(dev, parent); /* first, register with generic layer. */ error = kobject_add(&dev->kobj, dev->kobj.parent, "%s", dev->bus_id); @@ -864,6 +864,7 @@ int device_add(struct device *dev) kobject_uevent(&dev->kobj, KOBJ_REMOVE); kobject_del(&dev->kobj); Error: + cleanup_device_parent(dev); if (parent) put_device(parent); goto Done; @@ -1344,15 +1345,12 @@ int device_move(struct device *dev, struct device *new_parent) new_parent = get_device(new_parent); new_parent_kobj = get_device_parent (dev, new_parent); - if (IS_ERR(new_parent_kobj)) { - error = PTR_ERR(new_parent_kobj); - put_device(new_parent); - goto out; - } + pr_debug("device: '%s': %s: moving to '%s'\n", dev->bus_id, __FUNCTION__, new_parent ? new_parent->bus_id : ""); error = kobject_move(&dev->kobj, new_parent_kobj); if (error) { + cleanup_glue_dir(dev, new_parent_kobj); put_device(new_parent); goto out; } @@ -1375,6 +1373,7 @@ int device_move(struct device *dev, struct device *new_parent) klist_add_tail(&dev->knode_parent, &old_parent->klist_children); } + cleanup_glue_dir(dev, new_parent_kobj); put_device(new_parent); goto out; } -- cgit v1.1 From fd04897bb20be29d60f7e426a053545aebeaa61a Mon Sep 17 00:00:00 2001 From: Dave Young Date: Tue, 22 Jan 2008 15:27:08 +0800 Subject: Driver Core: add class iteration api Add the following class iteration functions for driver use: class_for_each_device class_find_device class_for_each_child class_find_child Signed-off-by: Dave Young Acked-by: Cornelia Huck Signed-off-by: Greg Kroah-Hartman --- drivers/base/class.c | 133 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 133 insertions(+) (limited to 'drivers/base') diff --git a/drivers/base/class.c b/drivers/base/class.c index b962a76..9f737ff 100644 --- a/drivers/base/class.c +++ b/drivers/base/class.c @@ -809,6 +809,139 @@ void class_device_put(struct class_device *class_dev) kobject_put(&class_dev->kobj); } +/** + * class_for_each_device - device iterator + * @class: the class we're iterating + * @data: data for the callback + * @fn: function to be called for each device + * + * Iterate over @class's list of devices, and call @fn for each, + * passing it @data. + * + * We check the return of @fn each time. If it returns anything + * other than 0, we break out and return that value. + * + * Note, we hold class->sem in this function, so it can not be + * re-acquired in @fn, otherwise it will self-deadlocking. For + * example, calls to add or remove class members would be verboten. + */ +int class_for_each_device(struct class *class, void *data, + int (*fn)(struct device *, void *)) +{ + struct device *dev; + int error = 0; + + if (!class) + return -EINVAL; + down(&class->sem); + list_for_each_entry(dev, &class->devices, node) { + dev = get_device(dev); + if (dev) { + error = fn(dev, data); + put_device(dev); + } else + error = -ENODEV; + if (error) + break; + } + up(&class->sem); + + return error; +} +EXPORT_SYMBOL_GPL(class_for_each_device); + +/** + * class_find_device - device iterator for locating a particular device + * @class: the class we're iterating + * @data: data for the match function + * @match: function to check device + * + * This is similar to the class_for_each_dev() function above, but it + * returns a reference to a device that is 'found' for later use, as + * determined by the @match callback. + * + * The callback should return 0 if the device doesn't match and non-zero + * if it does. If the callback returns non-zero, this function will + * return to the caller and not iterate over any more devices. + + * Note, you will need to drop the reference with put_device() after use. + * + * We hold class->sem in this function, so it can not be + * re-acquired in @match, otherwise it will self-deadlocking. For + * example, calls to add or remove class members would be verboten. + */ +struct device *class_find_device(struct class *class, void *data, + int (*match)(struct device *, void *)) +{ + struct device *dev; + int found = 0; + + if (!class) + return NULL; + + down(&class->sem); + list_for_each_entry(dev, &class->devices, node) { + dev = get_device(dev); + if (dev) { + if (match(dev, data)) { + found = 1; + break; + } else + put_device(dev); + } else + break; + } + up(&class->sem); + + return found ? dev : NULL; +} +EXPORT_SYMBOL_GPL(class_find_device); + +/** + * class_find_child - device iterator for locating a particular class_device + * @class: the class we're iterating + * @data: data for the match function + * @match: function to check class_device + * + * This function returns a reference to a class_device that is 'found' for + * later use, as determined by the @match callback. + * + * The callback should return 0 if the class_device doesn't match and non-zero + * if it does. If the callback returns non-zero, this function will + * return to the caller and not iterate over any more class_devices. + * + * Note, you will need to drop the reference with class_device_put() after use. + * + * We hold class->sem in this function, so it can not be + * re-acquired in @match, otherwise it will self-deadlocking. For + * example, calls to add or remove class members would be verboten. + */ +struct class_device *class_find_child(struct class *class, void *data, + int (*match)(struct class_device *, void *)) +{ + struct class_device *dev; + int found = 0; + + if (!class) + return NULL; + + down(&class->sem); + list_for_each_entry(dev, &class->children, node) { + dev = class_device_get(dev); + if (dev) { + if (match(dev, data)) { + found = 1; + break; + } else + class_device_put(dev); + } else + break; + } + up(&class->sem); + + return found ? dev : NULL; +} +EXPORT_SYMBOL_GPL(class_find_child); int class_interface_register(struct class_interface *class_intf) { -- cgit v1.1 From 4a3ad20ccd8f4d2a0535cf98fa83f7b561ba59a9 Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Thu, 24 Jan 2008 22:50:12 -0800 Subject: Driver core: coding style fixes Fix up a number of coding style issues in the drivers/base/ directory that have annoyed me over the years. checkpatch.pl is now very happy. Signed-off-by: Greg Kroah-Hartman --- drivers/base/base.h | 14 +-- drivers/base/bus.c | 290 +++++++++++++++++++++++------------------------- drivers/base/class.c | 140 +++++++++++------------ drivers/base/core.c | 203 ++++++++++++++++----------------- drivers/base/dd.c | 119 ++++++++++---------- drivers/base/driver.c | 120 +++++++++----------- drivers/base/init.c | 9 +- drivers/base/platform.c | 233 +++++++++++++++++++------------------- 8 files changed, 545 insertions(+), 583 deletions(-) (limited to 'drivers/base') diff --git a/drivers/base/base.h b/drivers/base/base.h index f7ad65a..c044414 100644 --- a/drivers/base/base.h +++ b/drivers/base/base.h @@ -50,15 +50,15 @@ extern int platform_bus_init(void); extern int system_bus_init(void); extern int cpu_dev_init(void); -extern int bus_add_device(struct device * dev); -extern void bus_attach_device(struct device * dev); -extern void bus_remove_device(struct device * dev); +extern int bus_add_device(struct device *dev); +extern void bus_attach_device(struct device *dev); +extern void bus_remove_device(struct device *dev); -extern int bus_add_driver(struct device_driver *); -extern void bus_remove_driver(struct device_driver *); +extern int bus_add_driver(struct device_driver *drv); +extern void bus_remove_driver(struct device_driver *drv); -extern void driver_detach(struct device_driver * drv); -extern int driver_probe_device(struct device_driver *, struct device *); +extern void driver_detach(struct device_driver *drv); +extern int driver_probe_device(struct device_driver *drv, struct device *dev); extern void sysdev_shutdown(void); extern int sysdev_suspend(pm_message_t state); diff --git a/drivers/base/bus.c b/drivers/base/bus.c index a377b65..f484495 100644 --- a/drivers/base/bus.c +++ b/drivers/base/bus.c @@ -46,10 +46,10 @@ static void bus_put(struct bus_type *bus) kset_put(&bus->p->subsys); } -static ssize_t -drv_attr_show(struct kobject * kobj, struct attribute * attr, char * buf) +static ssize_t drv_attr_show(struct kobject *kobj, struct attribute *attr, + char *buf) { - struct driver_attribute * drv_attr = to_drv_attr(attr); + struct driver_attribute *drv_attr = to_drv_attr(attr); struct driver_private *drv_priv = to_driver(kobj); ssize_t ret = -EIO; @@ -58,11 +58,10 @@ drv_attr_show(struct kobject * kobj, struct attribute * attr, char * buf) return ret; } -static ssize_t -drv_attr_store(struct kobject * kobj, struct attribute * attr, - const char * buf, size_t count) +static ssize_t drv_attr_store(struct kobject *kobj, struct attribute *attr, + const char *buf, size_t count) { - struct driver_attribute * drv_attr = to_drv_attr(attr); + struct driver_attribute *drv_attr = to_drv_attr(attr); struct driver_private *drv_priv = to_driver(kobj); ssize_t ret = -EIO; @@ -89,16 +88,13 @@ static struct kobj_type driver_ktype = { .release = driver_release, }; - /* * sysfs bindings for buses */ - - -static ssize_t -bus_attr_show(struct kobject * kobj, struct attribute * attr, char * buf) +static ssize_t bus_attr_show(struct kobject *kobj, struct attribute *attr, + char *buf) { - struct bus_attribute * bus_attr = to_bus_attr(attr); + struct bus_attribute *bus_attr = to_bus_attr(attr); struct bus_type_private *bus_priv = to_bus(kobj); ssize_t ret = 0; @@ -107,11 +103,10 @@ bus_attr_show(struct kobject * kobj, struct attribute * attr, char * buf) return ret; } -static ssize_t -bus_attr_store(struct kobject * kobj, struct attribute * attr, - const char * buf, size_t count) +static ssize_t bus_attr_store(struct kobject *kobj, struct attribute *attr, + const char *buf, size_t count) { - struct bus_attribute * bus_attr = to_bus_attr(attr); + struct bus_attribute *bus_attr = to_bus_attr(attr); struct bus_type_private *bus_priv = to_bus(kobj); ssize_t ret = 0; @@ -125,7 +120,7 @@ static 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(struct bus_type *bus, struct bus_attribute *attr) { int error; if (bus_get(bus)) { @@ -135,14 +130,16 @@ int bus_create_file(struct bus_type * bus, struct bus_attribute * attr) error = -EINVAL; return error; } +EXPORT_SYMBOL_GPL(bus_create_file); -void bus_remove_file(struct bus_type * bus, struct bus_attribute * attr) +void bus_remove_file(struct bus_type *bus, struct bus_attribute *attr) { if (bus_get(bus)) { sysfs_remove_file(&bus->p->subsys.kobj, &attr->attr); bus_put(bus); } } +EXPORT_SYMBOL_GPL(bus_remove_file); static struct kobj_type bus_ktype = { .sysfs_ops = &bus_sysfs_ops, @@ -219,10 +216,13 @@ static ssize_t driver_bind(struct device_driver *drv, if (dev->parent) up(&dev->parent->sem); - if (err > 0) /* success */ + if (err > 0) { + /* success */ err = count; - else if (err == 0) /* driver didn't accept device */ + } else if (err == 0) { + /* driver didn't accept device */ err = -ENODEV; + } } put_device(dev); bus_put(bus); @@ -259,37 +259,36 @@ static ssize_t store_drivers_probe(struct bus_type *bus, } #endif -static struct device * next_device(struct klist_iter * i) +static struct device *next_device(struct klist_iter *i) { - struct klist_node * n = klist_next(i); + struct klist_node *n = klist_next(i); return n ? container_of(n, struct device, knode_bus) : NULL; } /** - * bus_for_each_dev - device iterator. - * @bus: bus type. - * @start: device to start iterating from. - * @data: data for the callback. - * @fn: function to be called for each device. + * bus_for_each_dev - device iterator. + * @bus: bus type. + * @start: device to start iterating from. + * @data: data for the callback. + * @fn: function to be called for each device. * - * Iterate over @bus's list of devices, and call @fn for each, - * passing it @data. If @start is not NULL, we use that device to - * begin iterating from. + * Iterate over @bus's list of devices, and call @fn for each, + * passing it @data. If @start is not NULL, we use that device to + * begin iterating from. * - * We check the return of @fn each time. If it returns anything - * other than 0, we break out and return that value. + * We check the return of @fn each time. If it returns anything + * other than 0, we break out and return that value. * - * NOTE: The device that returns a non-zero value is not retained - * in any way, nor is its refcount incremented. If the caller needs - * to retain this data, it should do, and increment the reference - * count in the supplied callback. + * NOTE: The device that returns a non-zero value is not retained + * in any way, nor is its refcount incremented. If the caller needs + * to retain this data, it should do, and increment the reference + * count in the supplied callback. */ - -int bus_for_each_dev(struct bus_type * bus, struct device * start, - void * data, int (*fn)(struct device *, void *)) +int bus_for_each_dev(struct bus_type *bus, struct device *start, + void *data, int (*fn)(struct device *, void *)) { struct klist_iter i; - struct device * dev; + struct device *dev; int error = 0; if (!bus) @@ -302,6 +301,7 @@ int bus_for_each_dev(struct bus_type * bus, struct device * start, klist_iter_exit(&i); return error; } +EXPORT_SYMBOL_GPL(bus_for_each_dev); /** * bus_find_device - device iterator for locating a particular device. @@ -318,9 +318,9 @@ int bus_for_each_dev(struct bus_type * bus, struct device * start, * if it does. If the callback returns non-zero, this function will * return to the caller and not iterate over any more devices. */ -struct device * bus_find_device(struct bus_type *bus, - struct device *start, void *data, - int (*match)(struct device *, void *)) +struct device *bus_find_device(struct bus_type *bus, + struct device *start, void *data, + int (*match)(struct device *dev, void *data)) { struct klist_iter i; struct device *dev; @@ -336,11 +336,11 @@ struct device * bus_find_device(struct bus_type *bus, klist_iter_exit(&i); return dev; } +EXPORT_SYMBOL_GPL(bus_find_device); - -static struct device_driver * next_driver(struct klist_iter * i) +static struct device_driver *next_driver(struct klist_iter *i) { - struct klist_node * n = klist_next(i); + struct klist_node *n = klist_next(i); struct driver_private *drv_priv; if (n) { @@ -351,30 +351,29 @@ static struct device_driver * next_driver(struct klist_iter * i) } /** - * bus_for_each_drv - driver iterator - * @bus: bus we're dealing with. - * @start: driver to start iterating on. - * @data: data to pass to the callback. - * @fn: function to call for each driver. + * bus_for_each_drv - driver iterator + * @bus: bus we're dealing with. + * @start: driver to start iterating on. + * @data: data to pass to the callback. + * @fn: function to call for each driver. * - * This is nearly identical to the device iterator above. - * We iterate over each driver that belongs to @bus, and call - * @fn for each. If @fn returns anything but 0, we break out - * and return it. If @start is not NULL, we use it as the head - * of the list. + * This is nearly identical to the device iterator above. + * We iterate over each driver that belongs to @bus, and call + * @fn for each. If @fn returns anything but 0, we break out + * and return it. If @start is not NULL, we use it as the head + * of the list. * - * NOTE: we don't return the driver that returns a non-zero - * value, nor do we leave the reference count incremented for that - * driver. If the caller needs to know that info, it must set it - * in the callback. It must also be sure to increment the refcount - * so it doesn't disappear before returning to the caller. + * NOTE: we don't return the driver that returns a non-zero + * value, nor do we leave the reference count incremented for that + * driver. If the caller needs to know that info, it must set it + * in the callback. It must also be sure to increment the refcount + * so it doesn't disappear before returning to the caller. */ - -int bus_for_each_drv(struct bus_type * bus, struct device_driver * start, - void * data, int (*fn)(struct device_driver *, void *)) +int bus_for_each_drv(struct bus_type *bus, struct device_driver *start, + void *data, int (*fn)(struct device_driver *, void *)) { struct klist_iter i; - struct device_driver * drv; + struct device_driver *drv; int error = 0; if (!bus) @@ -387,6 +386,7 @@ int bus_for_each_drv(struct bus_type * bus, struct device_driver * start, klist_iter_exit(&i); return error; } +EXPORT_SYMBOL_GPL(bus_for_each_drv); static int device_add_attrs(struct bus_type *bus, struct device *dev) { @@ -397,7 +397,7 @@ static int device_add_attrs(struct bus_type *bus, struct device *dev) return 0; for (i = 0; attr_name(bus->dev_attrs[i]); i++) { - error = device_create_file(dev,&bus->dev_attrs[i]); + error = device_create_file(dev, &bus->dev_attrs[i]); if (error) { while (--i >= 0) device_remove_file(dev, &bus->dev_attrs[i]); @@ -407,13 +407,13 @@ static int device_add_attrs(struct bus_type *bus, struct device *dev) return error; } -static void device_remove_attrs(struct bus_type * bus, struct device * dev) +static void device_remove_attrs(struct bus_type *bus, struct device *dev) { int i; if (bus->dev_attrs) { for (i = 0; attr_name(bus->dev_attrs[i]); i++) - device_remove_file(dev,&bus->dev_attrs[i]); + device_remove_file(dev, &bus->dev_attrs[i]); } } @@ -434,15 +434,15 @@ static inline void remove_deprecated_bus_links(struct device *dev) { } #endif /** - * bus_add_device - add device to bus - * @dev: device being added + * bus_add_device - add device to bus + * @dev: device being added * - * - Add the device to its bus's list of devices. - * - Create link to device's bus. + * - Add the device to its bus's list of devices. + * - Create link to device's bus. */ -int bus_add_device(struct device * dev) +int bus_add_device(struct device *dev) { - struct bus_type * bus = bus_get(dev->bus); + struct bus_type *bus = bus_get(dev->bus); int error = 0; if (bus) { @@ -476,13 +476,13 @@ out_put: } /** - * bus_attach_device - add device to bus - * @dev: device tried to attach to a driver + * bus_attach_device - add device to bus + * @dev: device tried to attach to a driver * - * - Add device to bus's list of devices. - * - Try to attach to driver. + * - Add device to bus's list of devices. + * - Try to attach to driver. */ -void bus_attach_device(struct device * dev) +void bus_attach_device(struct device *dev) { struct bus_type *bus = dev->bus; int ret = 0; @@ -500,32 +500,34 @@ void bus_attach_device(struct device * dev) } /** - * bus_remove_device - remove device from bus - * @dev: device to be removed + * bus_remove_device - remove device from bus + * @dev: device to be removed * - * - Remove symlink from bus's directory. - * - Delete device from bus's list. - * - Detach from its driver. - * - Drop reference taken in bus_add_device(). + * - Remove symlink from bus's directory. + * - Delete device from bus's list. + * - Detach from its driver. + * - Drop reference taken in bus_add_device(). */ -void bus_remove_device(struct device * dev) +void bus_remove_device(struct device *dev) { if (dev->bus) { sysfs_remove_link(&dev->kobj, "subsystem"); remove_deprecated_bus_links(dev); - sysfs_remove_link(&dev->bus->p->devices_kset->kobj, dev->bus_id); + sysfs_remove_link(&dev->bus->p->devices_kset->kobj, + dev->bus_id); device_remove_attrs(dev->bus, dev); if (dev->is_registered) { dev->is_registered = 0; klist_del(&dev->knode_bus); } - pr_debug("bus: '%s': remove device %s\n", dev->bus->name, dev->bus_id); + pr_debug("bus: '%s': remove device %s\n", + dev->bus->name, dev->bus_id); device_release_driver(dev); bus_put(dev->bus); } } -static int driver_add_attrs(struct bus_type * bus, struct device_driver * drv) +static int driver_add_attrs(struct bus_type *bus, struct device_driver *drv) { int error = 0; int i; @@ -534,19 +536,19 @@ static int driver_add_attrs(struct bus_type * bus, struct device_driver * drv) for (i = 0; attr_name(bus->drv_attrs[i]); i++) { error = driver_create_file(drv, &bus->drv_attrs[i]); if (error) - goto Err; + goto err; } } - Done: +done: return error; - Err: +err: while (--i >= 0) driver_remove_file(drv, &bus->drv_attrs[i]); - goto Done; + goto done; } - -static void driver_remove_attrs(struct bus_type * bus, struct device_driver * drv) +static void driver_remove_attrs(struct bus_type *bus, + struct device_driver *drv) { int i; @@ -623,9 +625,8 @@ static ssize_t driver_uevent_store(struct device_driver *drv, static DRIVER_ATTR(uevent, S_IWUSR, NULL, driver_uevent_store); /** - * bus_add_driver - Add a driver to the bus. - * @drv: driver. - * + * bus_add_driver - Add a driver to the bus. + * @drv: driver. */ int bus_add_driver(struct device_driver *drv) { @@ -688,15 +689,14 @@ out_put_bus: } /** - * bus_remove_driver - delete driver from bus's knowledge. - * @drv: driver. + * bus_remove_driver - delete driver from bus's knowledge. + * @drv: driver. * - * Detach the driver from the devices it controls, and remove - * it from its bus's list of drivers. Finally, we drop the reference - * to the bus we took in bus_add_driver(). + * Detach the driver from the devices it controls, and remove + * it from its bus's list of drivers. Finally, we drop the reference + * to the bus we took in bus_add_driver(). */ - -void bus_remove_driver(struct device_driver * drv) +void bus_remove_driver(struct device_driver *drv) { if (!drv->bus) return; @@ -712,10 +712,9 @@ void bus_remove_driver(struct device_driver * drv) bus_put(drv->bus); } - /* Helper for bus_rescan_devices's iter */ static int __must_check bus_rescan_devices_helper(struct device *dev, - void *data) + void *data) { int ret = 0; @@ -737,10 +736,11 @@ static int __must_check bus_rescan_devices_helper(struct device *dev, * attached and rescan it against existing drivers to see if it matches * any by calling device_attach() for the unbound devices. */ -int bus_rescan_devices(struct bus_type * bus) +int bus_rescan_devices(struct bus_type *bus) { return bus_for_each_dev(bus, NULL, NULL, bus_rescan_devices_helper); } +EXPORT_SYMBOL_GPL(bus_rescan_devices); /** * device_reprobe - remove driver for a device and probe for a new driver @@ -765,55 +765,55 @@ int device_reprobe(struct device *dev) EXPORT_SYMBOL_GPL(device_reprobe); /** - * find_bus - locate bus by name. - * @name: name of bus. + * find_bus - locate bus by name. + * @name: name of bus. * - * Call kset_find_obj() to iterate over list of buses to - * find a bus by name. Return bus if found. + * Call kset_find_obj() to iterate over list of buses to + * find a bus by name. Return bus if found. * - * Note that kset_find_obj increments bus' reference count. + * Note that kset_find_obj increments bus' reference count. */ #if 0 -struct bus_type * find_bus(char * name) +struct bus_type *find_bus(char *name) { - struct kobject * k = kset_find_obj(bus_kset, name); + struct kobject *k = kset_find_obj(bus_kset, name); return k ? to_bus(k) : NULL; } #endif /* 0 */ /** - * bus_add_attrs - Add default attributes for this bus. - * @bus: Bus that has just been registered. + * bus_add_attrs - Add default attributes for this bus. + * @bus: Bus that has just been registered. */ -static int bus_add_attrs(struct bus_type * bus) +static int bus_add_attrs(struct bus_type *bus) { int error = 0; int i; if (bus->bus_attrs) { for (i = 0; attr_name(bus->bus_attrs[i]); i++) { - error = bus_create_file(bus,&bus->bus_attrs[i]); + error = bus_create_file(bus, &bus->bus_attrs[i]); if (error) - goto Err; + goto err; } } - Done: +done: return error; - Err: +err: while (--i >= 0) - bus_remove_file(bus,&bus->bus_attrs[i]); - goto Done; + bus_remove_file(bus, &bus->bus_attrs[i]); + goto done; } -static void bus_remove_attrs(struct bus_type * bus) +static void bus_remove_attrs(struct bus_type *bus) { int i; if (bus->bus_attrs) { for (i = 0; attr_name(bus->bus_attrs[i]); i++) - bus_remove_file(bus,&bus->bus_attrs[i]); + bus_remove_file(bus, &bus->bus_attrs[i]); } } @@ -843,14 +843,14 @@ static ssize_t bus_uevent_store(struct bus_type *bus, static BUS_ATTR(uevent, S_IWUSR, NULL, bus_uevent_store); /** - * bus_register - register a bus with the system. - * @bus: bus. + * bus_register - register a bus with the system. + * @bus: bus. * - * Once we have that, we registered the bus with the kobject - * infrastructure, then register the children subsystems it has: - * the devices and drivers that belong to the bus. + * Once we have that, we registered the bus with the kobject + * infrastructure, then register the children subsystems it has: + * the devices and drivers that belong to the bus. */ -int bus_register(struct bus_type * bus) +int bus_register(struct bus_type *bus) { int retval; struct bus_type_private *priv; @@ -922,15 +922,16 @@ bus_uevent_fail: out: return retval; } +EXPORT_SYMBOL_GPL(bus_register); /** - * bus_unregister - remove a bus from the system - * @bus: bus. + * bus_unregister - remove a bus from the system + * @bus: bus. * - * Unregister the child subsystems and the bus itself. - * Finally, we call bus_put() to release the refcount + * Unregister the child subsystems and the bus itself. + * Finally, we call bus_put() to release the refcount */ -void bus_unregister(struct bus_type * bus) +void bus_unregister(struct bus_type *bus) { pr_debug("bus: '%s': unregistering\n", bus->name); bus_remove_attrs(bus); @@ -941,6 +942,7 @@ void bus_unregister(struct bus_type * bus) kset_unregister(&bus->p->subsys); kfree(bus->p); } +EXPORT_SYMBOL_GPL(bus_unregister); int bus_register_notifier(struct bus_type *bus, struct notifier_block *nb) { @@ -973,15 +975,3 @@ int __init buses_init(void) return -ENOMEM; return 0; } - - -EXPORT_SYMBOL_GPL(bus_for_each_dev); -EXPORT_SYMBOL_GPL(bus_find_device); -EXPORT_SYMBOL_GPL(bus_for_each_drv); - -EXPORT_SYMBOL_GPL(bus_register); -EXPORT_SYMBOL_GPL(bus_unregister); -EXPORT_SYMBOL_GPL(bus_rescan_devices); - -EXPORT_SYMBOL_GPL(bus_create_file); -EXPORT_SYMBOL_GPL(bus_remove_file); diff --git a/drivers/base/class.c b/drivers/base/class.c index 9f737ff..59cf358 100644 --- a/drivers/base/class.c +++ b/drivers/base/class.c @@ -23,11 +23,11 @@ #define to_class_attr(_attr) container_of(_attr, struct class_attribute, attr) #define to_class(obj) container_of(obj, struct class, subsys.kobj) -static ssize_t -class_attr_show(struct kobject * kobj, struct attribute * attr, char * buf) +static ssize_t class_attr_show(struct kobject *kobj, struct attribute *attr, + char *buf) { - struct class_attribute * class_attr = to_class_attr(attr); - struct class * dc = to_class(kobj); + struct class_attribute *class_attr = to_class_attr(attr); + struct class *dc = to_class(kobj); ssize_t ret = -EIO; if (class_attr->show) @@ -35,12 +35,11 @@ class_attr_show(struct kobject * kobj, struct attribute * attr, char * buf) return ret; } -static ssize_t -class_attr_store(struct kobject * kobj, struct attribute * attr, - const char * buf, size_t count) +static ssize_t class_attr_store(struct kobject *kobj, struct attribute *attr, + const char *buf, size_t count) { - struct class_attribute * class_attr = to_class_attr(attr); - struct class * dc = to_class(kobj); + struct class_attribute *class_attr = to_class_attr(attr); + struct class *dc = to_class(kobj); ssize_t ret = -EIO; if (class_attr->store) @@ -48,7 +47,7 @@ class_attr_store(struct kobject * kobj, struct attribute * attr, return ret; } -static void class_release(struct kobject * kobj) +static void class_release(struct kobject *kobj) { struct class *class = to_class(kobj); @@ -75,17 +74,17 @@ static struct kobj_type class_ktype = { static struct kset *class_kset; -int class_create_file(struct class * cls, const struct class_attribute * attr) +int class_create_file(struct class *cls, const struct class_attribute *attr) { int error; - if (cls) { + if (cls) error = sysfs_create_file(&cls->subsys.kobj, &attr->attr); - } else + else error = -EINVAL; return error; } -void class_remove_file(struct class * cls, const struct class_attribute * attr) +void class_remove_file(struct class *cls, const struct class_attribute *attr) { if (cls) sysfs_remove_file(&cls->subsys.kobj, &attr->attr); @@ -94,48 +93,48 @@ void class_remove_file(struct class * cls, const struct class_attribute * attr) static struct class *class_get(struct class *cls) { if (cls) - return container_of(kset_get(&cls->subsys), struct class, subsys); + return container_of(kset_get(&cls->subsys), + struct class, subsys); return NULL; } -static void class_put(struct class * cls) +static void class_put(struct class *cls) { if (cls) kset_put(&cls->subsys); } - -static int add_class_attrs(struct class * cls) +static int add_class_attrs(struct class *cls) { int i; int error = 0; if (cls->class_attrs) { for (i = 0; attr_name(cls->class_attrs[i]); i++) { - error = class_create_file(cls,&cls->class_attrs[i]); + error = class_create_file(cls, &cls->class_attrs[i]); if (error) - goto Err; + goto error; } } - Done: +done: return error; - Err: +error: while (--i >= 0) - class_remove_file(cls,&cls->class_attrs[i]); - goto Done; + class_remove_file(cls, &cls->class_attrs[i]); + goto done; } -static void remove_class_attrs(struct class * cls) +static void remove_class_attrs(struct class *cls) { int i; if (cls->class_attrs) { for (i = 0; attr_name(cls->class_attrs[i]); i++) - class_remove_file(cls,&cls->class_attrs[i]); + class_remove_file(cls, &cls->class_attrs[i]); } } -int class_register(struct class * cls) +int class_register(struct class *cls) { int error; @@ -167,7 +166,7 @@ int class_register(struct class * cls) return error; } -void class_unregister(struct class * cls) +void class_unregister(struct class *cls) { pr_debug("device class '%s': unregistering\n", cls->name); remove_class_attrs(cls); @@ -249,8 +248,8 @@ void class_destroy(struct class *cls) /* Class Device Stuff */ -int class_device_create_file(struct class_device * class_dev, - const struct class_device_attribute * attr) +int class_device_create_file(struct class_device *class_dev, + const struct class_device_attribute *attr) { int error = -EINVAL; if (class_dev) @@ -258,8 +257,8 @@ int class_device_create_file(struct class_device * class_dev, return error; } -void class_device_remove_file(struct class_device * class_dev, - const struct class_device_attribute * attr) +void class_device_remove_file(struct class_device *class_dev, + const struct class_device_attribute *attr) { if (class_dev) sysfs_remove_file(&class_dev->kobj, &attr->attr); @@ -281,12 +280,11 @@ void class_device_remove_bin_file(struct class_device *class_dev, sysfs_remove_bin_file(&class_dev->kobj, attr); } -static ssize_t -class_device_attr_show(struct kobject * kobj, struct attribute * attr, - char * buf) +static ssize_t class_device_attr_show(struct kobject *kobj, + struct attribute *attr, char *buf) { - struct class_device_attribute * class_dev_attr = to_class_dev_attr(attr); - struct class_device * cd = to_class_dev(kobj); + struct class_device_attribute *class_dev_attr = to_class_dev_attr(attr); + struct class_device *cd = to_class_dev(kobj); ssize_t ret = 0; if (class_dev_attr->show) @@ -294,12 +292,12 @@ class_device_attr_show(struct kobject * kobj, struct attribute * attr, return ret; } -static ssize_t -class_device_attr_store(struct kobject * kobj, struct attribute * attr, - const char * buf, size_t count) +static ssize_t class_device_attr_store(struct kobject *kobj, + struct attribute *attr, + const char *buf, size_t count) { - struct class_device_attribute * class_dev_attr = to_class_dev_attr(attr); - struct class_device * cd = to_class_dev(kobj); + struct class_device_attribute *class_dev_attr = to_class_dev_attr(attr); + struct class_device *cd = to_class_dev(kobj); ssize_t ret = 0; if (class_dev_attr->store) @@ -312,10 +310,10 @@ static struct sysfs_ops class_dev_sysfs_ops = { .store = class_device_attr_store, }; -static void class_dev_release(struct kobject * kobj) +static void class_dev_release(struct kobject *kobj) { struct class_device *cd = to_class_dev(kobj); - struct class * cls = cd->class; + struct class *cls = cd->class; pr_debug("device class '%s': release.\n", cd->class_id); @@ -324,8 +322,8 @@ static void class_dev_release(struct kobject * kobj) else if (cls->release) cls->release(cd); else { - printk(KERN_ERR "Class Device '%s' does not have a release() function, " - "it is broken and must be fixed.\n", + printk(KERN_ERR "Class Device '%s' does not have a release() " + "function, it is broken and must be fixed.\n", cd->class_id); WARN_ON(1); } @@ -436,7 +434,8 @@ static int class_uevent(struct kset *kset, struct kobject *kobj, add_uevent_var(env, "PHYSDEVBUS=%s", dev->bus->name); if (dev->driver) - add_uevent_var(env, "PHYSDEVDRIVER=%s", dev->driver->name); + add_uevent_var(env, "PHYSDEVDRIVER=%s", + dev->driver->name); } if (class_dev->uevent) { @@ -469,40 +468,40 @@ static struct kset class_obj_subsys = { .uevent_ops = &class_uevent_ops, }; -static int class_device_add_attrs(struct class_device * cd) +static int class_device_add_attrs(struct class_device *cd) { int i; int error = 0; - struct class * cls = cd->class; + struct class *cls = cd->class; if (cls->class_dev_attrs) { for (i = 0; attr_name(cls->class_dev_attrs[i]); i++) { error = class_device_create_file(cd, - &cls->class_dev_attrs[i]); + &cls->class_dev_attrs[i]); if (error) - goto Err; + goto err; } } - Done: +done: return error; - Err: +err: while (--i >= 0) - class_device_remove_file(cd,&cls->class_dev_attrs[i]); - goto Done; + class_device_remove_file(cd, &cls->class_dev_attrs[i]); + goto done; } -static void class_device_remove_attrs(struct class_device * cd) +static void class_device_remove_attrs(struct class_device *cd) { int i; - struct class * cls = cd->class; + struct class *cls = cd->class; if (cls->class_dev_attrs) { for (i = 0; attr_name(cls->class_dev_attrs[i]); i++) - class_device_remove_file(cd,&cls->class_dev_attrs[i]); + class_device_remove_file(cd, &cls->class_dev_attrs[i]); } } -static int class_device_add_groups(struct class_device * cd) +static int class_device_add_groups(struct class_device *cd) { int i; int error = 0; @@ -512,7 +511,8 @@ static int class_device_add_groups(struct class_device * cd) error = sysfs_create_group(&cd->kobj, cd->groups[i]); if (error) { while (--i >= 0) - sysfs_remove_group(&cd->kobj, cd->groups[i]); + sysfs_remove_group(&cd->kobj, + cd->groups[i]); goto out; } } @@ -521,14 +521,12 @@ out: return error; } -static void class_device_remove_groups(struct class_device * cd) +static void class_device_remove_groups(struct class_device *cd) { int i; - if (cd->groups) { - for (i = 0; cd->groups[i]; i++) { + if (cd->groups) + for (i = 0; cd->groups[i]; i++) sysfs_remove_group(&cd->kobj, cd->groups[i]); - } - } } static ssize_t show_dev(struct class_device *class_dev, char *buf) @@ -653,7 +651,7 @@ int class_device_add(struct class_device *class_dev) out3: kobject_del(&class_dev->kobj); out2: - if(parent_class_dev) + if (parent_class_dev) class_device_put(parent_class_dev); class_put(parent_class); out1: @@ -670,9 +668,11 @@ int class_device_register(struct class_device *class_dev) /** * class_device_create - creates a class device and registers it with sysfs * @cls: pointer to the struct class that this device should be registered to. - * @parent: pointer to the parent struct class_device of this new device, if any. + * @parent: pointer to the parent struct class_device of this new device, if + * any. * @devt: the dev_t for the char device to be added. - * @device: a pointer to a struct device that is assiociated with this class device. + * @device: a pointer to a struct device that is assiociated with this class + * device. * @fmt: string for the class device's name * * This function can be used by char device classes. A struct @@ -796,7 +796,7 @@ void class_device_destroy(struct class *cls, dev_t devt) class_device_unregister(class_dev); } -struct class_device * class_device_get(struct class_device *class_dev) +struct class_device *class_device_get(struct class_device *class_dev) { if (class_dev) return to_class_dev(kobject_get(&class_dev->kobj)); @@ -973,7 +973,7 @@ int class_interface_register(struct class_interface *class_intf) void class_interface_unregister(struct class_interface *class_intf) { - struct class * parent = class_intf->class; + struct class *parent = class_intf->class; struct class_device *class_dev; struct device *dev; diff --git a/drivers/base/core.c b/drivers/base/core.c index f09dde3..edf3bbe 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c @@ -24,8 +24,8 @@ #include "base.h" #include "power/power.h" -int (*platform_notify)(struct device * dev) = NULL; -int (*platform_notify_remove)(struct device * dev) = NULL; +int (*platform_notify)(struct device *dev) = NULL; +int (*platform_notify_remove)(struct device *dev) = NULL; /* * sysfs bindings for devices. @@ -51,11 +51,11 @@ EXPORT_SYMBOL(dev_driver_string); #define to_dev(obj) container_of(obj, struct device, kobj) #define to_dev_attr(_attr) container_of(_attr, struct device_attribute, attr) -static ssize_t -dev_attr_show(struct kobject * kobj, struct attribute * attr, char * buf) +static ssize_t dev_attr_show(struct kobject *kobj, struct attribute *attr, + char *buf) { - struct device_attribute * dev_attr = to_dev_attr(attr); - struct device * dev = to_dev(kobj); + struct device_attribute *dev_attr = to_dev_attr(attr); + struct device *dev = to_dev(kobj); ssize_t ret = -EIO; if (dev_attr->show) @@ -63,12 +63,11 @@ dev_attr_show(struct kobject * kobj, struct attribute * attr, char * buf) return ret; } -static ssize_t -dev_attr_store(struct kobject * kobj, struct attribute * attr, - const char * buf, size_t count) +static ssize_t dev_attr_store(struct kobject *kobj, struct attribute *attr, + const char *buf, size_t count) { - struct device_attribute * dev_attr = to_dev_attr(attr); - struct device * dev = to_dev(kobj); + struct device_attribute *dev_attr = to_dev_attr(attr); + struct device *dev = to_dev(kobj); ssize_t ret = -EIO; if (dev_attr->store) @@ -90,9 +89,9 @@ static struct sysfs_ops dev_sysfs_ops = { * reaches 0. We forward the call to the device's release * method, which should handle actually freeing the structure. */ -static void device_release(struct kobject * kobj) +static void device_release(struct kobject *kobj) { - struct device * dev = to_dev(kobj); + struct device *dev = to_dev(kobj); if (dev->release) dev->release(dev); @@ -101,8 +100,8 @@ static void device_release(struct kobject * kobj) else if (dev->class && dev->class->dev_release) dev->class->dev_release(dev); else { - printk(KERN_ERR "Device '%s' does not have a release() function, " - "it is broken and must be fixed.\n", + printk(KERN_ERR "Device '%s' does not have a release() " + "function, it is broken and must be fixed.\n", dev->bus_id); WARN_ON(1); } @@ -185,7 +184,8 @@ static int dev_uevent(struct kset *kset, struct kobject *kobj, add_uevent_var(env, "PHYSDEVBUS=%s", dev->bus->name); if (dev->driver) - add_uevent_var(env, "PHYSDEVDRIVER=%s", dev->driver->name); + add_uevent_var(env, "PHYSDEVDRIVER=%s", + dev->driver->name); } #endif @@ -327,7 +327,8 @@ static int device_add_groups(struct device *dev, error = sysfs_create_group(&dev->kobj, groups[i]); if (error) { while (--i >= 0) - sysfs_remove_group(&dev->kobj, groups[i]); + sysfs_remove_group(&dev->kobj, + groups[i]); break; } } @@ -406,14 +407,12 @@ static struct device_attribute devt_attr = /* kset to create /sys/devices/ */ struct kset *devices_kset; - /** - * device_create_file - create sysfs attribute file for device. - * @dev: device. - * @attr: device attribute descriptor. + * device_create_file - create sysfs attribute file for device. + * @dev: device. + * @attr: device attribute descriptor. */ - -int device_create_file(struct device * dev, struct device_attribute * attr) +int device_create_file(struct device *dev, struct device_attribute *attr) { int error = 0; if (get_device(dev)) { @@ -424,12 +423,11 @@ int device_create_file(struct device * dev, struct device_attribute * attr) } /** - * device_remove_file - remove sysfs attribute file. - * @dev: device. - * @attr: device attribute descriptor. + * device_remove_file - remove sysfs attribute file. + * @dev: device. + * @attr: device attribute descriptor. */ - -void device_remove_file(struct device * dev, struct device_attribute * attr) +void device_remove_file(struct device *dev, struct device_attribute *attr) { if (get_device(dev)) { sysfs_remove_file(&dev->kobj, &attr->attr); @@ -510,18 +508,16 @@ static void klist_children_put(struct klist_node *n) put_device(dev); } - /** - * device_initialize - init device structure. - * @dev: device. + * device_initialize - init device structure. + * @dev: device. * - * This prepares the device for use by other layers, - * including adding it to the device hierarchy. - * It is the first half of device_register(), if called by - * that, though it can also be called separately, so one - * may use @dev's fields (e.g. the refcount). + * This prepares the device for use by other layers, + * including adding it to the device hierarchy. + * It is the first half of device_register(), if called by + * that, though it can also be called separately, so one + * may use @dev's fields (e.g. the refcount). */ - void device_initialize(struct device *dev) { dev->kobj.kset = devices_kset; @@ -754,15 +750,15 @@ static void device_remove_class_symlinks(struct device *dev) } /** - * device_add - add device to device hierarchy. - * @dev: device. + * device_add - add device to device hierarchy. + * @dev: device. * - * This is part 2 of device_register(), though may be called - * separately _iff_ device_initialize() has been called separately. + * This is part 2 of device_register(), though may be called + * separately _iff_ device_initialize() has been called separately. * - * This adds it to the kobject hierarchy via kobject_add(), adds it - * to the global and sibling lists for the device, then - * adds it to the other relevant subsystems of the driver model. + * This adds it to the kobject hierarchy via kobject_add(), adds it + * to the global and sibling lists for the device, then + * adds it to the other relevant subsystems of the driver model. */ int device_add(struct device *dev) { @@ -870,70 +866,63 @@ int device_add(struct device *dev) goto Done; } - /** - * device_register - register a device with the system. - * @dev: pointer to the device structure + * device_register - register a device with the system. + * @dev: pointer to the device structure * - * This happens in two clean steps - initialize the device - * and add it to the system. The two steps can be called - * separately, but this is the easiest and most common. - * I.e. you should only call the two helpers separately if - * have a clearly defined need to use and refcount the device - * before it is added to the hierarchy. + * This happens in two clean steps - initialize the device + * and add it to the system. The two steps can be called + * separately, but this is the easiest and most common. + * I.e. you should only call the two helpers separately if + * have a clearly defined need to use and refcount the device + * before it is added to the hierarchy. */ - int device_register(struct device *dev) { device_initialize(dev); return device_add(dev); } - /** - * get_device - increment reference count for device. - * @dev: device. + * get_device - increment reference count for device. + * @dev: device. * - * This simply forwards the call to kobject_get(), though - * we do take care to provide for the case that we get a NULL - * pointer passed in. + * This simply forwards the call to kobject_get(), though + * we do take care to provide for the case that we get a NULL + * pointer passed in. */ - -struct device * get_device(struct device * dev) +struct device *get_device(struct device *dev) { return dev ? to_dev(kobject_get(&dev->kobj)) : NULL; } - /** - * put_device - decrement reference count. - * @dev: device in question. + * put_device - decrement reference count. + * @dev: device in question. */ -void put_device(struct device * dev) +void put_device(struct device *dev) { /* might_sleep(); */ if (dev) kobject_put(&dev->kobj); } - /** - * device_del - delete device from system. - * @dev: device. + * device_del - delete device from system. + * @dev: device. * - * This is the first part of the device unregistration - * sequence. This removes the device from the lists we control - * from here, has it removed from the other driver model - * subsystems it was added to in device_add(), and removes it - * from the kobject hierarchy. + * This is the first part of the device unregistration + * sequence. This removes the device from the lists we control + * from here, has it removed from the other driver model + * subsystems it was added to in device_add(), and removes it + * from the kobject hierarchy. * - * NOTE: this should be called manually _iff_ device_add() was - * also called manually. + * NOTE: this should be called manually _iff_ device_add() was + * also called manually. */ - -void device_del(struct device * dev) +void device_del(struct device *dev) { - struct device * parent = dev->parent; + struct device *parent = dev->parent; struct class_interface *class_intf; device_pm_remove(dev); @@ -979,47 +968,46 @@ void device_del(struct device * dev) } /** - * device_unregister - unregister device from system. - * @dev: device going away. + * device_unregister - unregister device from system. + * @dev: device going away. * - * We do this in two parts, like we do device_register(). First, - * we remove it from all the subsystems with device_del(), then - * we decrement the reference count via put_device(). If that - * is the final reference count, the device will be cleaned up - * via device_release() above. Otherwise, the structure will - * stick around until the final reference to the device is dropped. + * We do this in two parts, like we do device_register(). First, + * we remove it from all the subsystems with device_del(), then + * we decrement the reference count via put_device(). If that + * is the final reference count, the device will be cleaned up + * via device_release() above. Otherwise, the structure will + * stick around until the final reference to the device is dropped. */ -void device_unregister(struct device * dev) +void device_unregister(struct device *dev) { pr_debug("device: '%s': %s\n", dev->bus_id, __FUNCTION__); device_del(dev); put_device(dev); } - -static struct device * next_device(struct klist_iter * i) +static struct device *next_device(struct klist_iter *i) { - struct klist_node * n = klist_next(i); + struct klist_node *n = klist_next(i); return n ? container_of(n, struct device, knode_parent) : NULL; } /** - * device_for_each_child - device child iterator. - * @parent: parent struct device. - * @data: data for the callback. - * @fn: function to be called for each device. + * device_for_each_child - device child iterator. + * @parent: parent struct device. + * @data: data for the callback. + * @fn: function to be called for each device. * - * Iterate over @parent's child devices, and call @fn for each, - * passing it @data. + * Iterate over @parent's child devices, and call @fn for each, + * passing it @data. * - * We check the return of @fn each time. If it returns anything - * other than 0, we break out and return that value. + * We check the return of @fn each time. If it returns anything + * other than 0, we break out and return that value. */ -int device_for_each_child(struct device * parent, void * data, - int (*fn)(struct device *, void *)) +int device_for_each_child(struct device *parent, void *data, + int (*fn)(struct device *dev, void *data)) { struct klist_iter i; - struct device * child; + struct device *child; int error = 0; klist_iter_init(&parent->klist_children, &i); @@ -1044,8 +1032,8 @@ int device_for_each_child(struct device * parent, void * data, * current device can be obtained, this function will return to the caller * and not iterate over any more devices. */ -struct device * device_find_child(struct device *parent, void *data, - int (*match)(struct device *, void *)) +struct device *device_find_child(struct device *parent, void *data, + int (*match)(struct device *dev, void *data)) { struct klist_iter i; struct device *child; @@ -1312,8 +1300,7 @@ static int device_move_class_links(struct device *dev, class_name); if (error) sysfs_remove_link(&dev->kobj, "device"); - } - else + } else error = 0; out: kfree(class_name); @@ -1344,7 +1331,7 @@ int device_move(struct device *dev, struct device *new_parent) return -EINVAL; new_parent = get_device(new_parent); - new_parent_kobj = get_device_parent (dev, new_parent); + new_parent_kobj = get_device_parent(dev, new_parent); pr_debug("device: '%s': %s: moving to '%s'\n", dev->bus_id, __FUNCTION__, new_parent ? new_parent->bus_id : ""); @@ -1390,7 +1377,7 @@ EXPORT_SYMBOL_GPL(device_move); */ void device_shutdown(void) { - struct device * dev, *devn; + struct device *dev, *devn; list_for_each_entry_safe_reverse(dev, devn, &devices_kset->list, kobj.entry) { diff --git a/drivers/base/dd.c b/drivers/base/dd.c index b0726eb..a5cde94 100644 --- a/drivers/base/dd.c +++ b/drivers/base/dd.c @@ -1,20 +1,20 @@ /* - * drivers/base/dd.c - The core device/driver interactions. + * drivers/base/dd.c - The core device/driver interactions. * - * This file contains the (sometimes tricky) code that controls the - * interactions between devices and drivers, which primarily includes - * driver binding and unbinding. + * This file contains the (sometimes tricky) code that controls the + * interactions between devices and drivers, which primarily includes + * driver binding and unbinding. * - * All of this code used to exist in drivers/base/bus.c, but was - * relocated to here in the name of compartmentalization (since it wasn't - * strictly code just for the 'struct bus_type'. + * All of this code used to exist in drivers/base/bus.c, but was + * relocated to here in the name of compartmentalization (since it wasn't + * strictly code just for the 'struct bus_type'. * - * Copyright (c) 2002-5 Patrick Mochel - * Copyright (c) 2002-3 Open Source Development Labs - * Copyright (c) 2007 Greg Kroah-Hartman - * Copyright (c) 2007 Novell Inc. + * Copyright (c) 2002-5 Patrick Mochel + * Copyright (c) 2002-3 Open Source Development Labs + * Copyright (c) 2007 Greg Kroah-Hartman + * Copyright (c) 2007 Novell Inc. * - * This file is released under the GPLv2 + * This file is released under the GPLv2 */ #include @@ -71,18 +71,18 @@ static void driver_sysfs_remove(struct device *dev) } /** - * device_bind_driver - bind a driver to one device. - * @dev: device. + * device_bind_driver - bind a driver to one device. + * @dev: device. * - * Allow manual attachment of a driver to a device. - * Caller must have already set @dev->driver. + * Allow manual attachment of a driver to a device. + * Caller must have already set @dev->driver. * - * Note that this does not modify the bus reference count - * nor take the bus's rwsem. Please verify those are accounted - * for before calling this. (It is ok to call with no other effort - * from a driver's probe() method.) + * Note that this does not modify the bus reference count + * nor take the bus's rwsem. Please verify those are accounted + * for before calling this. (It is ok to call with no other effort + * from a driver's probe() method.) * - * This function must be called with @dev->sem held. + * This function must be called with @dev->sem held. */ int device_bind_driver(struct device *dev) { @@ -93,6 +93,7 @@ int device_bind_driver(struct device *dev) driver_bound(dev); return ret; } +EXPORT_SYMBOL_GPL(device_bind_driver); static atomic_t probe_count = ATOMIC_INIT(0); static DECLARE_WAIT_QUEUE_HEAD(probe_waitqueue); @@ -183,7 +184,7 @@ int driver_probe_done(void) * This function must be called with @dev->sem held. When called for a * USB interface, @dev->parent->sem must be held as well. */ -int driver_probe_device(struct device_driver * drv, struct device * dev) +int driver_probe_device(struct device_driver *drv, struct device *dev) { int ret = 0; @@ -201,27 +202,27 @@ done: return ret; } -static int __device_attach(struct device_driver * drv, void * data) +static int __device_attach(struct device_driver *drv, void *data) { - struct device * dev = data; + struct device *dev = data; return driver_probe_device(drv, dev); } /** - * device_attach - try to attach device to a driver. - * @dev: device. + * device_attach - try to attach device to a driver. + * @dev: device. * - * Walk the list of drivers that the bus has and call - * driver_probe_device() for each pair. If a compatible - * pair is found, break out and return. + * Walk the list of drivers that the bus has and call + * driver_probe_device() for each pair. If a compatible + * pair is found, break out and return. * - * Returns 1 if the device was bound to a driver; - * 0 if no matching device was found; - * -ENODEV if the device is not registered. + * Returns 1 if the device was bound to a driver; + * 0 if no matching device was found; + * -ENODEV if the device is not registered. * - * When called for a USB interface, @dev->parent->sem must be held. + * When called for a USB interface, @dev->parent->sem must be held. */ -int device_attach(struct device * dev) +int device_attach(struct device *dev) { int ret = 0; @@ -240,10 +241,11 @@ int device_attach(struct device * dev) up(&dev->sem); return ret; } +EXPORT_SYMBOL_GPL(device_attach); -static int __driver_attach(struct device * dev, void * data) +static int __driver_attach(struct device *dev, void *data) { - struct device_driver * drv = data; + struct device_driver *drv = data; /* * Lock device and try to bind to it. We drop the error @@ -268,26 +270,27 @@ static int __driver_attach(struct device * dev, void * data) } /** - * driver_attach - try to bind driver to devices. - * @drv: driver. + * driver_attach - try to bind driver to devices. + * @drv: driver. * - * Walk the list of devices that the bus has on it and try to - * match the driver with each one. If driver_probe_device() - * returns 0 and the @dev->driver is set, we've found a - * compatible pair. + * Walk the list of devices that the bus has on it and try to + * match the driver with each one. If driver_probe_device() + * returns 0 and the @dev->driver is set, we've found a + * compatible pair. */ -int driver_attach(struct device_driver * drv) +int driver_attach(struct device_driver *drv) { return bus_for_each_dev(drv->bus, NULL, drv, __driver_attach); } +EXPORT_SYMBOL_GPL(driver_attach); /* - * __device_release_driver() must be called with @dev->sem held. - * When called for a USB interface, @dev->parent->sem must be held as well. + * __device_release_driver() must be called with @dev->sem held. + * When called for a USB interface, @dev->parent->sem must be held as well. */ -static void __device_release_driver(struct device * dev) +static void __device_release_driver(struct device *dev) { - struct device_driver * drv; + struct device_driver *drv; drv = dev->driver; if (drv) { @@ -310,13 +313,13 @@ static void __device_release_driver(struct device * dev) } /** - * device_release_driver - manually detach device from driver. - * @dev: device. + * device_release_driver - manually detach device from driver. + * @dev: device. * - * Manually detach device from driver. - * When called for a USB interface, @dev->parent->sem must be held. + * Manually detach device from driver. + * When called for a USB interface, @dev->parent->sem must be held. */ -void device_release_driver(struct device * dev) +void device_release_driver(struct device *dev) { /* * If anyone calls device_release_driver() recursively from @@ -327,15 +330,15 @@ void device_release_driver(struct device * dev) __device_release_driver(dev); up(&dev->sem); } - +EXPORT_SYMBOL_GPL(device_release_driver); /** * driver_detach - detach driver from all devices it controls. * @drv: driver. */ -void driver_detach(struct device_driver * drv) +void driver_detach(struct device_driver *drv) { - struct device * dev; + struct device *dev; for (;;) { spin_lock(&drv->p->klist_devices.k_lock); @@ -359,9 +362,3 @@ void driver_detach(struct device_driver * drv) put_device(dev); } } - -EXPORT_SYMBOL_GPL(device_bind_driver); -EXPORT_SYMBOL_GPL(device_release_driver); -EXPORT_SYMBOL_GPL(device_attach); -EXPORT_SYMBOL_GPL(driver_attach); - diff --git a/drivers/base/driver.c b/drivers/base/driver.c index 94b697a..a35f041 100644 --- a/drivers/base/driver.c +++ b/drivers/base/driver.c @@ -19,27 +19,26 @@ #define to_dev(node) container_of(node, struct device, driver_list) -static struct device * next_device(struct klist_iter * i) +static struct device *next_device(struct klist_iter *i) { - struct klist_node * n = klist_next(i); + struct klist_node *n = klist_next(i); return n ? container_of(n, struct device, knode_driver) : NULL; } /** - * driver_for_each_device - Iterator for devices bound to a driver. - * @drv: Driver we're iterating. - * @start: Device to begin with - * @data: Data to pass to the callback. - * @fn: Function to call for each device. + * driver_for_each_device - Iterator for devices bound to a driver. + * @drv: Driver we're iterating. + * @start: Device to begin with + * @data: Data to pass to the callback. + * @fn: Function to call for each device. * - * Iterate over the @drv's list of devices calling @fn for each one. + * Iterate over the @drv's list of devices calling @fn for each one. */ - -int driver_for_each_device(struct device_driver * drv, struct device * start, - void * data, int (*fn)(struct device *, void *)) +int driver_for_each_device(struct device_driver *drv, struct device *start, + void *data, int (*fn)(struct device *, void *)) { struct klist_iter i; - struct device * dev; + struct device *dev; int error = 0; if (!drv) @@ -52,10 +51,8 @@ int driver_for_each_device(struct device_driver * drv, struct device * start, klist_iter_exit(&i); return error; } - EXPORT_SYMBOL_GPL(driver_for_each_device); - /** * driver_find_device - device iterator for locating a particular device. * @drv: The device's driver @@ -71,9 +68,9 @@ EXPORT_SYMBOL_GPL(driver_for_each_device); * if it does. If the callback returns non-zero, this function will * return to the caller and not iterate over any more devices. */ -struct device * driver_find_device(struct device_driver *drv, - struct device * start, void * data, - int (*match)(struct device *, void *)) +struct device *driver_find_device(struct device_driver *drv, + struct device *start, void *data, + int (*match)(struct device *dev, void *data)) { struct klist_iter i; struct device *dev; @@ -92,12 +89,12 @@ struct device * driver_find_device(struct device_driver *drv, EXPORT_SYMBOL_GPL(driver_find_device); /** - * driver_create_file - create sysfs file for driver. - * @drv: driver. - * @attr: driver attribute descriptor. + * driver_create_file - create sysfs file for driver. + * @drv: driver. + * @attr: driver attribute descriptor. */ - -int driver_create_file(struct device_driver * drv, struct driver_attribute * attr) +int driver_create_file(struct device_driver *drv, + struct driver_attribute *attr) { int error; if (get_driver(drv)) { @@ -107,22 +104,22 @@ int driver_create_file(struct device_driver * drv, struct driver_attribute * att error = -EINVAL; return error; } - +EXPORT_SYMBOL_GPL(driver_create_file); /** - * driver_remove_file - remove sysfs file for driver. - * @drv: driver. - * @attr: driver attribute descriptor. + * driver_remove_file - remove sysfs file for driver. + * @drv: driver. + * @attr: driver attribute descriptor. */ - -void driver_remove_file(struct device_driver * drv, struct driver_attribute * attr) +void driver_remove_file(struct device_driver *drv, + struct driver_attribute *attr) { if (get_driver(drv)) { sysfs_remove_file(&drv->p->kobj, &attr->attr); put_driver(drv); } } - +EXPORT_SYMBOL_GPL(driver_remove_file); /** * driver_add_kobj - add a kobject below the specified driver @@ -149,10 +146,10 @@ int driver_add_kobj(struct device_driver *drv, struct kobject *kobj, EXPORT_SYMBOL_GPL(driver_add_kobj); /** - * get_driver - increment driver reference count. - * @drv: driver. + * get_driver - increment driver reference count. + * @drv: driver. */ -struct device_driver * get_driver(struct device_driver * drv) +struct device_driver *get_driver(struct device_driver *drv) { if (drv) { struct driver_private *priv; @@ -164,16 +161,17 @@ struct device_driver * get_driver(struct device_driver * drv) } return NULL; } - +EXPORT_SYMBOL_GPL(get_driver); /** - * put_driver - decrement driver's refcount. - * @drv: driver. + * put_driver - decrement driver's refcount. + * @drv: driver. */ -void put_driver(struct device_driver * drv) +void put_driver(struct device_driver *drv) { kobject_put(&drv->p->kobj); } +EXPORT_SYMBOL_GPL(put_driver); static int driver_add_groups(struct device_driver *drv, struct attribute_group **groups) @@ -205,24 +203,23 @@ static void driver_remove_groups(struct device_driver *drv, sysfs_remove_group(&drv->p->kobj, groups[i]); } - /** - * driver_register - register driver with bus - * @drv: driver to register + * driver_register - register driver with bus + * @drv: driver to register * - * We pass off most of the work to the bus_add_driver() call, - * since most of the things we have to do deal with the bus - * structures. + * We pass off most of the work to the bus_add_driver() call, + * since most of the things we have to do deal with the bus + * structures. */ -int driver_register(struct device_driver * drv) +int driver_register(struct device_driver *drv) { int ret; if ((drv->bus->probe && drv->probe) || (drv->bus->remove && drv->remove) || - (drv->bus->shutdown && drv->shutdown)) { - printk(KERN_WARNING "Driver '%s' needs updating - please use bus_type methods\n", drv->name); - } + (drv->bus->shutdown && drv->shutdown)) + printk(KERN_WARNING "Driver '%s' needs updating - please use " + "bus_type methods\n", drv->name); ret = bus_add_driver(drv); if (ret) return ret; @@ -231,29 +228,30 @@ int driver_register(struct device_driver * drv) bus_remove_driver(drv); return ret; } +EXPORT_SYMBOL_GPL(driver_register); /** - * driver_unregister - remove driver from system. - * @drv: driver. + * driver_unregister - remove driver from system. + * @drv: driver. * - * Again, we pass off most of the work to the bus-level call. + * Again, we pass off most of the work to the bus-level call. */ - -void driver_unregister(struct device_driver * drv) +void driver_unregister(struct device_driver *drv) { driver_remove_groups(drv, drv->groups); bus_remove_driver(drv); } +EXPORT_SYMBOL_GPL(driver_unregister); /** - * driver_find - locate driver on a bus by its name. - * @name: name of the driver. - * @bus: bus to scan for the driver. + * driver_find - locate driver on a bus by its name. + * @name: name of the driver. + * @bus: bus to scan for the driver. * - * Call kset_find_obj() to iterate over list of drivers on - * a bus to find driver by name. Return driver if found. + * Call kset_find_obj() to iterate over list of drivers on + * a bus to find driver by name. Return driver if found. * - * Note that kset_find_obj increments driver's reference count. + * Note that kset_find_obj increments driver's reference count. */ struct device_driver *driver_find(const char *name, struct bus_type *bus) { @@ -266,12 +264,4 @@ struct device_driver *driver_find(const char *name, struct bus_type *bus) } return NULL; } - -EXPORT_SYMBOL_GPL(driver_register); -EXPORT_SYMBOL_GPL(driver_unregister); -EXPORT_SYMBOL_GPL(get_driver); -EXPORT_SYMBOL_GPL(put_driver); EXPORT_SYMBOL_GPL(driver_find); - -EXPORT_SYMBOL_GPL(driver_create_file); -EXPORT_SYMBOL_GPL(driver_remove_file); diff --git a/drivers/base/init.c b/drivers/base/init.c index 1da88a1..7bd9b6a 100644 --- a/drivers/base/init.c +++ b/drivers/base/init.c @@ -1,10 +1,8 @@ /* - * * Copyright (c) 2002-3 Patrick Mochel * Copyright (c) 2002-3 Open Source Development Labs * * This file is released under the GPLv2 - * */ #include @@ -14,12 +12,11 @@ #include "base.h" /** - * driver_init - initialize driver model. + * driver_init - initialize driver model. * - * Call the driver model init functions to initialize their - * subsystems. Called early from init/main.c. + * Call the driver model init functions to initialize their + * subsystems. Called early from init/main.c. */ - void __init driver_init(void) { /* These are the core pieces */ diff --git a/drivers/base/platform.c b/drivers/base/platform.c index 48d5db4..efaf282 100644 --- a/drivers/base/platform.c +++ b/drivers/base/platform.c @@ -20,7 +20,8 @@ #include "base.h" -#define to_platform_driver(drv) (container_of((drv), struct platform_driver, driver)) +#define to_platform_driver(drv) (container_of((drv), struct platform_driver, \ + driver)) struct device platform_bus = { .bus_id = "platform", @@ -28,14 +29,13 @@ struct device platform_bus = { EXPORT_SYMBOL_GPL(platform_bus); /** - * platform_get_resource - get a resource for a device - * @dev: platform device - * @type: resource type - * @num: resource index + * platform_get_resource - get a resource for a device + * @dev: platform device + * @type: resource type + * @num: resource index */ -struct resource * -platform_get_resource(struct platform_device *dev, unsigned int type, - unsigned int num) +struct resource *platform_get_resource(struct platform_device *dev, + unsigned int type, unsigned int num) { int i; @@ -43,8 +43,7 @@ platform_get_resource(struct platform_device *dev, unsigned int type, struct resource *r = &dev->resource[i]; if ((r->flags & (IORESOURCE_IO|IORESOURCE_MEM| - IORESOURCE_IRQ|IORESOURCE_DMA)) - == type) + IORESOURCE_IRQ|IORESOURCE_DMA)) == type) if (num-- == 0) return r; } @@ -53,9 +52,9 @@ platform_get_resource(struct platform_device *dev, unsigned int type, EXPORT_SYMBOL_GPL(platform_get_resource); /** - * platform_get_irq - get an IRQ for a device - * @dev: platform device - * @num: IRQ number index + * platform_get_irq - get an IRQ for a device + * @dev: platform device + * @num: IRQ number index */ int platform_get_irq(struct platform_device *dev, unsigned int num) { @@ -66,14 +65,13 @@ int platform_get_irq(struct platform_device *dev, unsigned int num) EXPORT_SYMBOL_GPL(platform_get_irq); /** - * platform_get_resource_byname - get a resource for a device by name - * @dev: platform device - * @type: resource type - * @name: resource name + * platform_get_resource_byname - get a resource for a device by name + * @dev: platform device + * @type: resource type + * @name: resource name */ -struct resource * -platform_get_resource_byname(struct platform_device *dev, unsigned int type, - char *name) +struct resource *platform_get_resource_byname(struct platform_device *dev, + unsigned int type, char *name) { int i; @@ -90,22 +88,23 @@ platform_get_resource_byname(struct platform_device *dev, unsigned int type, EXPORT_SYMBOL_GPL(platform_get_resource_byname); /** - * platform_get_irq - get an IRQ for a device - * @dev: platform device - * @name: IRQ name + * platform_get_irq - get an IRQ for a device + * @dev: platform device + * @name: IRQ name */ int platform_get_irq_byname(struct platform_device *dev, char *name) { - struct resource *r = platform_get_resource_byname(dev, IORESOURCE_IRQ, name); + struct resource *r = platform_get_resource_byname(dev, IORESOURCE_IRQ, + name); return r ? r->start : -ENXIO; } EXPORT_SYMBOL_GPL(platform_get_irq_byname); /** - * platform_add_devices - add a numbers of platform devices - * @devs: array of platform devices to add - * @num: number of platform devices in array + * platform_add_devices - add a numbers of platform devices + * @devs: array of platform devices to add + * @num: number of platform devices in array */ int platform_add_devices(struct platform_device **devs, int num) { @@ -130,12 +129,11 @@ struct platform_object { }; /** - * platform_device_put - * @pdev: platform device to free + * platform_device_put + * @pdev: platform device to free * - * Free all memory associated with a platform device. This function - * must _only_ be externally called in error cases. All other usage - * is a bug. + * Free all memory associated with a platform device. This function must + * _only_ be externally called in error cases. All other usage is a bug. */ void platform_device_put(struct platform_device *pdev) { @@ -146,7 +144,8 @@ EXPORT_SYMBOL_GPL(platform_device_put); static void platform_device_release(struct device *dev) { - struct platform_object *pa = container_of(dev, struct platform_object, pdev.dev); + struct platform_object *pa = container_of(dev, struct platform_object, + pdev.dev); kfree(pa->pdev.dev.platform_data); kfree(pa->pdev.resource); @@ -154,12 +153,12 @@ static void platform_device_release(struct device *dev) } /** - * platform_device_alloc - * @name: base name of the device we're adding - * @id: instance id + * platform_device_alloc + * @name: base name of the device we're adding + * @id: instance id * - * Create a platform device object which can have other objects attached - * to it, and which will have attached objects freed when it is released. + * Create a platform device object which can have other objects attached + * to it, and which will have attached objects freed when it is released. */ struct platform_device *platform_device_alloc(const char *name, int id) { @@ -179,16 +178,17 @@ struct platform_device *platform_device_alloc(const char *name, int id) EXPORT_SYMBOL_GPL(platform_device_alloc); /** - * platform_device_add_resources - * @pdev: platform device allocated by platform_device_alloc to add resources to - * @res: set of resources that needs to be allocated for the device - * @num: number of resources + * platform_device_add_resources + * @pdev: platform device allocated by platform_device_alloc to add resources to + * @res: set of resources that needs to be allocated for the device + * @num: number of resources * - * Add a copy of the resources to the platform device. The memory - * associated with the resources will be freed when the platform - * device is released. + * Add a copy of the resources to the platform device. The memory + * associated with the resources will be freed when the platform device is + * released. */ -int platform_device_add_resources(struct platform_device *pdev, struct resource *res, unsigned int num) +int platform_device_add_resources(struct platform_device *pdev, + struct resource *res, unsigned int num) { struct resource *r; @@ -203,16 +203,17 @@ int platform_device_add_resources(struct platform_device *pdev, struct resource EXPORT_SYMBOL_GPL(platform_device_add_resources); /** - * platform_device_add_data - * @pdev: platform device allocated by platform_device_alloc to add resources to - * @data: platform specific data for this platform device - * @size: size of platform specific data + * platform_device_add_data + * @pdev: platform device allocated by platform_device_alloc to add resources to + * @data: platform specific data for this platform device + * @size: size of platform specific data * - * Add a copy of platform specific data to the platform device's platform_data - * pointer. The memory associated with the platform data will be freed - * when the platform device is released. + * Add a copy of platform specific data to the platform device's + * platform_data pointer. The memory associated with the platform data + * will be freed when the platform device is released. */ -int platform_device_add_data(struct platform_device *pdev, const void *data, size_t size) +int platform_device_add_data(struct platform_device *pdev, const void *data, + size_t size) { void *d; @@ -226,11 +227,11 @@ int platform_device_add_data(struct platform_device *pdev, const void *data, siz EXPORT_SYMBOL_GPL(platform_device_add_data); /** - * platform_device_add - add a platform device to device hierarchy - * @pdev: platform device we're adding + * platform_device_add - add a platform device to device hierarchy + * @pdev: platform device we're adding * - * This is part 2 of platform_device_register(), though may be called - * separately _iff_ pdev was allocated by platform_device_alloc(). + * This is part 2 of platform_device_register(), though may be called + * separately _iff_ pdev was allocated by platform_device_alloc(). */ int platform_device_add(struct platform_device *pdev) { @@ -289,13 +290,12 @@ int platform_device_add(struct platform_device *pdev) EXPORT_SYMBOL_GPL(platform_device_add); /** - * platform_device_del - remove a platform-level device - * @pdev: platform device we're removing + * platform_device_del - remove a platform-level device + * @pdev: platform device we're removing * - * Note that this function will also release all memory- and port-based - * resources owned by the device (@dev->resource). This function - * must _only_ be externally called in error cases. All other usage - * is a bug. + * Note that this function will also release all memory- and port-based + * resources owned by the device (@dev->resource). This function must + * _only_ be externally called in error cases. All other usage is a bug. */ void platform_device_del(struct platform_device *pdev) { @@ -314,11 +314,10 @@ void platform_device_del(struct platform_device *pdev) EXPORT_SYMBOL_GPL(platform_device_del); /** - * platform_device_register - add a platform-level device - * @pdev: platform device we're adding - * + * platform_device_register - add a platform-level device + * @pdev: platform device we're adding */ -int platform_device_register(struct platform_device * pdev) +int platform_device_register(struct platform_device *pdev) { device_initialize(&pdev->dev); return platform_device_add(pdev); @@ -326,14 +325,14 @@ int platform_device_register(struct platform_device * pdev) EXPORT_SYMBOL_GPL(platform_device_register); /** - * platform_device_unregister - unregister a platform-level device - * @pdev: platform device we're unregistering + * platform_device_unregister - unregister a platform-level device + * @pdev: platform device we're unregistering * - * Unregistration is done in 2 steps. First we release all resources - * and remove it from the subsystem, then we drop reference count by - * calling platform_device_put(). + * Unregistration is done in 2 steps. First we release all resources + * and remove it from the subsystem, then we drop reference count by + * calling platform_device_put(). */ -void platform_device_unregister(struct platform_device * pdev) +void platform_device_unregister(struct platform_device *pdev) { platform_device_del(pdev); platform_device_put(pdev); @@ -341,27 +340,29 @@ void platform_device_unregister(struct platform_device * pdev) EXPORT_SYMBOL_GPL(platform_device_unregister); /** - * platform_device_register_simple - * @name: base name of the device we're adding - * @id: instance id - * @res: set of resources that needs to be allocated for the device - * @num: number of resources + * platform_device_register_simple + * @name: base name of the device we're adding + * @id: instance id + * @res: set of resources that needs to be allocated for the device + * @num: number of resources * - * This function creates a simple platform device that requires minimal - * resource and memory management. Canned release function freeing - * memory allocated for the device allows drivers using such devices - * to be unloaded without waiting for the last reference to the device - * to be dropped. + * This function creates a simple platform device that requires minimal + * resource and memory management. Canned release function freeing memory + * allocated for the device allows drivers using such devices to be + * unloaded without waiting for the last reference to the device to be + * dropped. * - * This interface is primarily intended for use with legacy drivers - * which probe hardware directly. Because such drivers create sysfs - * device nodes themselves, rather than letting system infrastructure - * handle such device enumeration tasks, they don't fully conform to - * the Linux driver model. In particular, when such drivers are built - * as modules, they can't be "hotplugged". + * This interface is primarily intended for use with legacy drivers which + * probe hardware directly. Because such drivers create sysfs device nodes + * themselves, rather than letting system infrastructure handle such device + * enumeration tasks, they don't fully conform to the Linux driver model. + * In particular, when such drivers are built as modules, they can't be + * "hotplugged". */ -struct platform_device *platform_device_register_simple(const char *name, int id, - struct resource *res, unsigned int num) +struct platform_device *platform_device_register_simple(const char *name, + int id, + struct resource *res, + unsigned int num) { struct platform_device *pdev; int retval; @@ -436,8 +437,8 @@ static int platform_drv_resume(struct device *_dev) } /** - * platform_driver_register - * @drv: platform driver structure + * platform_driver_register + * @drv: platform driver structure */ int platform_driver_register(struct platform_driver *drv) { @@ -457,8 +458,8 @@ int platform_driver_register(struct platform_driver *drv) EXPORT_SYMBOL_GPL(platform_driver_register); /** - * platform_driver_unregister - * @drv: platform driver structure + * platform_driver_unregister + * @drv: platform driver structure */ void platform_driver_unregister(struct platform_driver *drv) { @@ -516,8 +517,8 @@ EXPORT_SYMBOL_GPL(platform_driver_probe); * (b) sysfs attribute lets new-style coldplug recover from hotplug events * mishandled before system is fully running: "modprobe $(cat modalias)" */ -static ssize_t -modalias_show(struct device *dev, struct device_attribute *a, char *buf) +static ssize_t modalias_show(struct device *dev, struct device_attribute *a, + char *buf) { struct platform_device *pdev = to_platform_device(dev); int len = snprintf(buf, PAGE_SIZE, "platform:%s\n", pdev->name); @@ -538,26 +539,24 @@ static int platform_uevent(struct device *dev, struct kobj_uevent_env *env) return 0; } - /** - * platform_match - bind platform device to platform driver. - * @dev: device. - * @drv: driver. + * platform_match - bind platform device to platform driver. + * @dev: device. + * @drv: driver. * - * Platform device IDs are assumed to be encoded like this: - * "", where is a short description of the - * type of device, like "pci" or "floppy", and is the - * enumerated instance of the device, like '0' or '42'. - * Driver IDs are simply "". - * So, extract the from the platform_device structure, - * and compare it against the name of the driver. Return whether - * they match or not. + * Platform device IDs are assumed to be encoded like this: + * "", where is a short description of the type of + * device, like "pci" or "floppy", and is the enumerated + * instance of the device, like '0' or '42'. Driver IDs are simply + * "". So, extract the from the platform_device structure, + * and compare it against the name of the driver. Return whether they match + * or not. */ - -static int platform_match(struct device * dev, struct device_driver * drv) +static int platform_match(struct device *dev, struct device_driver *drv) { - struct platform_device *pdev = container_of(dev, struct platform_device, dev); + struct platform_device *pdev; + pdev = container_of(dev, struct platform_device, dev); return (strncmp(pdev->name, drv->name, BUS_ID_SIZE) == 0); } @@ -574,9 +573,10 @@ static int platform_suspend(struct device *dev, pm_message_t mesg) static int platform_suspend_late(struct device *dev, pm_message_t mesg) { struct platform_driver *drv = to_platform_driver(dev->driver); - struct platform_device *pdev = container_of(dev, struct platform_device, dev); + struct platform_device *pdev; int ret = 0; + pdev = container_of(dev, struct platform_device, dev); if (dev->driver && drv->suspend_late) ret = drv->suspend_late(pdev, mesg); @@ -586,16 +586,17 @@ static int platform_suspend_late(struct device *dev, pm_message_t mesg) static int platform_resume_early(struct device *dev) { struct platform_driver *drv = to_platform_driver(dev->driver); - struct platform_device *pdev = container_of(dev, struct platform_device, dev); + struct platform_device *pdev; int ret = 0; + pdev = container_of(dev, struct platform_device, dev); if (dev->driver && drv->resume_early) ret = drv->resume_early(pdev); return ret; } -static int platform_resume(struct device * dev) +static int platform_resume(struct device *dev) { int ret = 0; -- cgit v1.1