From: Maxwell Doose <m32285159@gmail.com>
To: jic23@kernel.org
Cc: "David Lechner" <dlechner@baylibre.com>,
"Nuno Sá" <nuno.sa@analog.com>,
"Andy Shevchenko" <andy@kernel.org>,
"Daniel Baluta" <daniel.baluta@intel.com>,
linux-iio@vger.kernel.org (open list:IIO SUBSYSTEM AND DRIVERS),
linux-kernel@vger.kernel.org (open list)
Subject: [PATCH] iio: imu: kmx61: Fix TOCTOU race condition
Date: Tue, 12 May 2026 07:03:55 -0500 [thread overview]
Message-ID: <20260512120356.40839-1-m32285159@gmail.com> (raw)
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
next reply other threads:[~2026-05-12 12:03 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-12 12:03 Maxwell Doose [this message]
2026-05-12 15:17 ` [PATCH] iio: imu: kmx61: Fix TOCTOU race condition 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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260512120356.40839-1-m32285159@gmail.com \
--to=m32285159@gmail.com \
--cc=andy@kernel.org \
--cc=daniel.baluta@intel.com \
--cc=dlechner@baylibre.com \
--cc=jic23@kernel.org \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=nuno.sa@analog.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.