The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [PATCH] iio: imu: kmx61: Fix TOCTOU race condition
@ 2026-05-12 12:03 Maxwell Doose
  2026-05-12 15:17 ` Maxwell Doose
  2026-05-12 15:54 ` David Lechner
  0 siblings, 2 replies; 8+ messages in thread
From: Maxwell Doose @ 2026-05-12 12:03 UTC (permalink / raw)
  To: jic23
  Cc: David Lechner, Nuno Sá, Andy Shevchenko, Daniel Baluta,
	open list:IIO SUBSYSTEM AND DRIVERS, open list

A Time-of-check to Time-of-use race condition is present in
kmx61_write_event_config(). Move the mutex_lock() call above it to fix
it.

Fixes: fd3ae7a9f21c ("iio: imu: kmx61: Add support for any motion trigger")
Signed-off-by: Maxwell Doose <m32285159@gmail.com>
---
 drivers/iio/imu/kmx61.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/drivers/iio/imu/kmx61.c b/drivers/iio/imu/kmx61.c
index 3cd91d8a89ee..9aa00acc7f14 100644
--- a/drivers/iio/imu/kmx61.c
+++ b/drivers/iio/imu/kmx61.c
@@ -942,11 +942,13 @@ static int kmx61_write_event_config(struct iio_dev *indio_dev,
 	struct kmx61_data *data = kmx61_get_data(indio_dev);
 	int ret = 0;
 
-	if (state && data->ev_enable_state)
-		return 0;
-
 	mutex_lock(&data->lock);
 
+	if (state && data->ev_enable_state) {
+		ret = 0;
+		goto err_unlock;
+	}
+
 	if (!state && data->motion_trig_on) {
 		data->ev_enable_state = false;
 		goto err_unlock;
-- 
2.54.0


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

end of thread, other threads:[~2026-05-13 13:11 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-12 12:03 [PATCH] iio: imu: kmx61: Fix TOCTOU race condition Maxwell Doose
2026-05-12 15:17 ` Maxwell Doose
2026-05-12 15:24   ` Andy Shevchenko
2026-05-12 15:30     ` Maxwell Doose
2026-05-12 17:10       ` Jonathan Cameron
2026-05-12 17:37         ` Maxwell Doose
2026-05-13 13:11           ` Jonathan Cameron
2026-05-12 15:54 ` David Lechner

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