Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

iio:core: Introduce unlocked version of iio_map_array_unregister()

Introduce an unlocked version of iio_map_array_unregister(). This function
can help to unwind in case of error while the iio_map_list_lock mutex is
held.

Signed-off-by: Lino Sanfilippo <LinoSanfilippo@gmx.de>
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Link: https://lore.kernel.org/r/1606571059-13974-1-git-send-email-LinoSanfilippo@gmx.de
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

authored by

Lino Sanfilippo and committed by
Jonathan Cameron
cc9fb60e 619c7e60

+18 -9
+18 -9
drivers/iio/inkern.c
··· 24 24 static LIST_HEAD(iio_map_list); 25 25 static DEFINE_MUTEX(iio_map_list_lock); 26 26 27 + static int iio_map_array_unregister_locked(struct iio_dev *indio_dev) 28 + { 29 + int ret = -ENODEV; 30 + struct iio_map_internal *mapi, *next; 31 + 32 + list_for_each_entry_safe(mapi, next, &iio_map_list, l) { 33 + if (indio_dev == mapi->indio_dev) { 34 + list_del(&mapi->l); 35 + kfree(mapi); 36 + ret = 0; 37 + } 38 + } 39 + return ret; 40 + } 41 + 27 42 int iio_map_array_register(struct iio_dev *indio_dev, struct iio_map *maps) 28 43 { 29 44 int i = 0, ret = 0; ··· 72 57 */ 73 58 int iio_map_array_unregister(struct iio_dev *indio_dev) 74 59 { 75 - int ret = -ENODEV; 76 - struct iio_map_internal *mapi, *next; 60 + int ret; 77 61 78 62 mutex_lock(&iio_map_list_lock); 79 - list_for_each_entry_safe(mapi, next, &iio_map_list, l) { 80 - if (indio_dev == mapi->indio_dev) { 81 - list_del(&mapi->l); 82 - kfree(mapi); 83 - ret = 0; 84 - } 85 - } 63 + ret = iio_map_array_unregister_locked(indio_dev); 86 64 mutex_unlock(&iio_map_list_lock); 65 + 87 66 return ret; 88 67 } 89 68 EXPORT_SYMBOL_GPL(iio_map_array_unregister);