X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=drivers%2Fhwmon%2Fhwmon.c;fp=drivers%2Fhwmon%2Fhwmon.c;h=dddd3eb9b3870ef060e84db9d8db4e099303c71d;hb=64ba3f394c830ec48a1c31b53dcae312c56f1604;hp=106fa01cdb6069717c61ee6a596e94d1ad38bf98;hpb=be1e6109ac94a859551f8e1774eb9a8469fe055c;p=linux-2.6.git diff --git a/drivers/hwmon/hwmon.c b/drivers/hwmon/hwmon.c index 106fa01cd..dddd3eb9b 100644 --- a/drivers/hwmon/hwmon.c +++ b/drivers/hwmon/hwmon.c @@ -17,7 +17,6 @@ #include #include #include -#include #define HWMON_ID_PREFIX "hwmon" #define HWMON_ID_FORMAT HWMON_ID_PREFIX "%d" @@ -25,7 +24,6 @@ static struct class *hwmon_class; static DEFINE_IDR(hwmon_idr); -static DEFINE_SPINLOCK(idr_lock); /** * hwmon_device_register - register w/ hwmon sysfs class @@ -39,30 +37,20 @@ static DEFINE_SPINLOCK(idr_lock); struct class_device *hwmon_device_register(struct device *dev) { struct class_device *cdev; - int id, err; + int id; -again: - if (unlikely(idr_pre_get(&hwmon_idr, GFP_KERNEL) == 0)) + if (idr_pre_get(&hwmon_idr, GFP_KERNEL) == 0) return ERR_PTR(-ENOMEM); - spin_lock(&idr_lock); - err = idr_get_new(&hwmon_idr, NULL, &id); - spin_unlock(&idr_lock); - - if (unlikely(err == -EAGAIN)) - goto again; - else if (unlikely(err)) - return ERR_PTR(err); + if (idr_get_new(&hwmon_idr, NULL, &id) < 0) + return ERR_PTR(-ENOMEM); id = id & MAX_ID_MASK; cdev = class_device_create(hwmon_class, NULL, MKDEV(0,0), dev, HWMON_ID_FORMAT, id); - if (IS_ERR(cdev)) { - spin_lock(&idr_lock); + if (IS_ERR(cdev)) idr_remove(&hwmon_idr, id); - spin_unlock(&idr_lock); - } return cdev; } @@ -76,11 +64,9 @@ void hwmon_device_unregister(struct class_device *cdev) { int id; - if (likely(sscanf(cdev->class_id, HWMON_ID_FORMAT, &id) == 1)) { + if (sscanf(cdev->class_id, HWMON_ID_FORMAT, &id) == 1) { class_device_unregister(cdev); - spin_lock(&idr_lock); idr_remove(&hwmon_idr, id); - spin_unlock(&idr_lock); } else dev_dbg(cdev->dev, "hwmon_device_unregister() failed: bad class ID!\n");