From 6cb2afd7c0abb93bd9dc6d36b858b1e312e2407d Mon Sep 17 00:00:00 2001 From: Guenter Roeck Date: Thu, 31 Jan 2013 21:43:00 +0000 Subject: iio: Simplify iio_map_array_unregister API Instead of requiring the map to unregister, simply unregister all map entries associated with the given iio device. This simplifies map removal and also works for maps generated through devicetree. Signed-off-by: Guenter Roeck Signed-off-by: Jonathan Cameron --- drivers/iio/inkern.c | 36 +++++++++++------------------------- 1 file changed, 11 insertions(+), 25 deletions(-) (limited to 'drivers/iio/inkern.c') diff --git a/drivers/iio/inkern.c b/drivers/iio/inkern.c index 58d0ffe856b6..c42aba6817e8 100644 --- a/drivers/iio/inkern.c +++ b/drivers/iio/inkern.c @@ -54,39 +54,25 @@ error_ret: EXPORT_SYMBOL_GPL(iio_map_array_register); -/* Assumes the exact same array (e.g. memory locations) - * used at unregistration as used at registration rather than - * more complex checking of contents. +/* + * Remove all map entries associated with the given iio device */ -int iio_map_array_unregister(struct iio_dev *indio_dev, - struct iio_map *maps) +int iio_map_array_unregister(struct iio_dev *indio_dev) { - int i = 0, ret = 0; - bool found_it; + int ret = -ENODEV; struct iio_map_internal *mapi; - - if (maps == NULL) - return 0; + struct list_head *pos, *tmp; mutex_lock(&iio_map_list_lock); - while (maps[i].consumer_dev_name != NULL) { - found_it = false; - list_for_each_entry(mapi, &iio_map_list, l) - if (&maps[i] == mapi->map) { - list_del(&mapi->l); - kfree(mapi); - found_it = true; - break; - } - if (!found_it) { - ret = -ENODEV; - goto error_ret; + list_for_each_safe(pos, tmp, &iio_map_list) { + mapi = list_entry(pos, struct iio_map_internal, l); + if (indio_dev == mapi->indio_dev) { + list_del(&mapi->l); + kfree(mapi); + ret = 0; } - i++; } -error_ret: mutex_unlock(&iio_map_list_lock); - return ret; } EXPORT_SYMBOL_GPL(iio_map_array_unregister); -- cgit v1.2.3