From: Jonathan Cameron <jic23@kernel.org>
To: Arnav Kapoor <kapoorarnav43@gmail.com>
Cc: "David Lechner" <dlechner@baylibre.com>,
"Nuno Sá" <nuno.sa@analog.com>,
"Andy Shevchenko" <andy@kernel.org>,
"Andy Shevchenko" <andriy.shevchenko@intel.com>,
"Gwendal Grignou" <gwendal@chromium.org>,
"Stephen Boyd" <swboyd@chromium.org>,
linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v3 3/6] iio: proximity: sx9324: reject negative hysteresis values
Date: Mon, 30 Nov 2026 00:39:45 +0000 [thread overview]
Message-ID: <20261130003945.0afa767e@jic23-hlaptop> (raw)
In-Reply-To: <20261128115534.558478-4-kapoorarnav43@gmail.com>
On Sat, 28 Nov 2026 17:24:51 +0530
Arnav Kapoor <kapoorarnav43@gmail.com> wrote:
> sx9324_write_hysteresis() copies the value into an unsigned int before
> comparing it with the threshold, so a negative value becomes a large
> one, passes the "val >= pthresh >> 2" check and sets the largest
> hysteresis instead of being rejected. The comparison is done in
> unsigned int, so this happens on both 32-bit and 64-bit architectures.
>
> Return -EINVAL for negative values, before converting them.
>
> Fixes: 4c18a890dff8 ("iio:proximity:sx9324: Add SX9324 support")
> Signed-off-by: Arnav Kapoor <kapoorarnav43@gmail.com>
Related to this, I don't see anything checking val2 at the caller of
this function. Should probably also reject val2 != 0 to avoid
odd things like -0.999999 being accepted as meaning 0.
This is an unrelated fix though so doesn't need to be in this patch.
> ---
> drivers/iio/proximity/sx9324.c | 7 ++++++-
> 1 file changed, 6 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/iio/proximity/sx9324.c b/drivers/iio/proximity/sx9324.c
> index 3f2f15d237e9..ef217f055472 100644
> --- a/drivers/iio/proximity/sx9324.c
> +++ b/drivers/iio/proximity/sx9324.c
> @@ -646,9 +646,14 @@ static int sx9324_write_thresh(struct sx_common_data *data,
> static int sx9324_write_hysteresis(struct sx_common_data *data,
> const struct iio_chan_spec *chan, int _val)
> {
> - unsigned int hyst, val = _val;
> + unsigned int hyst, val;
> int ret, pthresh;
>
> + if (_val < 0)
> + return -EINVAL;
> +
> + val = _val;
> +
> ret = sx9324_read_thresh(data, chan, &pthresh);
> if (ret < 0)
> return ret;
next prev parent reply other threads:[~2026-11-30 0:39 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-28 11:54 [PATCH v3 0/6] iio: proximity: sx93xx: fix raw reads, thresholds, hysteresis and gain Arnav Kapoor
2026-11-28 11:54 ` [PATCH v3 1/6] iio: proximity: sx_common: fix raw reads while the trigger is in use Arnav Kapoor
2026-11-28 11:54 ` [PATCH v3 2/6] iio: proximity: sx9324: fix proximity threshold writes Arnav Kapoor
2026-11-28 11:54 ` [PATCH v3 3/6] iio: proximity: sx9324: reject negative hysteresis values Arnav Kapoor
2026-11-30 0:39 ` Jonathan Cameron [this message]
2026-11-28 11:54 ` [PATCH v3 4/6] iio: proximity: sx9360: fix hardware gain encoding Arnav Kapoor
2026-11-28 11:54 ` [PATCH v3 5/6] iio: proximity: sx9360: fix proximity threshold writes Arnav Kapoor
2026-11-28 11:54 ` [PATCH v3 6/6] iio: proximity: sx9360: reject negative hysteresis values Arnav Kapoor
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=20261130003945.0afa767e@jic23-hlaptop \
--to=jic23@kernel.org \
--cc=andriy.shevchenko@intel.com \
--cc=andy@kernel.org \
--cc=dlechner@baylibre.com \
--cc=gwendal@chromium.org \
--cc=kapoorarnav43@gmail.com \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=nuno.sa@analog.com \
--cc=swboyd@chromium.org \
/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®