Commit 6d03d06d authored by Jonathan Cameron's avatar Jonathan Cameron Committed by Linus Torvalds

drivers/rtc/class.c: convert idr to ida and use ida_simple_get()

This is the one use of an ida that doesn't retry on receiving -EAGAIN.
I'm assuming do so will cause no harm and may help on a rare occasion.
Signed-off-by: default avatarJonathan Cameron <jic23@cam.ac.uk>
Cc: Alessandro Zummo <a.zummo@towertech.it>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent f919b923
...@@ -21,16 +21,13 @@ ...@@ -21,16 +21,13 @@
#include "rtc-core.h" #include "rtc-core.h"
static DEFINE_IDR(rtc_idr); static DEFINE_IDA(rtc_ida);
static DEFINE_MUTEX(idr_lock);
struct class *rtc_class; struct class *rtc_class;
static void rtc_device_release(struct device *dev) static void rtc_device_release(struct device *dev)
{ {
struct rtc_device *rtc = to_rtc_device(dev); struct rtc_device *rtc = to_rtc_device(dev);
mutex_lock(&idr_lock); ida_simple_remove(&rtc_ida, rtc->id);
idr_remove(&rtc_idr, rtc->id);
mutex_unlock(&idr_lock);
kfree(rtc); kfree(rtc);
} }
...@@ -146,25 +143,16 @@ struct rtc_device *rtc_device_register(const char *name, struct device *dev, ...@@ -146,25 +143,16 @@ struct rtc_device *rtc_device_register(const char *name, struct device *dev,
struct rtc_wkalrm alrm; struct rtc_wkalrm alrm;
int id, err; int id, err;
if (idr_pre_get(&rtc_idr, GFP_KERNEL) == 0) { id = ida_simple_get(&rtc_ida, 0, 0, GFP_KERNEL);
err = -ENOMEM; if (id < 0) {
err = id;
goto exit; 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); rtc = kzalloc(sizeof(struct rtc_device), GFP_KERNEL);
if (rtc == NULL) { if (rtc == NULL) {
err = -ENOMEM; err = -ENOMEM;
goto exit_idr; goto exit_ida;
} }
rtc->id = id; rtc->id = id;
...@@ -222,10 +210,8 @@ struct rtc_device *rtc_device_register(const char *name, struct device *dev, ...@@ -222,10 +210,8 @@ struct rtc_device *rtc_device_register(const char *name, struct device *dev,
exit_kfree: exit_kfree:
kfree(rtc); kfree(rtc);
exit_idr: exit_ida:
mutex_lock(&idr_lock); ida_simple_remove(&rtc_ida, id);
idr_remove(&rtc_idr, id);
mutex_unlock(&idr_lock);
exit: exit:
dev_err(dev, "rtc core: unable to register %s, err = %d\n", dev_err(dev, "rtc core: unable to register %s, err = %d\n",
...@@ -276,7 +262,7 @@ static void __exit rtc_exit(void) ...@@ -276,7 +262,7 @@ static void __exit rtc_exit(void)
{ {
rtc_dev_exit(); rtc_dev_exit();
class_destroy(rtc_class); class_destroy(rtc_class);
idr_destroy(&rtc_idr); ida_destroy(&rtc_ida);
} }
subsys_initcall(rtc_init); subsys_initcall(rtc_init);
......
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