Skip to contentSkip to conversation

iio: chemical: scd30: fix division by zero in write_raw

PATCH Applied Antoniu Miclaus 2 participants 2 messages Apr 1 – Apr 20

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

PATCH 1/1 iio: chemical: scd30: fix division by zero in write_raw

Add a zero check for val2 before using it as a divisor when setting the sampling frequency. A user writing a zero fractional part to the sampling_frequency sysfs attribute triggers a division by zero in the kernel.

Fixes 64b3d8b1b0f5 ("iio: chemical: scd30: add core driver")
---
 drivers/iio/chemical/scd30_core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iio/chemical/scd30_core.c +1 -1
index a665fcb78806..11d6bc1b63e6 100644
@@ -256,7 +256,7 @@ static int scd30_write_raw(struct iio_dev *indio_dev, struct iio_chan_spec const
 	guard(mutex)(&state->lock);
 	switch (mask) {
 	case IIO_CHAN_INFO_SAMP_FREQ:
-		if (val)
+		if (val || !val2)
 			return -EINVAL;
 
 		val = 1000000000 / val2;
Signature · 1 line
2.43.0
maintainer Applied
#1 lore raw
Quoted 7 lines · On Wed, 1 Apr 2026 14:08:29 +0300 Antoniu Miclaus <[email protected]>…

Add a zero check for val2 before using it as a divisor when setting the sampling frequency. A user writing a zero fractional part to the sampling_frequency sysfs attribute triggers a division by zero in the kernel.

Fixes 64b3d8b1b0f5 ("iio: chemical: scd30: add core driver")

Applied to fixes-togreg and marked for stable.

Thanks,

J

Quoted 17 lines
---
 drivers/iio/chemical/scd30_core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iio/chemical/scd30_core.c +1 -1
index a665fcb78806..11d6bc1b63e6 100644
@@ -256,7 +256,7 @@ static int scd30_write_raw(struct iio_dev *indio_dev, struct iio_chan_spec const
 	guard(mutex)(&state->lock);
 	switch (mask) {
 	case IIO_CHAN_INFO_SAMP_FREQ:
-		if (val)
+		if (val || !val2)
 			return -EINVAL;
 
 		val = 1000000000 / val2;