aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/hwmon/hwmon.c
diff options
context:
space:
mode:
authorJonathan Cameron <jic23@cam.ac.uk>2011-10-31 20:10:09 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2011-10-31 20:30:51 -0400
commit4ca5f468cc2a0be1cba585f335dcbe56b40944f2 (patch)
treeb3288c21e2fe572ab1b3f55219c192a1f6d97cbd /drivers/hwmon/hwmon.c
parentc51eaacce2ae6861e1ad8c80ade6102ad428dc93 (diff)
hwmon: convert idr to ida and use ida_simple interface
hwmon was using an idr with a NULL pointer, so convert to an ida which then allows use of Rusty's ida_simple_get. Signed-off-by: Jonathan Cameron <jic23@cam.ac.uk> Cc: Rusty Russell <rusty@rustcorp.com.au> Cc: Tejun Heo <tj@kernel.org> Acked-by: Guenter Roeck <guenter.roeck@ericsson.com> Cc: James Bottomley <James.Bottomley@HansenPartnership.com> Cc: David Airlie <airlied@linux.ie> Cc: Thomas Hellstrom <thellstrom@vmware.com> Cc: Evgeniy Polyakov <zbr@ioremap.net> Cc: Darrick J. Wong <djwong@us.ibm.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'drivers/hwmon/hwmon.c')
-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");