From: Sasha Levin <sashal@kernel.org>
To: stable@vger.kernel.org
Cc: Salah Triki <salah.triki@gmail.com>,
Andy Shevchenko <andriy.shevchenko@intel.com>,
Jonathan Cameron <jonathan.cameron@oss.qualcomm.com>,
Sasha Levin <sashal@kernel.org>
Subject: [PATCH 6.18.y 3/3] iio: adc: ad4030: fix invalid oversampling_ratio validation
Date: Wed, 7 Oct 2026 02:10:43 -0400 [thread overview]
Message-ID: <20261007060913.1488382-3-sashal@kernel.org> (raw)
In-Reply-To: <20261007060913.1488382-1-sashal@kernel.org>
From: Salah Triki <salah.triki@gmail.com>
[ Upstream commit d615210564205993e8f0e7ccb57cc2e66b7d5706 ]
In ad4030_set_avg_frame_len(), the logarithm is calculated before input
validation. Passing zero or negative values leads to an undefined result
from ilog2().
Validate that the input is strictly positive prior to computing its
logarithm.
Fixes: 949abd1ca5a4 ("iio: adc: ad4030: add averaging support")
Assisted-by: LLM
Signed-off-by: Salah Triki <salah.triki@gmail.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@intel.com>
Cc: stable@vger.kernel.org
Signed-off-by: Jonathan Cameron <jonathan.cameron@oss.qualcomm.com>
[ sashal: Adjusted context for the missing SPI offload code. ]
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
drivers/iio/adc/ad4030.c | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/drivers/iio/adc/ad4030.c b/drivers/iio/adc/ad4030.c
index aec95aceb81fa..b7cb589168c3b 100644
--- a/drivers/iio/adc/ad4030.c
+++ b/drivers/iio/adc/ad4030.c
@@ -514,13 +514,20 @@ static int ad4030_set_chan_calibbias(struct iio_dev *indio_dev,
static int ad4030_set_avg_frame_len(struct iio_dev *dev, int avg_val)
{
struct ad4030_state *st = iio_priv(dev);
- unsigned int avg_log2 = ilog2(avg_val);
unsigned int last_avg_idx = ARRAY_SIZE(ad4030_average_modes) - 1;
+ unsigned int avg_log2;
int ret;
- if (avg_val < 0 || avg_val > ad4030_average_modes[last_avg_idx])
+ /* Reject unsupported modes */
+ if (avg_val > ad4030_average_modes[last_avg_idx])
+ return -EINVAL;
+
+ /* Avoid invalid values for logarithm since it's undefined */
+ if (avg_val < 1)
return -EINVAL;
+ avg_log2 = ilog2(avg_val);
+
ret = regmap_write(st->regmap, AD4030_REG_AVG,
AD4030_REG_AVG_MASK_AVG_SYNC |
FIELD_PREP(AD4030_REG_AVG_MASK_AVG_VAL, avg_log2));
--
2.53.0
prev parent reply other threads:[~2026-10-07 6:10 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-06 7:43 FAILED: patch "[PATCH] iio: adc: ad4030: fix invalid oversampling_ratio validation" failed to apply to 6.18-stable tree gregkh
2026-10-07 6:10 ` [PATCH 6.18.y 1/3] units: Add HZ_PER_GHZ Sasha Levin
2026-10-07 6:10 ` [PATCH 6.18.y 2/3] iio: adc: ad4030: Use BIT macro to improve code readability Sasha Levin
2026-10-07 6:10 ` Sasha Levin [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=20261007060913.1488382-3-sashal@kernel.org \
--to=sashal@kernel.org \
--cc=andriy.shevchenko@intel.com \
--cc=jonathan.cameron@oss.qualcomm.com \
--cc=salah.triki@gmail.com \
--cc=stable@vger.kernel.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