mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-10-02 23:27:06 +00:00
iio: core: Fix double free.
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: Martin Fuzzey <mfuzzey@parkeon.com>
Cc: <Stable@vger.kernel.org>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
This commit is contained in:
parent
af5e1a6831
commit
c1b03ab5e8
2 changed files with 4 additions and 2 deletions
|
@ -847,8 +847,7 @@ static int iio_device_add_channel_sysfs(struct iio_dev *indio_dev,
|
||||||
* @attr_list: List of IIO device attributes
|
* @attr_list: List of IIO device attributes
|
||||||
*
|
*
|
||||||
* This function frees the memory allocated for each of the IIO device
|
* This function frees the memory allocated for each of the IIO device
|
||||||
* attributes in the list. Note: if you want to reuse the list after calling
|
* attributes in the list.
|
||||||
* this function you have to reinitialize it using INIT_LIST_HEAD().
|
|
||||||
*/
|
*/
|
||||||
void iio_free_chan_devattr_list(struct list_head *attr_list)
|
void iio_free_chan_devattr_list(struct list_head *attr_list)
|
||||||
{
|
{
|
||||||
|
@ -856,6 +855,7 @@ void iio_free_chan_devattr_list(struct list_head *attr_list)
|
||||||
|
|
||||||
list_for_each_entry_safe(p, n, attr_list, l) {
|
list_for_each_entry_safe(p, n, attr_list, l) {
|
||||||
kfree(p->dev_attr.attr.name);
|
kfree(p->dev_attr.attr.name);
|
||||||
|
list_del(&p->l);
|
||||||
kfree(p);
|
kfree(p);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -936,6 +936,7 @@ static void iio_device_unregister_sysfs(struct iio_dev *indio_dev)
|
||||||
|
|
||||||
iio_free_chan_devattr_list(&indio_dev->channel_attr_list);
|
iio_free_chan_devattr_list(&indio_dev->channel_attr_list);
|
||||||
kfree(indio_dev->chan_attr_group.attrs);
|
kfree(indio_dev->chan_attr_group.attrs);
|
||||||
|
indio_dev->chan_attr_group.attrs = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void iio_dev_release(struct device *device)
|
static void iio_dev_release(struct device *device)
|
||||||
|
|
|
@ -500,6 +500,7 @@ int iio_device_register_eventset(struct iio_dev *indio_dev)
|
||||||
error_free_setup_event_lines:
|
error_free_setup_event_lines:
|
||||||
iio_free_chan_devattr_list(&indio_dev->event_interface->dev_attr_list);
|
iio_free_chan_devattr_list(&indio_dev->event_interface->dev_attr_list);
|
||||||
kfree(indio_dev->event_interface);
|
kfree(indio_dev->event_interface);
|
||||||
|
indio_dev->event_interface = NULL;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue