X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=drivers%2Fbase%2Fcore.c;h=7de543d1d0b4337328f95c502915d99b3a4fa871;hb=b881502666783b2d9ca2fc7a056d0f773073a808;hp=b1727876182cdff178550856fc0696a770db9bdc;hpb=c1f3ee120bb61045b1c0a3ead620d1d65af47130;p=linux-2.6 diff --git a/drivers/base/core.c b/drivers/base/core.c index b172787618..7de543d1d0 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c @@ -423,10 +423,8 @@ struct kset *devices_kset; int device_create_file(struct device *dev, struct device_attribute *attr) { int error = 0; - if (get_device(dev)) { + if (dev) error = sysfs_create_file(&dev->kobj, &attr->attr); - put_device(dev); - } return error; } @@ -437,10 +435,8 @@ int device_create_file(struct device *dev, struct device_attribute *attr) */ void device_remove_file(struct device *dev, struct device_attribute *attr) { - if (get_device(dev)) { + if (dev) sysfs_remove_file(&dev->kobj, &attr->attr); - put_device(dev); - } } /** @@ -625,7 +621,8 @@ static struct kobject *get_device_parent(struct device *dev, static void cleanup_glue_dir(struct device *dev, struct kobject *glue_dir) { /* see if we live in a "glue" directory */ - if (!dev->class || glue_dir->kset != &dev->class->class_dirs) + if (!glue_dir || !dev->class || + glue_dir->kset != &dev->class->class_dirs) return; kobject_put(glue_dir); @@ -774,17 +771,10 @@ int device_add(struct device *dev) struct class_interface *class_intf; 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)) { error = -EINVAL; - goto Error; + goto Done; } pr_debug("device: '%s': %s\n", dev->bus_id, __FUNCTION__); @@ -847,11 +837,9 @@ int device_add(struct device *dev) } Done: put_device(dev); - pm_sleep_unlock(); return error; BusError: device_pm_remove(dev); - dpm_sysfs_remove(dev); PMError: if (dev->bus) blocking_notifier_call_chain(&dev->bus->p->bus_notifier, @@ -1144,25 +1132,11 @@ error: } EXPORT_SYMBOL_GPL(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 - */ -static struct device *find_device(struct class *class, dev_t devt) +static int __match_devt(struct device *dev, void *data) { - struct device *dev = NULL; - struct device *dev_tmp; + dev_t *devt = data; - down(&class->sem); - list_for_each_entry(dev_tmp, &class->devices, node) { - if (dev_tmp->devt == devt) { - dev = dev_tmp; - break; - } - } - up(&class->sem); - return dev; + return dev->devt == *devt; } /** @@ -1177,9 +1151,11 @@ void device_destroy(struct class *class, dev_t devt) { struct device *dev; - dev = find_device(class, devt); - if (dev) + dev = class_find_device(class, &devt, __match_devt); + if (dev) { + put_device(dev); device_unregister(dev); + } } EXPORT_SYMBOL_GPL(device_destroy); @@ -1203,9 +1179,11 @@ void destroy_suspended_device(struct class *class, dev_t devt) { struct device *dev; - dev = find_device(class, devt); - if (dev) + dev = class_find_device(class, &devt, __match_devt); + if (dev) { device_pm_schedule_removal(dev); + put_device(dev); + } } EXPORT_SYMBOL_GPL(destroy_suspended_device); #endif /* CONFIG_PM_SLEEP */