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>
This commit is contained in:
parent
619c7e60ff
commit
cc9fb60eaf
1 changed files with 18 additions and 9 deletions
|
@ -24,6 +24,21 @@ struct iio_map_internal {
|
||||||
static LIST_HEAD(iio_map_list);
|
static LIST_HEAD(iio_map_list);
|
||||||
static DEFINE_MUTEX(iio_map_list_lock);
|
static DEFINE_MUTEX(iio_map_list_lock);
|
||||||
|
|
||||||
|
static int iio_map_array_unregister_locked(struct iio_dev *indio_dev)
|
||||||
|
{
|
||||||
|
int ret = -ENODEV;
|
||||||
|
struct iio_map_internal *mapi, *next;
|
||||||
|
|
||||||
|
list_for_each_entry_safe(mapi, next, &iio_map_list, l) {
|
||||||
|
if (indio_dev == mapi->indio_dev) {
|
||||||
|
list_del(&mapi->l);
|
||||||
|
kfree(mapi);
|
||||||
|
ret = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
int iio_map_array_register(struct iio_dev *indio_dev, struct iio_map *maps)
|
int iio_map_array_register(struct iio_dev *indio_dev, struct iio_map *maps)
|
||||||
{
|
{
|
||||||
int i = 0, ret = 0;
|
int i = 0, ret = 0;
|
||||||
|
@ -57,18 +72,12 @@ EXPORT_SYMBOL_GPL(iio_map_array_register);
|
||||||
*/
|
*/
|
||||||
int iio_map_array_unregister(struct iio_dev *indio_dev)
|
int iio_map_array_unregister(struct iio_dev *indio_dev)
|
||||||
{
|
{
|
||||||
int ret = -ENODEV;
|
int ret;
|
||||||
struct iio_map_internal *mapi, *next;
|
|
||||||
|
|
||||||
mutex_lock(&iio_map_list_lock);
|
mutex_lock(&iio_map_list_lock);
|
||||||
list_for_each_entry_safe(mapi, next, &iio_map_list, l) {
|
ret = iio_map_array_unregister_locked(indio_dev);
|
||||||
if (indio_dev == mapi->indio_dev) {
|
|
||||||
list_del(&mapi->l);
|
|
||||||
kfree(mapi);
|
|
||||||
ret = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
mutex_unlock(&iio_map_list_lock);
|
mutex_unlock(&iio_map_list_lock);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL_GPL(iio_map_array_unregister);
|
EXPORT_SYMBOL_GPL(iio_map_array_unregister);
|
||||||
|
|
Loading…
Add table
Reference in a new issue