diff options
author | Jonathan Cameron <jic23@cam.ac.uk> | 2011-08-30 12:41:07 +0100 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@suse.de> | 2011-09-06 16:00:25 -0700 |
commit | 47c24fdd4253a2c8d730b978a186923b1af5e879 (patch) | |
tree | c70e6887bb431943e5307d328bb0f480f802f738 /drivers/staging/iio/industrialio-core.c | |
parent | 5aa9618896e0ba49b444731f9fafa7f7c18a13ab (diff) | |
download | talos-obmc-linux-47c24fdd4253a2c8d730b978a186923b1af5e879.tar.gz talos-obmc-linux-47c24fdd4253a2c8d730b978a186923b1af5e879.zip |
staging:iio: use ida_simple_get and ida_simple_remove + merge ids
Use new simple ida allocation functions to remove some boilerplate
code.
Also, now we only have one chdev per device we don't need to maintain
a separate ida for minor numbers. Just use the devices id.
Signed-off-by: Jonathan Cameron <jic23@cam.ac.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers/staging/iio/industrialio-core.c')
-rw-r--r-- | drivers/staging/iio/industrialio-core.c | 63 |
1 files changed, 5 insertions, 58 deletions
diff --git a/drivers/staging/iio/industrialio-core.c b/drivers/staging/iio/industrialio-core.c index 269a0f2bc3ee..13f8c820f50e 100644 --- a/drivers/staging/iio/industrialio-core.c +++ b/drivers/staging/iio/industrialio-core.c @@ -26,13 +26,8 @@ #include "iio_core.h" #include "iio_core_trigger.h" #include "chrdev.h" - -/* IDR to assign each registered device a unique id*/ +/* IDA to assign each registered device a unique id*/ static DEFINE_IDA(iio_ida); -/* IDR to allocate character device minor numbers */ -static DEFINE_IDA(iio_chrdev_ida); -/* Lock used to protect both of the above */ -static DEFINE_SPINLOCK(iio_ida_lock); static dev_t iio_devt; @@ -88,34 +83,6 @@ static const char * const iio_chan_info_postfix[] = { = "quadrature_correction_raw", }; -/* Return a negative errno on failure */ -static int iio_get_new_ida_val(struct ida *this_ida) -{ - int ret; - int val; - -ida_again: - if (unlikely(ida_pre_get(this_ida, GFP_KERNEL) == 0)) - return -ENOMEM; - - spin_lock(&iio_ida_lock); - ret = ida_get_new(this_ida, &val); - spin_unlock(&iio_ida_lock); - if (unlikely(ret == -EAGAIN)) - goto ida_again; - else if (unlikely(ret)) - return ret; - - return val; -} - -static void iio_free_ida_val(struct ida *this_ida, int id) -{ - spin_lock(&iio_ida_lock); - ida_remove(this_ida, id); - spin_unlock(&iio_ida_lock); -} - /** * struct iio_detected_event_list - list element for events that have occurred * @list: linked list header @@ -269,22 +236,6 @@ static const struct file_operations iio_event_chrdev_fileops = { .llseek = noop_llseek, }; -static int iio_device_get_chrdev_minor(void) -{ - int ret; - - ret = iio_get_new_ida_val(&iio_chrdev_ida); - if (ret < IIO_DEV_MAX) /* both errors and valid */ - return ret; - else - return -ENOMEM; -} - -static void iio_device_free_chrdev_minor(int val) -{ - iio_free_ida_val(&iio_chrdev_ida, val); -} - static int iio_event_getfd(struct iio_dev *indio_dev) { if (indio_dev->event_interface == NULL) @@ -1067,7 +1018,6 @@ static void iio_dev_release(struct device *device) { struct iio_dev *dev_info = container_of(device, struct iio_dev, dev); cdev_del(&dev_info->chrdev); - iio_device_free_chrdev_minor(MINOR(device->devt)); iio_put(); kfree(dev_info); } @@ -1168,19 +1118,16 @@ int iio_device_register(struct iio_dev *dev_info) { int ret; - dev_info->id = iio_get_new_ida_val(&iio_ida); + dev_info->id = ida_simple_get(&iio_ida, 0, 0, GFP_KERNEL); if (dev_info->id < 0) { ret = dev_info->id; dev_err(&dev_info->dev, "Failed to get id\n"); goto error_ret; } dev_set_name(&dev_info->dev, "iio:device%d", dev_info->id); - ret = iio_device_get_chrdev_minor(); - if (ret < 0) - goto error_free_ida; /* configure elements for the chrdev */ - dev_info->dev.devt = MKDEV(MAJOR(iio_devt), ret); + dev_info->dev.devt = MKDEV(MAJOR(iio_devt), dev_info->id); ret = device_add(&dev_info->dev); if (ret) @@ -1210,7 +1157,7 @@ error_free_sysfs: error_del_device: device_del(&dev_info->dev); error_free_ida: - iio_free_ida_val(&iio_ida, dev_info->id); + ida_simple_remove(&iio_ida, dev_info->id); error_ret: return ret; } @@ -1222,7 +1169,7 @@ void iio_device_unregister(struct iio_dev *dev_info) iio_device_unregister_trigger_consumer(dev_info); iio_device_unregister_eventset(dev_info); iio_device_unregister_sysfs(dev_info); - iio_free_ida_val(&iio_ida, dev_info->id); + ida_simple_remove(&iio_ida, dev_info->id); device_unregister(&dev_info->dev); } EXPORT_SYMBOL(iio_device_unregister); |