From: Fabrice Gasnier <fabrice.gasnier@foss.st.com>
To: "Jonathan Cameron" <jic23@kernel.org>,
"David Lechner" <dlechner@baylibre.com>,
"Nuno Sá" <nuno.sa@analog.com>,
"Andy Shevchenko" <andy@kernel.org>,
"Maxime Coquelin" <mcoquelin.stm32@gmail.com>,
"Alexandre Torgue" <alexandre.torgue@foss.st.com>,
"Olivier Moysan" <olivier.moysan@foss.st.com>,
"Fabrice Gasnier" <fabrice.gasnier@foss.st.com>
Cc: <linux-iio@vger.kernel.org>,
<linux-stm32@st-md-mailman.stormreply.com>,
<linux-arm-kernel@lists.infradead.org>,
<linux-kernel@vger.kernel.org>,
Jonathan Cameron <jic23@kernel.org>,
Sashiko <sashiko-bot@kernel.org>, <stable@vger.kernel.org>
Subject: [PATCH] iio: adc: stm32-adc: fix possible division by zero in processed channel
Date: Tue, 15 Sep 2026 18:10:40 +0200 [thread overview]
Message-ID: <20260915-adc-fix-div0-v1-1-7daed9e52f2f@foss.st.com> (raw)
In case the conversion has failed or returned zero, processing *val
can lead to a division by zero.
Need to check for errors, or converted value is zero, before processing
the data.
In case converted value is zero, e.g. the Vrefint channel, this should
be considered as invalid in all case.
Fixes: 0e346b2cfa85 ("iio: adc: stm32-adc: add vrefint calibration support")
Reported-by: Sashiko <sashiko-bot@kernel.org>
Link: https://lore.kernel.org/all/20260911161555.244F31F000FF@smtp.kernel.org/
Cc: stable@vger.kernel.org
Signed-off-by: Fabrice Gasnier <fabrice.gasnier@foss.st.com>
---
drivers/iio/adc/stm32-adc.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/drivers/iio/adc/stm32-adc.c b/drivers/iio/adc/stm32-adc.c
index 5c6c06b269be..d290c5a8f86d 100644
--- a/drivers/iio/adc/stm32-adc.c
+++ b/drivers/iio/adc/stm32-adc.c
@@ -1609,8 +1609,12 @@ static int stm32_adc_read_raw(struct iio_dev *indio_dev,
else
ret = -EINVAL;
- if (mask == IIO_CHAN_INFO_PROCESSED)
- *val = STM32_ADC_VREFINT_VOLTAGE * adc->vrefint.vrefint_cal / *val;
+ if (mask == IIO_CHAN_INFO_PROCESSED) {
+ if (ret >= 0 && *val)
+ *val = STM32_ADC_VREFINT_VOLTAGE * adc->vrefint.vrefint_cal / *val;
+ else
+ ret = ret < 0 ? ret : -EINVAL;
+ }
iio_device_release_direct(indio_dev);
return ret;
---
base-commit: 8d3ae59288f1e7d58d76558a6ee96d533bc5019f
change-id: 20260915-adc-fix-div0-ae38365abfeb
Best regards,
--
Fabrice Gasnier <fabrice.gasnier@foss.st.com>
next reply other threads:[~2026-09-15 16:11 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-15 16:10 Fabrice Gasnier [this message]
2026-09-16 7:35 ` [PATCH] iio: adc: stm32-adc: fix possible division by zero in processed channel Andy Shevchenko
2026-09-16 10:23 ` Fabrice Gasnier
2026-09-16 11:00 ` Andy Shevchenko
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=20260915-adc-fix-div0-v1-1-7daed9e52f2f@foss.st.com \
--to=fabrice.gasnier@foss.st.com \
--cc=alexandre.torgue@foss.st.com \
--cc=andy@kernel.org \
--cc=dlechner@baylibre.com \
--cc=jic23@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-stm32@st-md-mailman.stormreply.com \
--cc=mcoquelin.stm32@gmail.com \
--cc=nuno.sa@analog.com \
--cc=olivier.moysan@foss.st.com \
--cc=sashiko-bot@kernel.org \
--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