Linux IIO development
 help / color / mirror / Atom feed
* [PATCH] iio: chemical: scd30: Prevent potential divide-by-zero error
@ 2026-05-09 21:19 Maxwell Doose
  2026-05-09 21:25 ` David Lechner
  0 siblings, 1 reply; 9+ messages in thread
From: Maxwell Doose @ 2026-05-09 21:19 UTC (permalink / raw)
  To: jic23
  Cc: Tomasz Duszynski, David Lechner, Nuno Sá, Andy Shevchenko,
	open list:IIO SUBSYSTEM AND DRIVERS, open list

In scd30_read_raw, the current value of tmp in the
IIO_CHAN_INFO_SAMP_FREQ case is unchecked. Add checking to see if the
value we got was 0 to prevent a divide-by-zero error.

Fixes: 64b3d8b1b0f5 ("iio: chemical: scd30: add core driver")
Signed-off-by: Maxwell Doose <m32285159@gmail.com>
---
 drivers/iio/chemical/scd30_core.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/drivers/iio/chemical/scd30_core.c b/drivers/iio/chemical/scd30_core.c
index be8c055be184..3e2bb6f4e42c 100644
--- a/drivers/iio/chemical/scd30_core.c
+++ b/drivers/iio/chemical/scd30_core.c
@@ -237,6 +237,13 @@ static int scd30_read_raw(struct iio_dev *indio_dev, struct iio_chan_spec const
 		if (ret)
 			return ret;
 
+		/* Likely only taken if something really strange happens */
+		if (!tmp) {
+			dev_err(&indio_dev->dev,
+				"Invalid measurement interval 0 received\n");
+			return -EIO;
+		}
+
 		*val = 0;
 		*val2 = 1000000000 / tmp;
 		return IIO_VAL_INT_PLUS_NANO;
-- 
2.54.0


^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2026-05-11 14:28 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-09 21:19 [PATCH] iio: chemical: scd30: Prevent potential divide-by-zero error Maxwell Doose
2026-05-09 21:25 ` David Lechner
2026-05-09 21:36   ` Maxwell Doose
2026-05-09 21:47     ` David Lechner
2026-05-09 21:53       ` Maxwell Doose
2026-05-10  0:47         ` Maxwell Doose
2026-05-11 12:03           ` Jonathan Cameron
2026-05-11 13:31             ` Andy Shevchenko
2026-05-11 14:27               ` Maxwell Doose

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox