Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 23263
b: refs/heads/master
c: ded2b66
h: refs/heads/master
i:
  23261: 816c537
  23259: e6009d0
  23255: cea1935
  23247: 45487e3
  23231: ecfeade
v: v3
  • Loading branch information
Mark M. Hoffman authored and Greg Kroah-Hartman committed Mar 23, 2006
1 parent 257adf1 commit 3040724
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 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: f6c27fc17c5e575c5471fb344bdbd5f5f6072136
refs/heads/master: ded2b66615613093eeb83b81499bc270de8fc499
26 changes: 20 additions & 6 deletions trunk/drivers/hwmon/hwmon.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@
#include <linux/idr.h>
#include <linux/hwmon.h>
#include <linux/gfp.h>
#include <linux/spinlock.h>

#define HWMON_ID_PREFIX "hwmon"
#define HWMON_ID_FORMAT HWMON_ID_PREFIX "%d"

static struct class *hwmon_class;

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

/**
* hwmon_device_register - register w/ hwmon sysfs class
Expand All @@ -37,20 +39,30 @@ static DEFINE_IDR(hwmon_idr);
struct class_device *hwmon_device_register(struct device *dev)
{
struct class_device *cdev;
int id;
int id, err;

if (idr_pre_get(&hwmon_idr, GFP_KERNEL) == 0)
again:
if (unlikely(idr_pre_get(&hwmon_idr, GFP_KERNEL) == 0))
return ERR_PTR(-ENOMEM);

if (idr_get_new(&hwmon_idr, NULL, &id) < 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);

id = id & MAX_ID_MASK;
cdev = class_device_create(hwmon_class, NULL, MKDEV(0,0), dev,
HWMON_ID_FORMAT, id);

if (IS_ERR(cdev))
if (IS_ERR(cdev)) {
spin_lock(&idr_lock);
idr_remove(&hwmon_idr, id);
spin_unlock(&idr_lock);
}

return cdev;
}
Expand All @@ -64,9 +76,11 @@ void hwmon_device_unregister(struct class_device *cdev)
{
int id;

if (sscanf(cdev->class_id, HWMON_ID_FORMAT, &id) == 1) {
if (likely(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");
Expand Down

0 comments on commit 3040724

Please sign in to comment.