Re: [PATCH v1 1/1] iio: Fix iio_multiply_value use in iio_read_channel_processed_scale

From: Hans de Goede

Date: Thu Apr 16 2026 - 08:34:07 EST


Hi,

On 16-Apr-26 13:14, Svyatoslav Ryhel wrote:
> The function iio_multiply_value returns IIO_VAL_INT (1) on success or a
> negative error number on failure, while iio_read_channel_processed_scale
> should return an error code or 0. This creates a situation where the
> expected result is treated as an error. Fix this by checking the
> iio_multiply_value result separately, instead of passing it as a return
> value.
>
> Fixes: 05f958d003c9 ("iio: Improve iio_read_channel_processed_scale() precision")
> Signed-off-by: Svyatoslav Ryhel <clamor95@xxxxxxxxx>

Thank you, good catch:

Reviewed-by: Hans de Goede <johannes.goede@xxxxxxxxxxxxxxxx>

Regards,

Hans



> ---
> drivers/iio/inkern.c | 6 +++++-
> 1 file changed, 5 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/iio/inkern.c b/drivers/iio/inkern.c
> index 0df0ab3de270..9ce20cb05a9b 100644
> --- a/drivers/iio/inkern.c
> +++ b/drivers/iio/inkern.c
> @@ -738,7 +738,11 @@ int iio_read_channel_processed_scale(struct iio_channel *chan, int *val,
> if (ret < 0)
> return ret;
>
> - return iio_multiply_value(val, scale, ret, pval, pval2);
> + ret = iio_multiply_value(val, scale, ret, pval, pval2);
> + if (ret < 0)
> + return ret;
> +
> + return 0;
> } else {
> ret = iio_channel_read(chan, val, NULL, IIO_CHAN_INFO_RAW);
> if (ret < 0)