Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 273232
b: refs/heads/master
c: 6d03d06
h: refs/heads/master
v: v3
  • Loading branch information
Jonathan Cameron authored and Linus Torvalds committed Nov 2, 2011
1 parent 1f7efca commit fa8ea16
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 24 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: f919b9235f930e649b374a50009c6c268bd9a073
refs/heads/master: 6d03d06db8881f4f9da87d5c77234b98c40a30e9
32 changes: 9 additions & 23 deletions trunk/drivers/rtc/class.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,13 @@
#include "rtc-core.h"


static DEFINE_IDR(rtc_idr);
static DEFINE_MUTEX(idr_lock);
static DEFINE_IDA(rtc_ida);
struct class *rtc_class;

static void rtc_device_release(struct device *dev)
{
struct rtc_device *rtc = to_rtc_device(dev);
mutex_lock(&idr_lock);
idr_remove(&rtc_idr, rtc->id);
mutex_unlock(&idr_lock);
ida_simple_remove(&rtc_ida, rtc->id);
kfree(rtc);
}

Expand Down Expand Up @@ -146,25 +143,16 @@ struct rtc_device *rtc_device_register(const char *name, struct device *dev,
struct rtc_wkalrm alrm;
int id, err;

if (idr_pre_get(&rtc_idr, GFP_KERNEL) == 0) {
err = -ENOMEM;
id = ida_simple_get(&rtc_ida, 0, 0, GFP_KERNEL);
if (id < 0) {
err = id;
goto exit;
}


mutex_lock(&idr_lock);
err = idr_get_new(&rtc_idr, NULL, &id);
mutex_unlock(&idr_lock);

if (err < 0)
goto exit;

id = id & MAX_ID_MASK;

rtc = kzalloc(sizeof(struct rtc_device), GFP_KERNEL);
if (rtc == NULL) {
err = -ENOMEM;
goto exit_idr;
goto exit_ida;
}

rtc->id = id;
Expand Down Expand Up @@ -222,10 +210,8 @@ struct rtc_device *rtc_device_register(const char *name, struct device *dev,
exit_kfree:
kfree(rtc);

exit_idr:
mutex_lock(&idr_lock);
idr_remove(&rtc_idr, id);
mutex_unlock(&idr_lock);
exit_ida:
ida_simple_remove(&rtc_ida, id);

exit:
dev_err(dev, "rtc core: unable to register %s, err = %d\n",
Expand Down Expand Up @@ -276,7 +262,7 @@ static void __exit rtc_exit(void)
{
rtc_dev_exit();
class_destroy(rtc_class);
idr_destroy(&rtc_idr);
ida_destroy(&rtc_ida);
}

subsys_initcall(rtc_init);
Expand Down

0 comments on commit fa8ea16

Please sign in to comment.