Skip to contentSkip to conversation

FAILED: patch "[PATCH] iio: adc: ad4030: fix invalid oversampling_ratio validation" failed to apply to 6.18-stable tree

PATCH New [email protected] 2 participants 4 messages Oct 6 – Oct 7

Subsystems (4)
lore
Share & tools
lore

[email protected]

author maintainer
#0 lore raw

The patch below does not apply to the 6.18-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.

To reproduce the conflict and resubmit, you may use the following commands:

git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-6.18.y
git checkout FETCH_HEAD
git cherry-pick -x d615210564205993e8f0e7ccb57cc2e66b7d5706
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '2026100606-wolf-obsessed-e5c2@gregkh' --subject-prefix 'PATCH 6.18.y' 'HEAD^..'

Possible dependencies:

thanks,

greg k-h

------------------ original commit in Linus's tree ------------------

From d615210564205993e8f0e7ccb57cc2e66b7d5706 Mon Sep 17 00:00:00 2001
From: Salah Triki <[email protected]>
Date: Thu, 3 Sep 2026 12:43:09 +0100
Subject: [PATCH] iio: adc: ad4030: fix invalid oversampling_ratio validation

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
drivers/iio/adc/ad4030.c +9 -2
index e97400a1aa48..877b06007396 100644
@@ -746,14 +746,21 @@ 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 freq_hz;
 	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);
+
 	if (st->offload_trigger) {
 		/*
 		 * The sample averaging and sampling frequency configurations
maintainer
#1 lore raw

PATCH 1/3 units: Add HZ_PER_GHZ

From: Andy Shevchenko <[email protected]>

[ Upstream commit 5083dba0fde5446c00ee1a82a3911c8f88a2c72e ]

The is going to be a new user of the HZ_PER_GHZ definition besides possibly existing ones. Add that one to the header.

While at it, split Hz and kHz groups of the multipliers for better maintenance and readability.

Stable-dep-of: d61521056420 ("iio: adc: ad4030: fix invalid oversampling_ratio validation")

---
 include/linux/units.h | 3 +++
 1 file changed, 3 insertions(+)
include/linux/units.h +3 -0
index 00e15de33eca2..0c296a004e897 100644
@@ -25,9 +25,12 @@
 #define MICROHZ_PER_HZ		1000000UL
 #define MILLIHZ_PER_HZ		1000UL
 
+/* Hz based multipliers */
 #define HZ_PER_KHZ		1000UL
 #define HZ_PER_MHZ		1000000UL
+#define HZ_PER_GHZ		1000000000UL
 
+/* kHz based multipliers */
 #define KHZ_PER_MHZ		1000UL
 #define KHZ_PER_GHZ		1000000UL
 
Signature · 1 line
2.53.0
maintainer
#2 lore raw

PATCH 2/3 iio: adc: ad4030: Use BIT macro to improve code readability

From: Marcelo Schmitt <[email protected]>

[ Upstream commit a10f6dd4eef2e64fe1f366613bed45aa308494de ]

Use BIT macro to make the list of average modes more readable.

Stable-dep-of: d61521056420 ("iio: adc: ad4030: fix invalid oversampling_ratio validation")

---
 drivers/iio/adc/ad4030.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)
drivers/iio/adc/ad4030.c +9 -3
index d8bee6a4215a3..aec95aceb81fa 100644
@@ -232,10 +232,16 @@ struct ad4030_state {
 	.num_ext_scan_type = ARRAY_SIZE(_scan_type),			\
 }
 
+/*
+ * AD4030 can average over 2^N samples, where N = 1, 2, 3, ..., 16.
+ * We use N = 0 to mean no sample averaging.
+ */
 static const int ad4030_average_modes[] = {
-	1, 2, 4, 8, 16, 32, 64, 128,
-	256, 512, 1024, 2048, 4096, 8192, 16384, 32768,
-	65536,
+	BIT(0),					/* No sampling average */
+	BIT(1), BIT(2), BIT(3), BIT(4),
+	BIT(5), BIT(6), BIT(7), BIT(8),
+	BIT(9), BIT(10), BIT(11), BIT(12),
+	BIT(13), BIT(14), BIT(15), BIT(16),
 };
 
 static int ad4030_enter_config_mode(struct ad4030_state *st)
Signature · 1 line
2.53.0
maintainer
#3 lore raw

PATCH 3/3 iio: adc: ad4030: fix invalid oversampling_ratio validation

In reply to Sasha Levin

From: Salah Triki <[email protected]>

[ 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
[ sashal: Adjusted context for the missing SPI offload code. ]
---
 drivers/iio/adc/ad4030.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)
drivers/iio/adc/ad4030.c +9 -2
index aec95aceb81fa..b7cb589168c3b 100644
@@ -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));
Signature · 1 line
2.53.0