aboutsummaryrefslogtreecommitdiff
path: root/drivers/staging/iio/industrialio-core.c
diff options
context:
space:
mode:
authorJonathan Cameron <jic23@cam.ac.uk>2011-08-12 17:08:50 +0100
committerGreg Kroah-Hartman <gregkh@suse.de>2011-08-23 13:31:12 -0700
commit9aa1a167f0b8d6a58fe012992fd801bd78bf91f1 (patch)
treeb6c3a3a320c8f3397e156abd990c171524dda69e /drivers/staging/iio/industrialio-core.c
parent232b9cba130025d47531c5c539d6affc64950213 (diff)
staging:iio:core squash trivial wrappers and use ida allocation func.
Reorder to remove need for definitions currently in header. Remove ida related utility function defs from header. 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.c108
1 files changed, 42 insertions, 66 deletions
diff --git a/drivers/staging/iio/industrialio-core.c b/drivers/staging/iio/industrialio-core.c
index 97f4d632917..b4246491bfc 100644
--- a/drivers/staging/iio/industrialio-core.c
+++ b/drivers/staging/iio/industrialio-core.c
@@ -87,6 +87,36 @@ static const char * const iio_chan_info_postfix[] = {
[IIO_CHAN_INFO_PEAK_SCALE_SHARED/2] = "peak_scale",
};
+/* Return a negative errno on failure */
+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;
+}
+EXPORT_SYMBOL(iio_get_new_ida_val);
+
+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);
+}
+EXPORT_SYMBOL(iio_free_ida_val);
+
int iio_push_event(struct iio_dev *dev_info,
int ev_line,
int ev_code,
@@ -246,28 +276,18 @@ static struct device_type iio_event_type = {
int iio_device_get_chrdev_minor(void)
{
- int ret, val;
+ int ret;
-ida_again:
- if (unlikely(ida_pre_get(&iio_chrdev_ida, GFP_KERNEL) == 0))
- return -ENOMEM;
- spin_lock(&iio_ida_lock);
- ret = ida_get_new(&iio_chrdev_ida, &val);
- spin_unlock(&iio_ida_lock);
- if (unlikely(ret == -EAGAIN))
- goto ida_again;
- else if (unlikely(ret))
+ ret = iio_get_new_ida_val(&iio_chrdev_ida);
+ if (ret < IIO_DEV_MAX) /* both errors and valid */
return ret;
- if (val > IIO_DEV_MAX)
+ else
return -ENOMEM;
- return val;
}
void iio_device_free_chrdev_minor(int val)
{
- spin_lock(&iio_ida_lock);
- ida_remove(&iio_chrdev_ida, val);
- spin_unlock(&iio_ida_lock);
+ iio_free_ida_val(&iio_chrdev_ida, val);
}
static int iio_setup_ev_int(struct iio_event_interface *ev_int,
@@ -329,24 +349,6 @@ static void iio_free_ev_int(struct iio_event_interface *ev_int)
put_device(&ev_int->dev);
}
-static int __init iio_dev_init(void)
-{
- int err;
-
- err = alloc_chrdev_region(&iio_devt, 0, IIO_DEV_MAX, "iio");
- if (err < 0)
- printk(KERN_ERR "%s: failed to allocate char dev region\n",
- __FILE__);
-
- return err;
-}
-
-static void __exit iio_dev_exit(void)
-{
- if (iio_devt)
- unregister_chrdev_region(iio_devt, IIO_DEV_MAX);
-}
-
static int __init iio_init(void)
{
int ret;
@@ -360,9 +362,12 @@ static int __init iio_init(void)
goto error_nothing;
}
- ret = iio_dev_init();
- if (ret < 0)
+ ret = alloc_chrdev_region(&iio_devt, 0, IIO_DEV_MAX, "iio");
+ if (ret < 0) {
+ printk(KERN_ERR "%s: failed to allocate char dev region\n",
+ __FILE__);
goto error_unregister_bus_type;
+ }
return 0;
@@ -374,7 +379,8 @@ error_nothing:
static void __exit iio_exit(void)
{
- iio_dev_exit();
+ if (iio_devt)
+ unregister_chrdev_region(iio_devt, IIO_DEV_MAX);
bus_unregister(&iio_bus_type);
}
@@ -806,36 +812,6 @@ static void iio_device_unregister_sysfs(struct iio_dev *dev_info)
sysfs_remove_group(&dev_info->dev.kobj, &iio_base_dummy_group);
}
-/* Return a negative errno on failure */
-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;
-}
-EXPORT_SYMBOL(iio_get_new_ida_val);
-
-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);
-}
-EXPORT_SYMBOL(iio_free_ida_val);
-
static const char * const iio_ev_type_text[] = {
[IIO_EV_TYPE_THRESH] = "thresh",
[IIO_EV_TYPE_MAG] = "mag",