Skip to content

Commit 5210af7

Browse files
andy-shevgregkh
authored andcommitted
iio: core: add missing mutex_destroy in iio_dev_release()
[ Upstream commit f5d2034 ] Add missing mutex_destroy() call in iio_dev_release() to properly clean up the mutex initialized in iio_device_alloc(). Ensure proper resource cleanup and follows kernel practices. Found by code review. While at it, create a lockdep key before mutex initialisation. This will help with converting it to the better API in the future. Fixes: 847ec80 ("Staging: IIO: core support for device registration and management") Fixes: ac917a8 ("staging:iio:core set the iio_dev.info pointer to null on unregister under lock.") Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Reviewed-by: Nuno Sá <nuno.sa@analog.com> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com> Stable-dep-of: 9910159 ("iio: core: add separate lockdep class for info_exist_lock") Signed-off-by: Sasha Levin <sashal@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 5c9737b commit 5210af7

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

drivers/iio/industrialio-core.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1628,6 +1628,9 @@ static void iio_dev_release(struct device *device)
16281628

16291629
iio_device_detach_buffers(indio_dev);
16301630

1631+
mutex_destroy(&iio_dev_opaque->info_exist_lock);
1632+
mutex_destroy(&iio_dev_opaque->mlock);
1633+
16311634
lockdep_unregister_key(&iio_dev_opaque->mlock_key);
16321635

16331636
ida_free(&iio_ida, iio_dev_opaque->id);
@@ -1672,8 +1675,7 @@ struct iio_dev *iio_device_alloc(struct device *parent, int sizeof_priv)
16721675
indio_dev->dev.type = &iio_device_type;
16731676
indio_dev->dev.bus = &iio_bus_type;
16741677
device_initialize(&indio_dev->dev);
1675-
mutex_init(&iio_dev_opaque->mlock);
1676-
mutex_init(&iio_dev_opaque->info_exist_lock);
1678+
16771679
INIT_LIST_HEAD(&iio_dev_opaque->channel_attr_list);
16781680

16791681
iio_dev_opaque->id = ida_alloc(&iio_ida, GFP_KERNEL);
@@ -1696,6 +1698,9 @@ struct iio_dev *iio_device_alloc(struct device *parent, int sizeof_priv)
16961698
lockdep_register_key(&iio_dev_opaque->mlock_key);
16971699
lockdep_set_class(&iio_dev_opaque->mlock, &iio_dev_opaque->mlock_key);
16981700

1701+
mutex_init(&iio_dev_opaque->mlock);
1702+
mutex_init(&iio_dev_opaque->info_exist_lock);
1703+
16991704
return indio_dev;
17001705
}
17011706
EXPORT_SYMBOL(iio_device_alloc);

0 commit comments

Comments
 (0)