diff options
| author | Matteo Martelli <matteomartelli3@gmail.com> | 2024-07-30 10:11:53 +0200 |
|---|---|---|
| committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2024-09-12 11:06:50 +0200 |
| commit | 1719ebc8e303b699128c4ca01035b154d11130c7 (patch) | |
| tree | cc14c5debf24b2c6c82d948b869a608a979f66e9 | |
| parent | f3a54c27bacd07b21ac8c79ce21d9632d1a8e008 (diff) | |
| download | linux-1719ebc8e303b699128c4ca01035b154d11130c7.tar.gz linux-1719ebc8e303b699128c4ca01035b154d11130c7.tar.bz2 linux-1719ebc8e303b699128c4ca01035b154d11130c7.zip | |
iio: fix scale application in iio_convert_raw_to_processed_unlocked
commit 8a3dcc970dc57b358c8db2702447bf0af4e0d83a upstream.
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: 48e44ce0f881 ("iio:inkern: Add function to read the processed value")
Signed-off-by: Matteo 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: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
| -rw-r--r-- | drivers/iio/inkern.c | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/drivers/iio/inkern.c b/drivers/iio/inkern.c index c32b2577dd99..6e64ffde6c82 100644 --- a/drivers/iio/inkern.c +++ b/drivers/iio/inkern.c @@ -610,17 +610,17 @@ static int iio_convert_raw_to_processed_unlocked(struct iio_channel *chan, break; case IIO_VAL_INT_PLUS_MICRO: if (scale_val2 < 0) - *processed = -raw64 * scale_val; + *processed = -raw64 * scale_val * scale; else - *processed = raw64 * scale_val; + *processed = raw64 * scale_val * scale; *processed += div_s64(raw64 * (s64)scale_val2 * scale, 1000000LL); break; case IIO_VAL_INT_PLUS_NANO: if (scale_val2 < 0) - *processed = -raw64 * scale_val; + *processed = -raw64 * scale_val * scale; else - *processed = raw64 * scale_val; + *processed = raw64 * scale_val * scale; *processed += div_s64(raw64 * (s64)scale_val2 * scale, 1000000000LL); break; |
