Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 267538
b: refs/heads/master
c: 9aa1a16
h: refs/heads/master
v: v3
  • Loading branch information
Jonathan Cameron authored and Greg Kroah-Hartman committed Aug 23, 2011
1 parent 615e5ae commit 8598615
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 71 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 232b9cba130025d47531c5c539d6affc64950213
refs/heads/master: 9aa1a167f0b8d6a58fe012992fd801bd78bf91f1
4 changes: 0 additions & 4 deletions trunk/drivers/staging/iio/iio.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_ */
108 changes: 42 additions & 66 deletions trunk/drivers/staging/iio/industrialio-core.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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;
Expand All @@ -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;

Expand All @@ -374,7 +379,8 @@ static int __init iio_init(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);
}

Expand Down Expand Up @@ -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",
Expand Down

0 comments on commit 8598615

Please sign in to comment.