Commit 4ca5f468 authored by Jonathan Cameron's avatar Jonathan Cameron Committed by Linus Torvalds

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: default avatarJonathan Cameron <jic23@cam.ac.uk>
Cc: Rusty Russell <rusty@rustcorp.com.au>
Cc: Tejun Heo <tj@kernel.org>
Acked-by: default avatarGuenter 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: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent c51eaacc
...@@ -27,8 +27,7 @@ ...@@ -27,8 +27,7 @@
static struct class *hwmon_class; static struct class *hwmon_class;
static DEFINE_IDR(hwmon_idr); static DEFINE_IDA(hwmon_ida);
static DEFINE_SPINLOCK(idr_lock);
/** /**
* hwmon_device_register - register w/ hwmon * hwmon_device_register - register w/ hwmon
...@@ -42,30 +41,17 @@ static DEFINE_SPINLOCK(idr_lock); ...@@ -42,30 +41,17 @@ static DEFINE_SPINLOCK(idr_lock);
struct device *hwmon_device_register(struct device *dev) struct device *hwmon_device_register(struct device *dev)
{ {
struct device *hwdev; struct device *hwdev;
int id, err; int id;
again:
if (unlikely(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)) id = ida_simple_get(&hwmon_ida, 0, 0, GFP_KERNEL);
goto again; if (id < 0)
else if (unlikely(err)) return ERR_PTR(id);
return ERR_PTR(err);
id = id & MAX_ID_MASK;
hwdev = device_create(hwmon_class, dev, MKDEV(0, 0), NULL, hwdev = device_create(hwmon_class, dev, MKDEV(0, 0), NULL,
HWMON_ID_FORMAT, id); HWMON_ID_FORMAT, id);
if (IS_ERR(hwdev)) { if (IS_ERR(hwdev))
spin_lock(&idr_lock); ida_simple_remove(&hwmon_ida, id);
idr_remove(&hwmon_idr, id);
spin_unlock(&idr_lock);
}
return hwdev; return hwdev;
} }
...@@ -81,9 +67,7 @@ void hwmon_device_unregister(struct device *dev) ...@@ -81,9 +67,7 @@ void hwmon_device_unregister(struct device *dev)
if (likely(sscanf(dev_name(dev), HWMON_ID_FORMAT, &id) == 1)) { if (likely(sscanf(dev_name(dev), HWMON_ID_FORMAT, &id) == 1)) {
device_unregister(dev); device_unregister(dev);
spin_lock(&idr_lock); ida_simple_remove(&hwmon_ida, id);
idr_remove(&hwmon_idr, id);
spin_unlock(&idr_lock);
} else } else
dev_dbg(dev->parent, dev_dbg(dev->parent,
"hwmon_device_unregister() failed: bad class ID!\n"); "hwmon_device_unregister() failed: bad class ID!\n");
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment