iio: chemical: scd30: fix division by zero in write_raw
Subsystems (2)
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")
Signed-off-by Antoniu Miclaus <[email protected]>
--- drivers/iio/chemical/scd30_core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iio/chemical/scd30_core.c +1 -1
@@ -256,7 +256,7 @@ static int scd30_write_raw(struct iio_dev *indio_dev, struct iio_chan_spec constguard (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
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_frequencysysfs attribute triggers a division by zero in the kernel.Fixes 64b3d8b1b0f5 ("iio: chemical: scd30: add core driver")Signed-off-by Antoniu Miclaus <[email protected]>
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@@ -256,7 +256,7 @@ static int scd30_write_raw(struct iio_dev *indio_dev, struct iio_chan_spec constguard (mutex)(&state->lock);switch (mask) {case IIO_CHAN_INFO_SAMP_FREQ : -if (val) +if (val || !val2)return -EINVAL ; val =1000000000 / val2;