Commit 9aa1a167 authored by Jonathan Cameron's avatar Jonathan Cameron Committed by Greg Kroah-Hartman

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: default avatarJonathan Cameron <jic23@cam.ac.uk>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
parent 232b9cba
...@@ -432,8 +432,4 @@ static inline bool iio_ring_enabled(struct iio_dev *dev_info) ...@@ -432,8 +432,4 @@ static inline bool iio_ring_enabled(struct iio_dev *dev_info)
| INDIO_RING_HARDWARE_BUFFER); | 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_ */ #endif /* _INDUSTRIAL_IO_H_ */
...@@ -87,6 +87,36 @@ static const char * const iio_chan_info_postfix[] = { ...@@ -87,6 +87,36 @@ static const char * const iio_chan_info_postfix[] = {
[IIO_CHAN_INFO_PEAK_SCALE_SHARED/2] = "peak_scale", [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 iio_push_event(struct iio_dev *dev_info,
int ev_line, int ev_line,
int ev_code, int ev_code,
...@@ -246,28 +276,18 @@ static struct device_type iio_event_type = { ...@@ -246,28 +276,18 @@ static struct device_type iio_event_type = {
int iio_device_get_chrdev_minor(void) int iio_device_get_chrdev_minor(void)
{ {
int ret, val; int ret;
ida_again: ret = iio_get_new_ida_val(&iio_chrdev_ida);
if (unlikely(ida_pre_get(&iio_chrdev_ida, GFP_KERNEL) == 0)) if (ret < IIO_DEV_MAX) /* both errors and valid */
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))
return ret; return ret;
if (val > IIO_DEV_MAX) else
return -ENOMEM; return -ENOMEM;
return val;
} }
void iio_device_free_chrdev_minor(int val) void iio_device_free_chrdev_minor(int val)
{ {
spin_lock(&iio_ida_lock); iio_free_ida_val(&iio_chrdev_ida, val);
ida_remove(&iio_chrdev_ida, val);
spin_unlock(&iio_ida_lock);
} }
static int iio_setup_ev_int(struct iio_event_interface *ev_int, 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) ...@@ -329,24 +349,6 @@ static void iio_free_ev_int(struct iio_event_interface *ev_int)
put_device(&ev_int->dev); 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) static int __init iio_init(void)
{ {
int ret; int ret;
...@@ -360,9 +362,12 @@ static int __init iio_init(void) ...@@ -360,9 +362,12 @@ static int __init iio_init(void)
goto error_nothing; goto error_nothing;
} }
ret = iio_dev_init(); ret = alloc_chrdev_region(&iio_devt, 0, IIO_DEV_MAX, "iio");
if (ret < 0) if (ret < 0) {
printk(KERN_ERR "%s: failed to allocate char dev region\n",
__FILE__);
goto error_unregister_bus_type; goto error_unregister_bus_type;
}
return 0; return 0;
...@@ -374,7 +379,8 @@ static int __init iio_init(void) ...@@ -374,7 +379,8 @@ static int __init iio_init(void)
static void __exit iio_exit(void) 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); bus_unregister(&iio_bus_type);
} }
...@@ -806,36 +812,6 @@ static void iio_device_unregister_sysfs(struct iio_dev *dev_info) ...@@ -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); 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[] = { static const char * const iio_ev_type_text[] = {
[IIO_EV_TYPE_THRESH] = "thresh", [IIO_EV_TYPE_THRESH] = "thresh",
[IIO_EV_TYPE_MAG] = "mag", [IIO_EV_TYPE_MAG] = "mag",
......
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