aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--drivers/hwmon/hwmon.c32
1 files changed, 8 insertions, 24 deletions
diff --git a/drivers/hwmon/hwmon.c b/drivers/hwmon/hwmon.c
index a61e7815a2a9..6460487e41b5 100644
--- a/drivers/hwmon/hwmon.c
+++ b/drivers/hwmon/hwmon.c
@@ -27,8 +27,7 @@
27 27
28static struct class *hwmon_class; 28static struct class *hwmon_class;
29 29
30static DEFINE_IDR(hwmon_idr); 30static DEFINE_IDA(hwmon_ida);
31static DEFINE_SPINLOCK(idr_lock);
32 31
33/** 32/**
34 * hwmon_device_register - register w/ hwmon 33 * hwmon_device_register - register w/ hwmon
@@ -42,30 +41,17 @@ static DEFINE_SPINLOCK(idr_lock);
42struct device *hwmon_device_register(struct device *dev) 41struct device *hwmon_device_register(struct device *dev)
43{ 42{
44 struct device *hwdev; 43 struct device *hwdev;
45 int id, err; 44 int id;
46
47again:
48 if (unlikely(idr_pre_get(&hwmon_idr, GFP_KERNEL) == 0))
49 return ERR_PTR(-ENOMEM);
50
51 spin_lock(&idr_lock);
52 err = idr_get_new(&hwmon_idr, NULL, &id);
53 spin_unlock(&idr_lock);
54 45
55 if (unlikely(err == -EAGAIN)) 46 id = ida_simple_get(&hwmon_ida, 0, 0, GFP_KERNEL);
56 goto again; 47 if (id < 0)
57 else if (unlikely(err)) 48 return ERR_PTR(id);
58 return ERR_PTR(err);
59 49
60 id = id & MAX_ID_MASK;
61 hwdev = device_create(hwmon_class, dev, MKDEV(0, 0), NULL, 50 hwdev = device_create(hwmon_class, dev, MKDEV(0, 0), NULL,
62 HWMON_ID_FORMAT, id); 51 HWMON_ID_FORMAT, id);
63 52
64 if (IS_ERR(hwdev)) { 53 if (IS_ERR(hwdev))
65 spin_lock(&idr_lock); 54 ida_simple_remove(&hwmon_ida, id);
66 idr_remove(&hwmon_idr, id);
67 spin_unlock(&idr_lock);
68 }
69 55
70 return hwdev; 56 return hwdev;
71} 57}
@@ -81,9 +67,7 @@ void hwmon_device_unregister(struct device *dev)
81 67
82 if (likely(sscanf(dev_name(dev), HWMON_ID_FORMAT, &id) == 1)) { 68 if (likely(sscanf(dev_name(dev), HWMON_ID_FORMAT, &id) == 1)) {
83 device_unregister(dev); 69 device_unregister(dev);
84 spin_lock(&idr_lock); 70 ida_simple_remove(&hwmon_ida, id);
85 idr_remove(&hwmon_idr, id);
86 spin_unlock(&idr_lock);
87 } else 71 } else
88 dev_dbg(dev->parent, 72 dev_dbg(dev->parent,
89 "hwmon_device_unregister() failed: bad class ID!\n"); 73 "hwmon_device_unregister() failed: bad class ID!\n");