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>,
"Yasin Lee" <yasin.lee.x@gmail.com>,
linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org,
"Arnav Kapoor" <kapoorarnav43@gmail.com>
Subject: [PATCH 5/5] iio: proximity: hx9023s: reject out-of-range debounce values
Date: Mon, 23 Nov 2026 22:22:51 +0530 [thread overview]
Message-ID: <20261123165255.239490-6-kapoorarnav43@gmail.com> (raw)
In-Reply-To: <20261123165255.239490-1-kapoorarnav43@gmail.com>
The near and far debounce counts are 4-bit fields.
hx9023s_write_far_debounce() and hx9023s_write_near_debounce() pass the
value through FIELD_GET(), which only masks it here because the field
starts at bit 0, so an out-of-range value is silently written as a
different one: 16 becomes 0 (no debounce) and -1 becomes 15.
Return -EINVAL for values outside 0..15, and use FIELD_PREP(), which is
the right helper for building a register value.
Fixes: 60df548277b7 ("iio: proximity: Add driver support for TYHX's HX9023S capacitive proximity sensor")
Signed-off-by: Arnav Kapoor <kapoorarnav43@gmail.com>
---
drivers/iio/proximity/hx9023s.c | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/drivers/iio/proximity/hx9023s.c b/drivers/iio/proximity/hx9023s.c
index 1545b4ed2ead..906fd4baa468 100644
--- a/drivers/iio/proximity/hx9023s.c
+++ b/drivers/iio/proximity/hx9023s.c
@@ -359,18 +359,24 @@ static int hx9023s_ch_cfg(struct hx9023s_data *data)
static int hx9023s_write_far_debounce(struct hx9023s_data *data, int val)
{
+ if (val < 0 || val > FIELD_MAX(HX9023S_PROX_DEBOUNCE_MASK))
+ return -EINVAL;
+
guard(mutex)(&data->mutex);
return regmap_update_bits(data->regmap, HX9023S_PROX_INT_LOW_CFG,
HX9023S_PROX_DEBOUNCE_MASK,
- FIELD_GET(HX9023S_PROX_DEBOUNCE_MASK, val));
+ FIELD_PREP(HX9023S_PROX_DEBOUNCE_MASK, val));
}
static int hx9023s_write_near_debounce(struct hx9023s_data *data, int val)
{
+ if (val < 0 || val > FIELD_MAX(HX9023S_PROX_DEBOUNCE_MASK))
+ return -EINVAL;
+
guard(mutex)(&data->mutex);
return regmap_update_bits(data->regmap, HX9023S_PROX_INT_HIGH_CFG,
HX9023S_PROX_DEBOUNCE_MASK,
- FIELD_GET(HX9023S_PROX_DEBOUNCE_MASK, val));
+ FIELD_PREP(HX9023S_PROX_DEBOUNCE_MASK, val));
}
static int hx9023s_read_far_debounce(struct hx9023s_data *data, int *val)
--
2.53.0
prev parent reply other threads:[~2026-11-23 16:53 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-23 16:52 [PATCH 0/5] iio: proximity: hx9023s: fix sampling frequency, resume and event value handling Arnav Kapoor
2026-11-23 16:52 ` [PATCH 1/5] iio: proximity: hx9023s: fix division by zero in set_samp_freq Arnav Kapoor
2026-11-23 19:14 ` Andy Shevchenko
2026-11-23 16:52 ` [PATCH 2/5] iio: proximity: hx9023s: check the sampling frequency index Arnav Kapoor
2026-11-23 19:15 ` Andy Shevchenko
2026-11-23 16:52 ` [PATCH 3/5] iio: proximity: hx9023s: re-enable interrupts on resume for events Arnav Kapoor
2026-11-23 16:52 ` [PATCH 4/5] iio: proximity: hx9023s: reject out-of-range threshold values Arnav Kapoor
2026-11-23 19:26 ` Andy Shevchenko
2026-11-23 16:52 ` 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=20261123165255.239490-6-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=yasin.lee.x@gmail.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®