FAILED: patch "[PATCH] iio: chemical: scd30: fix division by zero in write_raw" failed to apply to 5.10-stable tree
Subsystems (3)
[email protected]
maintainerThe patch below does not apply to the 5.10-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
To reproduce the conflict and resubmit, you may use the following commands:
git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-5.10.y
git checkout FETCH_HEAD
git cherry-pick -x 5aba4f94b225617a55fed442a70329b2ee19c0a5
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '2026060457-rubdown-rival-345e@gregkh' --subject-prefix 'PATCH 5.10.y' HEAD^..
Possible dependencies:
thanks,
greg k-h
------------------ original commit in Linus's tree ------------------
From 5aba4f94b225617a55fed442a70329b2ee19c0a5 Mon Sep 17 00:00:00 2001
From: Antoniu Miclaus <[email protected]>
Date: Wed, 1 Apr 2026 14:08:29 +0300
Subject: [PATCH] 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.
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;
Sasha Levin
maintainerPATCH 1/2 iio: chemical: scd30: Use guard(mutex) to allow early returns
From: Jonathan Cameron <[email protected]>
[ Upstream commit 5feb5532870fbced5d6f450b8061a33f461b88ca ]
Auto cleanup based release of the lock allows for simpler code flow in a few functions with large multiplexing style switch statements and no common operations following the switch.
Stable-dep-of: 5aba4f94b225 ("iio: chemical: scd30: fix division by zero in write_raw")
--- drivers/iio/chemical/scd30_core.c | 63 ++++++++++++++----------------- 1 file changed, 28 insertions(+), 35 deletions(-)
drivers/iio/chemical/scd30_core.c +28 -35
@@ -5,6 +5,7 @@* Copyright (c) 2020 Tomasz Duszynski <[email protected]> */ #include <linux/bits.h> +#include <linux/cleanup.h> #include <linux/completion.h> #include <linux/delay.h> #include <linux/device.h>
@@ -198,112 +199,104 @@ static int scd30_read_raw(struct iio_dev *indio_dev, struct iio_chan_spec const int *val, int *val2, long mask) { struct scd30_state *state = iio_priv(indio_dev); -int ret = -EINVAL ; +int ret;u16 tmp; -mutex_lock (&state->lock); +guard (mutex)(&state->lock);switch (mask) {case IIO_CHAN_INFO_RAW :case IIO_CHAN_INFO_PROCESSED :if (chan->output) { *val = state->pressure_comp; - ret =IIO_VAL_INT ; -break ; +return IIO_VAL_INT ; } ret =iio_device_claim_direct_mode (indio_dev);if (ret) -break ; +return ret; ret =scd30_read (state);if (ret) {iio_device_release_direct_mode (indio_dev); -break ; +return ret; } *val = state->meas[chan->address];iio_device_release_direct_mode (indio_dev); - ret =IIO_VAL_INT ; -break ; +return IIO_VAL_INT ;case IIO_CHAN_INFO_SCALE : *val =0 ; *val2 =1 ; - ret =IIO_VAL_INT_PLUS_MICRO ; -break ; +return IIO_VAL_INT_PLUS_MICRO ;case IIO_CHAN_INFO_SAMP_FREQ : ret =scd30_command_read (state,CMD_MEAS_INTERVAL , &tmp);if (ret) -break ; +return ret; *val =0 ; *val2 =1000000000 / tmp; - ret =IIO_VAL_INT_PLUS_NANO ; -break ; +return IIO_VAL_INT_PLUS_NANO ;case IIO_CHAN_INFO_CALIBBIAS : ret =scd30_command_read (state,CMD_TEMP_OFFSET , &tmp);if (ret) -break ; +return ret; *val = tmp; - ret =IIO_VAL_INT ; -break ; +return IIO_VAL_INT ; +default : +return -EINVAL ; } -mutex_unlock (&state->lock); - -return ret; }static int scd30_write_raw (struct iio_dev *indio_dev,struct iio_chan_spec const *chan,int val,int val2,long mask) {struct scd30_state *state =iio_priv (indio_dev); -int ret = -EINVAL ; +int ret; -mutex_lock (&state->lock); +guard (mutex)(&state->lock);switch (mask) {case IIO_CHAN_INFO_SAMP_FREQ :if (val) -break ; +return -EINVAL ; val =1000000000 / val2;if (val <SCD30_MEAS_INTERVAL_MIN_S || val >SCD30_MEAS_INTERVAL_MAX_S ) -break ; +return -EINVAL ; ret =scd30_command_write (state,CMD_MEAS_INTERVAL , val);if (ret) -break ; +return ret; state->meas_interval = val; -break ; +return 0 ;case IIO_CHAN_INFO_RAW :switch (chan->type) {case IIO_PRESSURE :if (val <SCD30_PRESSURE_COMP_MIN_MBAR || val >SCD30_PRESSURE_COMP_MAX_MBAR ) -break ; +return -EINVAL ; ret =scd30_command_write (state,CMD_START_MEAS , val);if (ret) -break ; +return ret; state->pressure_comp = val; -break ; +return 0 ;default : -break ; +return -EINVAL ; } -break ;case IIO_CHAN_INFO_CALIBBIAS :if (val <0 || val >SCD30_TEMP_OFFSET_MAX ) -break ; +return -EINVAL ;/* * Manufacturer does not explicitly specify min/max sensible * values hence check is omitted for simplicity. */ - ret =scd30_command_write (state,CMD_TEMP_OFFSET /10 , val); +return scd30_command_write (state,CMD_TEMP_OFFSET /10 , val); +default : +return -EINVAL ; } -mutex_unlock (&state->lock); - -return ret; } static int scd30_write_raw_get_fmt(struct iio_dev *indio_dev, struct iio_chan_spec const *chan,
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 2/2 iio: chemical: scd30: fix division by zero in write_raw
From: Antoniu Miclaus <[email protected]>
[ Upstream commit 5aba4f94b225617a55fed442a70329b2ee19c0a5 ]
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.
--- drivers/iio/chemical/scd30_core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iio/chemical/scd30_core.c +1 -1
@@ -257,7 +257,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.53.0