Skip to contentSkip to conversation

iio: Fix iio_multiply_value use in iio_read_channel_processed_scale

PATCH In review Svyatoslav Ryhel 3 participants 4 messages Apr 16 – Apr 19 IIO

lore
Share & tools
lore
#0 lore raw

cover iio: Fix iio_multiply_value use in iio_read_channel_processed_scale

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.

Svyatoslav Ryhel (1):
iio: Fix iio_multiply_value use in iio_read_channel_processed_scale

 drivers/iio/inkern.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
Signature · 1 line
2.51.0
#1 lore raw

PATCH 1/1 iio: Fix iio_multiply_value use in iio_read_channel_processed_scale

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")
---
 drivers/iio/inkern.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/iio/inkern.c +5 -1
index 0df0ab3de270..9ce20cb05a9b 100644
@@ -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)
Signature · 1 line
2.51.0
Reviewed-by on v1 1/1
#2 lore raw

Hi,

Quoted 9 lines · Svyatoslav Ryhel

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")

Thank you, good catch:

Regards,

Hans

Quoted 21 lines
---
 drivers/iio/inkern.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/iio/inkern.c +5 -1
index 0df0ab3de270..9ce20cb05a9b 100644
@@ -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)
maintainer
#3 lore raw
Quoted 10 lines · On Thu, 16 Apr 2026 14:31:00 +0200 Hans de Goede <[email protected]> wrote:

Hi,

Quoted 7 lines · Svyatoslav Ryhel

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.

Quoted 4 lines
Quoted 2 lines
Fixes 05f958d003c9 ("iio: Improve iio_read_channel_processed_scale() precision")

Thank you, good catch:

Indeed and 'ouch'.

Anyhow, applied to the fixes-togreg branch of iio.git and marked for stable.

Thanks,

Jonathan

Quoted 32 lines

Regards,

Hans

Quoted 21 lines
---
 drivers/iio/inkern.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/iio/inkern.c +5 -1
index 0df0ab3de270..9ce20cb05a9b 100644
@@ -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)