From: Arnav Kapoor <kapoorarnav43@gmail.com>
To: Jonathan Cameron <jic23@kernel.org>
Cc: "David Lechner" <dlechner@baylibre.com>,
"Nuno Sá" <nuno.sa@analog.com>,
"Andy Shevchenko" <andy@kernel.org>,
"Andy Shevchenko" <andriy.shevchenko@intel.com>,
"Wang Shuaijie" <wangshuaijie@awinic.com>,
linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org,
"Arnav Kapoor" <kapoorarnav43@gmail.com>
Subject: [PATCH 4/4] iio: proximity: aw96103: reject out-of-range debounce and hysteresis values
Date: Thu, 26 Nov 2026 11:00:28 +0530 [thread overview]
Message-ID: <20261126053033.603086-5-kapoorarnav43@gmail.com> (raw)
In-Reply-To: <20261126053033.603086-1-kapoorarnav43@gmail.com>
The debounce (OUTDEB, INDEB) and hysteresis (THHYST) settings are 2-bit
fields of PROXCTRL. aw96103_write_event_val() passes the value through
FIELD_PREP() without checking it, which masks it to the field, so an
out-of-range value is silently written as a different one: 4 becomes 0
and -1 becomes 3.
Return -EINVAL for values outside 0..3. Both debounce fields have the
same width, so one check covers the two directions.
Fixes: 07b241262dca ("iio: proximity: aw96103: Add support for aw96103/aw96105 proximity sensor")
Signed-off-by: Arnav Kapoor <kapoorarnav43@gmail.com>
---
drivers/iio/proximity/aw96103.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/drivers/iio/proximity/aw96103.c b/drivers/iio/proximity/aw96103.c
index b4aa31a65369..24557a8f764d 100644
--- a/drivers/iio/proximity/aw96103.c
+++ b/drivers/iio/proximity/aw96103.c
@@ -401,6 +401,9 @@ static int aw96103_write_event_val(struct iio_dev *indio_dev,
return regmap_write(aw96103->regmap,
AW96103_REG_PROXTH0_CH(chan->channel), val);
case IIO_EV_INFO_PERIOD:
+ if (val < 0 || val > FIELD_MAX(AW96103_OUTDEB_MASK))
+ return -EINVAL;
+
switch (dir) {
case IIO_EV_DIR_RISING:
return regmap_update_bits(aw96103->regmap,
@@ -417,6 +420,9 @@ static int aw96103_write_event_val(struct iio_dev *indio_dev,
return -EINVAL;
}
case IIO_EV_INFO_HYSTERESIS:
+ if (val < 0 || val > FIELD_MAX(AW96103_THHYST_MASK))
+ return -EINVAL;
+
return regmap_update_bits(aw96103->regmap,
AW96103_REG_PROXCTRL_CH(chan->channel),
AW96103_THHYST_MASK,
--
2.53.0
prev parent reply other threads:[~2026-11-26 5:31 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-26 5:30 [PATCH 0/4] iio: proximity: aw96103: fix diff sign, missing config, async config lifetime and event values Arnav Kapoor
2026-11-26 5:30 ` [PATCH 1/4] iio: proximity: aw96103: report negative proximity diff values Arnav Kapoor
2026-11-26 5:30 ` [PATCH 2/4] iio: proximity: aw96103: use the default configuration without firmware Arnav Kapoor
2026-11-26 5:30 ` [PATCH 3/4] iio: proximity: aw96103: wait for the configuration load before freeing Arnav Kapoor
2026-11-26 5:30 ` Arnav Kapoor [this message]
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=20261126053033.603086-5-kapoorarnav43@gmail.com \
--to=kapoorarnav43@gmail.com \
--cc=andriy.shevchenko@intel.com \
--cc=andy@kernel.org \
--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 \
--cc=wangshuaijie@awinic.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®