Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 272174
b: refs/heads/master
c: 4ca5f46
h: refs/heads/master
v: v3
  • Loading branch information
Jonathan Cameron authored and Linus Torvalds committed Nov 1, 2011
1 parent fe8913a commit 04be738
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 25 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: c51eaacce2ae6861e1ad8c80ade6102ad428dc93
refs/heads/master: 4ca5f468cc2a0be1cba585f335dcbe56b40944f2
32 changes: 8 additions & 24 deletions trunk/drivers/hwmon/hwmon.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@

static struct class *hwmon_class;

static DEFINE_IDR(hwmon_idr);
static DEFINE_SPINLOCK(idr_lock);
static DEFINE_IDA(hwmon_ida);

/**
* hwmon_device_register - register w/ hwmon
Expand All @@ -42,30 +41,17 @@ static DEFINE_SPINLOCK(idr_lock);
struct device *hwmon_device_register(struct device *dev)
{
struct device *hwdev;
int id, err;

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);
int id;

if (unlikely(err == -EAGAIN))
goto again;
else if (unlikely(err))
return ERR_PTR(err);
id = ida_simple_get(&hwmon_ida, 0, 0, GFP_KERNEL);
if (id < 0)
return ERR_PTR(id);

id = id & MAX_ID_MASK;
hwdev = device_create(hwmon_class, dev, MKDEV(0, 0), NULL,
HWMON_ID_FORMAT, id);

if (IS_ERR(hwdev)) {
spin_lock(&idr_lock);
idr_remove(&hwmon_idr, id);
spin_unlock(&idr_lock);
}
if (IS_ERR(hwdev))
ida_simple_remove(&hwmon_ida, id);

return hwdev;
}
Expand All @@ -81,9 +67,7 @@ void hwmon_device_unregister(struct device *dev)

if (likely(sscanf(dev_name(dev), HWMON_ID_FORMAT, &id) == 1)) {
device_unregister(dev);
spin_lock(&idr_lock);
idr_remove(&hwmon_idr, id);
spin_unlock(&idr_lock);
ida_simple_remove(&hwmon_ida, id);
} else
dev_dbg(dev->parent,
"hwmon_device_unregister() failed: bad class ID!\n");
Expand Down

0 comments on commit 04be738

Please sign in to comment.