Commit 8a3dcc97 authored by Matteo Martelli's avatar Matteo Martelli Committed by Jonathan Cameron

iio: fix scale application in iio_convert_raw_to_processed_unlocked

When the scale_type is IIO_VAL_INT_PLUS_MICRO or IIO_VAL_INT_PLUS_NANO
the scale passed as argument is only applied to the fractional part of
the value. Fix it by also multiplying the integer part by the scale
provided.

Fixes: 48e44ce0 ("iio:inkern: Add function to read the processed value")
Signed-off-by: default avatarMatteo Martelli <matteomartelli3@gmail.com>
Link: https://patch.msgid.link/20240730-iio-fix-scale-v1-1-6246638c8daa@gmail.com
Cc: <Stable@vger.kernel.org>
Signed-off-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
parent 2f6b92d0
...@@ -647,17 +647,17 @@ static int iio_convert_raw_to_processed_unlocked(struct iio_channel *chan, ...@@ -647,17 +647,17 @@ static int iio_convert_raw_to_processed_unlocked(struct iio_channel *chan,
break; break;
case IIO_VAL_INT_PLUS_MICRO: case IIO_VAL_INT_PLUS_MICRO:
if (scale_val2 < 0) if (scale_val2 < 0)
*processed = -raw64 * scale_val; *processed = -raw64 * scale_val * scale;
else else
*processed = raw64 * scale_val; *processed = raw64 * scale_val * scale;
*processed += div_s64(raw64 * (s64)scale_val2 * scale, *processed += div_s64(raw64 * (s64)scale_val2 * scale,
1000000LL); 1000000LL);
break; break;
case IIO_VAL_INT_PLUS_NANO: case IIO_VAL_INT_PLUS_NANO:
if (scale_val2 < 0) if (scale_val2 < 0)
*processed = -raw64 * scale_val; *processed = -raw64 * scale_val * scale;
else else
*processed = raw64 * scale_val; *processed = raw64 * scale_val * scale;
*processed += div_s64(raw64 * (s64)scale_val2 * scale, *processed += div_s64(raw64 * (s64)scale_val2 * scale,
1000000000LL); 1000000000LL);
break; break;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment