Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

iio: Improve iio_read_channel_processed_scale() precision

Before this change iio_read_channel_processed_scale() always assumes that
channels which advertise IIO_CHAN_INFO_PROCESSED capability return
IIO_VAL_INT on success.

Ignoring any fractional values from drivers which return
IIO_VAL_INT_PLUS_MICRO / IIO_VAL_INT_PLUS_NANO. These fractional values
might become non fractional after scaling so these should be taken into
account for better precision.

Use the new iio_multiply_value() helper to do proper scaling taking
the fractionional values into account.

Reviewed-by: Andy Shevchenko <andy@kernel.org>
Signed-off-by: Hans de Goede <hansg@kernel.org>
Link: https://patch.msgid.link/20250831104825.15097-5-hansg@kernel.org
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

authored by

Hans de Goede and committed by
Jonathan Cameron
05f958d0 cec1aec9

+3 -4
+3 -4
drivers/iio/inkern.c
··· 726 726 unsigned int scale) 727 727 { 728 728 struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(chan->indio_dev); 729 - int ret; 729 + int ret, pval, pval2; 730 730 731 731 guard(mutex)(&iio_dev_opaque->info_exist_lock); 732 732 if (!chan->indio_dev->info) 733 733 return -ENODEV; 734 734 735 735 if (iio_channel_has_info(chan->channel, IIO_CHAN_INFO_PROCESSED)) { 736 - ret = iio_channel_read(chan, val, NULL, 736 + ret = iio_channel_read(chan, &pval, &pval2, 737 737 IIO_CHAN_INFO_PROCESSED); 738 738 if (ret < 0) 739 739 return ret; 740 - *val *= scale; 741 740 742 - return ret; 741 + return iio_multiply_value(val, scale, ret, pval, pval2); 743 742 } else { 744 743 ret = iio_channel_read(chan, val, NULL, IIO_CHAN_INFO_RAW); 745 744 if (ret < 0)