Commit 073bfbba authored by Martin Fuzzey's avatar Martin Fuzzey Committed by Ben Hutchings

iio: core: Fix double free.

commit c1b03ab5 upstream.

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
	78b33216 iio:core: Handle error when mask type is not separate
Signed-off-by: default avatarMartin Fuzzey <mfuzzey@parkeon.com>
Signed-off-by: default avatarJonathan Cameron <jic23@kernel.org>
[bwh: Backported to 3.2:
 - Adjust filenames, context
 - Drop inapplicable change to iio_free_chan_devattr_list()]
Signed-off-by: default avatarBen Hutchings <ben@decadent.org.uk>
parent 1e6775d3
...@@ -711,6 +711,7 @@ static void iio_device_unregister_sysfs(struct iio_dev *indio_dev) ...@@ -711,6 +711,7 @@ static void iio_device_unregister_sysfs(struct iio_dev *indio_dev)
iio_device_remove_and_free_read_attr(indio_dev, p); iio_device_remove_and_free_read_attr(indio_dev, p);
} }
kfree(indio_dev->chan_attr_group.attrs); kfree(indio_dev->chan_attr_group.attrs);
indio_dev->chan_attr_group.attrs = NULL;
} }
static const char * const iio_ev_type_text[] = { static const char * const iio_ev_type_text[] = {
...@@ -986,6 +987,7 @@ static int iio_device_register_eventset(struct iio_dev *indio_dev) ...@@ -986,6 +987,7 @@ static int iio_device_register_eventset(struct iio_dev *indio_dev)
error_free_setup_event_lines: error_free_setup_event_lines:
__iio_remove_event_config_attrs(indio_dev); __iio_remove_event_config_attrs(indio_dev);
kfree(indio_dev->event_interface); kfree(indio_dev->event_interface);
indio_dev->event_interface = NULL;
error_ret: error_ret:
return ret; return ret;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment