Skip to content

Commit

Permalink
iio: core: fix ioctl handlers removal
Browse files Browse the repository at this point in the history
Currently ioctl handlers are removed twice. For the first time during
iio_device_unregister() then later on inside
iio_device_unregister_eventset() and iio_buffers_free_sysfs_and_mask().
Double free leads to kernel panic.

Fix this by not touching ioctl handlers list directly but rather
letting code responsible for registration call the matching cleanup
routine itself.

Fixes: 8dedcc3 ("iio: core: centralize ioctl() calls to the main chardev")
Signed-off-by: Tomasz Duszynski <tomasz.duszynski@octakon.com>
Acked-by: Alexandru Ardelean <ardeleanalex@gmail.com>
Cc: <Stable@vger.kernel.org>
Link: https://lore.kernel.org/r/20210423080244.2790-1-tomasz.duszynski@octakon.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
  • Loading branch information
Tomasz Duszynski authored and Jonathan Cameron committed May 10, 2021
1 parent f73c730 commit 901f84d
Showing 1 changed file with 0 additions and 6 deletions.
6 changes: 0 additions & 6 deletions drivers/iio/industrialio-core.c
Original file line number Diff line number Diff line change
Expand Up @@ -1926,9 +1926,6 @@ EXPORT_SYMBOL(__iio_device_register);
**/
void iio_device_unregister(struct iio_dev *indio_dev)
{
struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(indio_dev);
struct iio_ioctl_handler *h, *t;

cdev_device_del(&indio_dev->chrdev, &indio_dev->dev);

mutex_lock(&indio_dev->info_exist_lock);
Expand All @@ -1939,9 +1936,6 @@ void iio_device_unregister(struct iio_dev *indio_dev)

indio_dev->info = NULL;

list_for_each_entry_safe(h, t, &iio_dev_opaque->ioctl_handlers, entry)
list_del(&h->entry);

iio_device_wakeup_eventset(indio_dev);
iio_buffer_wakeup_poll(indio_dev);

Expand Down

0 comments on commit 901f84d

Please sign in to comment.