Skip to contentSkip to conversation

iio: adc: qcom-spmi-adc5-gen3: Fix off by one in adc5_gen3_get_fw_channel_data()

PATCH In review Dan Carpenter 3 participants 3 messages Apr 10 – Apr 25

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 iio: adc: qcom-spmi-adc5-gen3: Fix off by one in adc5_gen3_get_fw_channel_data()

The > in "if (chan > ADC5_MAX_CHANNEL)" should be >= to prevent an out of bound read of the adc->data->adc_chans[] array.

Fixes baff45179e90 ("iio: adc: Add support for QCOM PMIC5 Gen3 ADC")

---
This email is a free service from the Smatch-CI project [smatch.sf.net].

 drivers/iio/adc/qcom-spmi-adc5-gen3.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iio/adc/qcom-spmi-adc5-gen3.c +1 -1
index f8168a14b907..48c793b18d11 100644
@@ -482,7 +482,7 @@ static int adc5_gen3_get_fw_channel_data(struct adc5_chip *adc,
 	sid = FIELD_GET(ADC5_GEN3_VIRTUAL_SID_MASK, chan);
 	chan = FIELD_GET(ADC5_GEN3_CHANNEL_MASK, chan);
 
-	if (chan > ADC5_MAX_CHANNEL)
+	if (chan >= ADC5_MAX_CHANNEL)
 		return dev_err_probe(dev, -EINVAL,
 				     "%s invalid channel number %d\n",
 				     name, chan);
Signature · 1 line
2.53.0
maintainer
#2 lore raw
Quoted 10 lines · On Fri, 10 Apr 2026 12:15:41 +0200 Konrad Dybcio…
Quoted 6 lines · Dan Carpenter

The > in "if (chan > ADC5_MAX_CHANNEL)" should be >= to prevent an out of bound read of the adc->data->adc_chans[] array.

Fixes baff45179e90 ("iio: adc: Add support for QCOM PMIC5 Gen3 ADC")

---

This was waiting on the char-misc pull requests going upstream so I could rebase my fixes branch. That's now happened, but I will rebase again on rc1 once available (as a pull request based mid merge window isn't the best plan!)

Anyhow applied to the fixes-togreg branch of iio.git.

Thanks,

Jonathan

Quoted 1 line

Konrad