Skip to content

Commit 42ec319

Browse files
Martin Fuzzeysashalevin
authored andcommitted
iio: core: Fix double free.
[ Upstream commit c1b03ab ] When an error occurred during event registration memory was freed twice resulting in kernel memory corruption and a crash in unrelated code. The problem was caused by iio_device_unregister_eventset() iio_device_unregister_sysfs() being called twice, once on the error path and then again via iio_dev_release(). Fix this by making these two functions idempotent so they may be called multiple times. The problem was observed before applying 78b3321 iio:core: Handle error when mask type is not separate Signed-off-by: Martin Fuzzey <mfuzzey@parkeon.com> Cc: <Stable@vger.kernel.org> Signed-off-by: Jonathan Cameron <jic23@kernel.org> Signed-off-by: Sasha Levin <sasha.levin@oracle.com>
1 parent 382fd03 commit 42ec319

2 files changed

Lines changed: 4 additions & 2 deletions

File tree

‎drivers/iio/industrialio-core.c‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -832,15 +832,15 @@ static int iio_device_add_channel_sysfs(struct iio_dev *indio_dev,
832832
* @attr_list: List of IIO device attributes
833833
*
834834
* This function frees the memory allocated for each of the IIO device
835-
* attributes in the list. Note: if you want to reuse the list after calling
836-
* this function you have to reinitialize it using INIT_LIST_HEAD().
835+
* attributes in the list.
837836
*/
838837
void iio_free_chan_devattr_list(struct list_head *attr_list)
839838
{
840839
struct iio_dev_attr *p, *n;
841840

842841
list_for_each_entry_safe(p, n, attr_list, l) {
843842
kfree(p->dev_attr.attr.name);
843+
list_del(&p->l);
844844
kfree(p);
845845
}
846846
}
@@ -921,6 +921,7 @@ static void iio_device_unregister_sysfs(struct iio_dev *indio_dev)
921921

922922
iio_free_chan_devattr_list(&indio_dev->channel_attr_list);
923923
kfree(indio_dev->chan_attr_group.attrs);
924+
indio_dev->chan_attr_group.attrs = NULL;
924925
}
925926

926927
static void iio_dev_release(struct device *device)

‎drivers/iio/industrialio-event.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -493,6 +493,7 @@ int iio_device_register_eventset(struct iio_dev *indio_dev)
493493
error_free_setup_event_lines:
494494
iio_free_chan_devattr_list(&indio_dev->event_interface->dev_attr_list);
495495
kfree(indio_dev->event_interface);
496+
indio_dev->event_interface = NULL;
496497
return ret;
497498
}
498499

0 commit comments

Comments
 (0)