]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
staging:iio:core squash trivial wrappers and use ida allocation func.
authorJonathan Cameron <jic23@cam.ac.uk>
Fri, 12 Aug 2011 16:08:50 +0000 (17:08 +0100)
committerGreg Kroah-Hartman <gregkh@suse.de>
Tue, 23 Aug 2011 20:31:12 +0000 (13:31 -0700)
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>
drivers/staging/iio/iio.h
drivers/staging/iio/industrialio-core.c

index 7a6ce4d0fb7bde721c278f7be59de58ec2693d87..42254b49395f666d3a2a88712720d72f7cdda66f 100644 (file)
@@ -432,8 +432,4 @@ static inline bool iio_ring_enabled(struct iio_dev *dev_info)
                   | INDIO_RING_HARDWARE_BUFFER);
 };
 
-struct ida;
-
-int iio_get_new_ida_val(struct ida *this_ida);
-void iio_free_ida_val(struct ida *this_ida, int id);
 #endif /* _INDUSTRIAL_IO_H_ */
index 97f4d63291703be56722475c49c966002166aefe..b4246491bfca8e1ed9d017418017051ca53959aa 100644 (file)
@@ -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",