* [PATCH] iio: chemical: scd30: fix division by zero in write_raw
@ 2026-04-01 11:08 Antoniu Miclaus
2026-04-20 14:31 ` Jonathan Cameron
0 siblings, 1 reply; 2+ messages in thread
From: Antoniu Miclaus @ 2026-04-01 11:08 UTC (permalink / raw)
To: Tomasz Duszynski, Jonathan Cameron, Lars-Peter Clausen, linux-iio,
linux-kernel
Cc: Antoniu Miclaus
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>
---
drivers/iio/chemical/scd30_core.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/iio/chemical/scd30_core.c b/drivers/iio/chemical/scd30_core.c
index a665fcb78806..11d6bc1b63e6 100644
--- a/drivers/iio/chemical/scd30_core.c
+++ b/drivers/iio/chemical/scd30_core.c
@@ -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;
--
2.43.0
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH] iio: chemical: scd30: fix division by zero in write_raw
2026-04-01 11:08 [PATCH] iio: chemical: scd30: fix division by zero in write_raw Antoniu Miclaus
@ 2026-04-20 14:31 ` Jonathan Cameron
0 siblings, 0 replies; 2+ messages in thread
From: Jonathan Cameron @ 2026-04-20 14:31 UTC (permalink / raw)
To: Antoniu Miclaus
Cc: Tomasz Duszynski, Lars-Peter Clausen, linux-iio, linux-kernel
On Wed, 1 Apr 2026 14:08:29 +0300
Antoniu Miclaus <antoniu.miclaus@analog.com> wrote:
> 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>
Applied to fixes-togreg and marked for stable.
Thanks,
J
> ---
> drivers/iio/chemical/scd30_core.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/iio/chemical/scd30_core.c b/drivers/iio/chemical/scd30_core.c
> index a665fcb78806..11d6bc1b63e6 100644
> --- a/drivers/iio/chemical/scd30_core.c
> +++ b/drivers/iio/chemical/scd30_core.c
> @@ -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;
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-04-20 14:31 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-01 11:08 [PATCH] iio: chemical: scd30: fix division by zero in write_raw Antoniu Miclaus
2026-04-20 14:31 ` Jonathan Cameron
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox