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>,
"Gwendal Grignou" <gwendal@chromium.org>,
"Stephen Boyd" <swboyd@chromium.org>,
linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org,
"Arnav Kapoor" <kapoorarnav43@gmail.com>
Subject: [PATCH] iio: proximity: sx9324: reject reserved gain values on read
Date: Wed, 4 Nov 2026 23:29:18 +0530 [thread overview]
Message-ID: <20261104175920.207384-1-kapoorarnav43@gmail.com> (raw)
sx9324_read_gain() is meant to return -EINVAL for the reserved
PROX_CTRL0 gain codes, 0 and 5 to 7. But the range check sits in the
else branch of "if (regval)", where regval is always 0, so codes 5 to 7
are never caught and are reported as gains of 16, 32 and 64, which the
sensor doesn't support and which write_raw() rejects.
Check both reserved ranges before converting the code to a gain.
Fixes: 108e4d4de2b5 ("iio:proximity:sx9324: Fix hardware gain read/write")
Signed-off-by: Arnav Kapoor <kapoorarnav43@gmail.com>
---
Compile-tested only (W=1); I don't have SX9324 hardware.
drivers/iio/proximity/sx9324.c | 8 +++-----
1 file changed, 3 insertions(+), 5 deletions(-)
diff --git a/drivers/iio/proximity/sx9324.c b/drivers/iio/proximity/sx9324.c
index 1c8ba28c030a..95e7315314f8 100644
--- a/drivers/iio/proximity/sx9324.c
+++ b/drivers/iio/proximity/sx9324.c
@@ -404,13 +404,11 @@ static int sx9324_read_gain(struct sx_common_data *data,
return ret;
regval = FIELD_GET(SX9324_REG_PROX_CTRL0_GAIN_MASK, regval);
- if (regval)
- regval--;
- else if (regval == SX9324_REG_PROX_CTRL0_GAIN_RSVD ||
- regval > SX9324_REG_PROX_CTRL0_GAIN_8)
+ if (regval == SX9324_REG_PROX_CTRL0_GAIN_RSVD ||
+ regval > SX9324_REG_PROX_CTRL0_GAIN_8)
return -EINVAL;
- *val = 1 << regval;
+ *val = 1 << (regval - 1);
return IIO_VAL_INT;
}
base-commit: 340d44bdf9db0f095f99845b5ad8628781d79b6f
--
2.53.0
reply other threads:[~2026-11-04 17:59 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20261104175920.207384-1-kapoorarnav43@gmail.com \
--to=kapoorarnav43@gmail.com \
--cc=andriy.shevchenko@intel.com \
--cc=andy@kernel.org \
--cc=dlechner@baylibre.com \
--cc=gwendal@chromium.org \
--cc=jic23@kernel.org \
--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®