X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=drivers%2Fbase%2Fcore.c;h=9c0070b5bd3e75d828a44d405dca4695b70e6ef6;hb=dd07a8db7283f52f347aee468007556944b5b393;hp=b1727876182cdff178550856fc0696a770db9bdc;hpb=5bdeae46be6dfe9efa44a548bd622af325f4bdb4;p=linux-2.6 diff --git a/drivers/base/core.c b/drivers/base/core.c index b172787618..9c0070b5bd 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); - } } /** @@ -1144,25 +1140,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 +1159,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 +1187,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 */