iio: core: Fix double free.
authorMartin Fuzzey <mfuzzey@parkeon.com>
Thu, 19 Feb 2015 14:17:44 +0000 (15:17 +0100)
committerBen Hutchings <ben@decadent.org.uk>
Sat, 9 May 2015 22:16:31 +0000 (23:16 +0100)
commit073bfbba54f94f1a9d3f20d5e07d830efe8f8f3a
tree884a061b51af1db31124eb2dc60655ba5a0ed560
parent1e6775d3670d51f2f50b5fb38ea1facbe1768061
iio: core: Fix double free.

commit c1b03ab5e886760bdd38c9c7a27af149046ffe01 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: Martin Fuzzey <mfuzzey@parkeon.com>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
[bwh: Backported to 3.2:
 - Adjust filenames, context
 - Drop inapplicable change to iio_free_chan_devattr_list()]
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
drivers/staging/iio/industrialio-core.c