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

staging: iio: convert idr to ida as pointer never provided

Signed-off-by: default avatarJonathan Cameron <jic23@cam.ac.uk>
Acked-by: default avatarManuel Stahl <manuel.stahl@iis.fraunhofer.de>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
parent 30295c89
...@@ -135,7 +135,7 @@ void iio_device_unregister(struct iio_dev *dev_info); ...@@ -135,7 +135,7 @@ void iio_device_unregister(struct iio_dev *dev_info);
* physical interrupt lines * physical interrupt lines
* @dev_info: the iio device for which the is an interrupt line * @dev_info: the iio device for which the is an interrupt line
* @line_number: associated line number * @line_number: associated line number
* @id: idr allocated unique id number * @id: ida allocated unique id number
* @irq: associate interrupt number * @irq: associate interrupt number
* @ev_list: event handler list for associated events * @ev_list: event handler list for associated events
* @ev_list_lock: ensure only one access to list at a time * @ev_list_lock: ensure only one access to list at a time
...@@ -302,8 +302,8 @@ static inline bool iio_ring_enabled(struct iio_dev *dev_info) ...@@ -302,8 +302,8 @@ static inline bool iio_ring_enabled(struct iio_dev *dev_info)
| INDIO_RING_HARDWARE_BUFFER); | INDIO_RING_HARDWARE_BUFFER);
}; };
struct idr; struct ida;
int iio_get_new_idr_val(struct idr *this_idr); int iio_get_new_ida_val(struct ida *this_ida);
void iio_free_idr_val(struct idr *this_idr, int id); void iio_free_ida_val(struct ida *this_ida, int id);
#endif /* _INDUSTRIAL_IO_H_ */ #endif /* _INDUSTRIAL_IO_H_ */
...@@ -29,11 +29,11 @@ ...@@ -29,11 +29,11 @@
#define IIO_ID_FORMAT IIO_ID_PREFIX "%d" #define IIO_ID_FORMAT IIO_ID_PREFIX "%d"
/* IDR to assign each registered device a unique id*/ /* IDR to assign each registered device a unique id*/
static DEFINE_IDR(iio_idr); static DEFINE_IDA(iio_ida);
/* IDR to allocate character device minor numbers */ /* IDR to allocate character device minor numbers */
static DEFINE_IDR(iio_chrdev_idr); static DEFINE_IDA(iio_chrdev_ida);
/* Lock used to protect both of the above */ /* Lock used to protect both of the above */
static DEFINE_SPINLOCK(iio_idr_lock); static DEFINE_SPINLOCK(iio_ida_lock);
dev_t iio_devt; dev_t iio_devt;
EXPORT_SYMBOL(iio_devt); EXPORT_SYMBOL(iio_devt);
...@@ -367,14 +367,14 @@ int iio_device_get_chrdev_minor(void) ...@@ -367,14 +367,14 @@ int iio_device_get_chrdev_minor(void)
{ {
int ret, val; int ret, val;
idr_again: ida_again:
if (unlikely(idr_pre_get(&iio_chrdev_idr, GFP_KERNEL) == 0)) if (unlikely(ida_pre_get(&iio_chrdev_ida, GFP_KERNEL) == 0))
return -ENOMEM; return -ENOMEM;
spin_lock(&iio_idr_lock); spin_lock(&iio_ida_lock);
ret = idr_get_new(&iio_chrdev_idr, NULL, &val); ret = ida_get_new(&iio_chrdev_ida, &val);
spin_unlock(&iio_idr_lock); spin_unlock(&iio_ida_lock);
if (unlikely(ret == -EAGAIN)) if (unlikely(ret == -EAGAIN))
goto idr_again; goto ida_again;
else if (unlikely(ret)) else if (unlikely(ret))
return ret; return ret;
if (val > IIO_DEV_MAX) if (val > IIO_DEV_MAX)
...@@ -384,9 +384,9 @@ int iio_device_get_chrdev_minor(void) ...@@ -384,9 +384,9 @@ int iio_device_get_chrdev_minor(void)
void iio_device_free_chrdev_minor(int val) void iio_device_free_chrdev_minor(int val)
{ {
spin_lock(&iio_idr_lock); spin_lock(&iio_ida_lock);
idr_remove(&iio_chrdev_idr, val); ida_remove(&iio_chrdev_ida, val);
spin_unlock(&iio_idr_lock); spin_unlock(&iio_ida_lock);
} }
int iio_setup_ev_int(struct iio_event_interface *ev_int, int iio_setup_ev_int(struct iio_event_interface *ev_int,
...@@ -517,40 +517,39 @@ static void iio_device_unregister_sysfs(struct iio_dev *dev_info) ...@@ -517,40 +517,39 @@ static void iio_device_unregister_sysfs(struct iio_dev *dev_info)
} }
/* Return a negative errno on failure */ /* Return a negative errno on failure */
int iio_get_new_idr_val(struct idr *this_idr) int iio_get_new_ida_val(struct ida *this_ida)
{ {
int ret; int ret;
int val; int val;
idr_again: ida_again:
if (unlikely(idr_pre_get(this_idr, GFP_KERNEL) == 0)) if (unlikely(ida_pre_get(this_ida, GFP_KERNEL) == 0))
return -ENOMEM; return -ENOMEM;
spin_lock(&iio_idr_lock); spin_lock(&iio_ida_lock);
ret = idr_get_new(this_idr, NULL, &val); ret = ida_get_new(this_ida, &val);
spin_unlock(&iio_idr_lock); spin_unlock(&iio_ida_lock);
if (unlikely(ret == -EAGAIN)) if (unlikely(ret == -EAGAIN))
goto idr_again; goto ida_again;
else if (unlikely(ret)) else if (unlikely(ret))
return ret; return ret;
return val; return val;
} }
EXPORT_SYMBOL(iio_get_new_idr_val); EXPORT_SYMBOL(iio_get_new_ida_val);
void iio_free_idr_val(struct idr *this_idr, int id) void iio_free_ida_val(struct ida *this_ida, int id)
{ {
spin_lock(&iio_idr_lock); spin_lock(&iio_ida_lock);
idr_remove(this_idr, id); ida_remove(this_ida, id);
spin_unlock(&iio_idr_lock); spin_unlock(&iio_ida_lock);
} }
EXPORT_SYMBOL(iio_free_idr_val); EXPORT_SYMBOL(iio_free_ida_val);
static int iio_device_register_id(struct iio_dev *dev_info, static int iio_device_register_id(struct iio_dev *dev_info,
struct idr *this_idr) struct ida *this_ida)
{ {
dev_info->id = iio_get_new_ida_val(&iio_ida);
dev_info->id = iio_get_new_idr_val(&iio_idr);
if (dev_info->id < 0) if (dev_info->id < 0)
return dev_info->id; return dev_info->id;
return 0; return 0;
...@@ -558,7 +557,7 @@ static int iio_device_register_id(struct iio_dev *dev_info, ...@@ -558,7 +557,7 @@ static int iio_device_register_id(struct iio_dev *dev_info,
static void iio_device_unregister_id(struct iio_dev *dev_info) static void iio_device_unregister_id(struct iio_dev *dev_info)
{ {
iio_free_idr_val(&iio_idr, dev_info->id); iio_free_ida_val(&iio_ida, dev_info->id);
} }
static inline int __iio_add_event_config_attrs(struct iio_dev *dev_info, int i) static inline int __iio_add_event_config_attrs(struct iio_dev *dev_info, int i)
...@@ -757,7 +756,7 @@ int iio_device_register(struct iio_dev *dev_info) ...@@ -757,7 +756,7 @@ int iio_device_register(struct iio_dev *dev_info)
{ {
int ret; int ret;
ret = iio_device_register_id(dev_info, &iio_idr); ret = iio_device_register_id(dev_info, &iio_ida);
if (ret) { if (ret) {
dev_err(&dev_info->dev, "Failed to get id\n"); dev_err(&dev_info->dev, "Failed to get id\n");
goto error_ret; goto error_ret;
...@@ -766,7 +765,7 @@ int iio_device_register(struct iio_dev *dev_info) ...@@ -766,7 +765,7 @@ int iio_device_register(struct iio_dev *dev_info)
ret = device_add(&dev_info->dev); ret = device_add(&dev_info->dev);
if (ret) if (ret)
goto error_free_idr; goto error_free_ida;
ret = iio_device_register_sysfs(dev_info); ret = iio_device_register_sysfs(dev_info);
if (ret) { if (ret) {
dev_err(dev_info->dev.parent, dev_err(dev_info->dev.parent,
...@@ -788,7 +787,7 @@ int iio_device_register(struct iio_dev *dev_info) ...@@ -788,7 +787,7 @@ int iio_device_register(struct iio_dev *dev_info)
iio_device_unregister_sysfs(dev_info); iio_device_unregister_sysfs(dev_info);
error_del_device: error_del_device:
device_del(&dev_info->dev); device_del(&dev_info->dev);
error_free_idr: error_free_ida:
iio_device_unregister_id(dev_info); iio_device_unregister_id(dev_info);
error_ret: error_ret:
return ret; return ret;
......
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