Linux IIO development
 help / color / mirror / Atom feed
* [PATCH 1/2] iio: mma8452: Fix trigger reference couting
@ 2021-10-24  9:26 Lars-Peter Clausen
  2021-10-24  9:27 ` [PATCH 2/2] iio: trigger: Fix reference counting Lars-Peter Clausen
  2021-10-28 14:07 ` [PATCH 1/2] iio: mma8452: Fix trigger reference couting Jonathan Cameron
  0 siblings, 2 replies; 11+ messages in thread
From: Lars-Peter Clausen @ 2021-10-24  9:26 UTC (permalink / raw)
  To: Jonathan Cameron
  Cc: Martin Fuzzey, Peter Meerwald-Stadler, linux-iio,
	Lars-Peter Clausen

The mma8452 driver directly assigns a trigger to the struct iio_dev. The
IIO core when done using this trigger will call `iio_trigger_put()` to drop
the reference count by 1.

Without the matching `iio_trigger_get()` in the driver the reference count
can reach 0 too early, the trigger gets freed while still in use and a
use-after-free occurs.

Fix this by getting a reference to the trigger before assigning it to the
IIO device.

Fixes: ae6d9ce05691 ("iio: mma8452: Add support for interrupt driven triggers.")
Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
---
 drivers/iio/accel/mma8452.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/iio/accel/mma8452.c b/drivers/iio/accel/mma8452.c
index 715b8138fb71..09c7f10fefb6 100644
--- a/drivers/iio/accel/mma8452.c
+++ b/drivers/iio/accel/mma8452.c
@@ -1470,7 +1470,7 @@ static int mma8452_trigger_setup(struct iio_dev *indio_dev)
 	if (ret)
 		return ret;
 
-	indio_dev->trig = trig;
+	indio_dev->trig = iio_trigger_get(trig);
 
 	return 0;
 }
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2021-10-30 17:04 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-10-24  9:26 [PATCH 1/2] iio: mma8452: Fix trigger reference couting Lars-Peter Clausen
2021-10-24  9:27 ` [PATCH 2/2] iio: trigger: Fix reference counting Lars-Peter Clausen
2021-10-25 10:55   ` Sa, Nuno
2021-10-28 14:16   ` Jonathan Cameron
2021-10-28 16:04     ` Lars-Peter Clausen
2021-10-28 16:12       ` Jonathan Cameron
2021-10-28 14:07 ` [PATCH 1/2] iio: mma8452: Fix trigger reference couting Jonathan Cameron
2021-10-28 19:52   ` Lars-Peter Clausen
2021-10-30 15:03     ` Jonathan Cameron
2021-10-30 15:12       ` Lars-Peter Clausen
2021-10-30 17:08         ` Jonathan Cameron

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox