]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
iio: chemical: scd30: fix division by zero in write_raw
authorAntoniu Miclaus <antoniu.miclaus@analog.com>
Wed, 1 Apr 2026 11:08:29 +0000 (14:08 +0300)
committerJonathan Cameron <jic23@kernel.org>
Tue, 28 Apr 2026 15:36:09 +0000 (16:36 +0100)
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 <antoniu.miclaus@analog.com>
Cc: <Stable@vger.kernel.org>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
drivers/iio/chemical/scd30_core.c

index a665fcb78806fac47e6ca0f0a3df8e109b03565a..11d6bc1b63e670292857d4741dec266227105e25 100644 (file)
@@ -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;