diff mbox series

[v1,1/9] iio: inkern: always apply scale requested by consumer

Message ID 20210530005917.20953-2-liambeguin@gmail.com (mailing list archive)
State Superseded, archived
Headers show
Series iio: afe: add temperature rescaling support | expand

Commit Message

Liam Beguin May 30, 2021, 12:59 a.m. UTC
From: Liam Beguin <lvb@xiphos.com>

When a consumer calls iio_read_channel_processed() and no scaling is
available on the channel, it's assumed that the scale is one and the raw
value is returned as expected.

On the other hand, if the consumer calls iio_convert_raw_to_processed()
the scaling factor requested by the consumer is not applied.
This for example causes the consumer to process mV when expecting uV.

Make sure to always apply the scaling factor requested by the consumer.

Signed-off-by: Liam Beguin <lvb@xiphos.com>
---
 drivers/iio/inkern.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)

Comments

Peter Rosin May 31, 2021, 1:39 p.m. UTC | #1
Hi!

On 2021-05-30 02:59, Liam Beguin wrote:
> From: Liam Beguin <lvb@xiphos.com>
> 
> When a consumer calls iio_read_channel_processed() and no scaling is
> available on the channel, it's assumed that the scale is one and the raw
> value is returned as expected.
> 
> On the other hand, if the consumer calls iio_convert_raw_to_processed()
> the scaling factor requested by the consumer is not applied.
> This for example causes the consumer to process mV when expecting uV.
> 
> Make sure to always apply the scaling factor requested by the consumer.
> 
> Signed-off-by: Liam Beguin <lvb@xiphos.com>
> ---
>  drivers/iio/inkern.c | 6 +-----
>  1 file changed, 1 insertion(+), 5 deletions(-)
> 
> diff --git a/drivers/iio/inkern.c b/drivers/iio/inkern.c
> index db77a2d4a56b..4b6a8e11116a 100644
> --- a/drivers/iio/inkern.c
> +++ b/drivers/iio/inkern.c
> @@ -601,11 +601,7 @@ static int iio_convert_raw_to_processed_unlocked(struct iio_channel *chan,
>  	scale_type = iio_channel_read(chan, &scale_val, &scale_val2,
>  					IIO_CHAN_INFO_SCALE);
>  	if (scale_type < 0) {
> -		/*
> -		 * Just pass raw values as processed if no scaling is
> -		 * available.
> -		 */
> -		*processed = raw;
> +		*processed = raw * scale;

I would keep the comment. Sure, it's now completely confusing since it's from
before the function had a scale parameter. Perhaps reword it to talk about
"no channel scaling" instead of plain old "no scaling"?

Also, this looks like a bugfix, no more, no less, and should perhaps have a
fixes tag?

Cheers,
Peter

>  		return 0;
>  	}
>  
>
diff mbox series

Patch

diff --git a/drivers/iio/inkern.c b/drivers/iio/inkern.c
index db77a2d4a56b..4b6a8e11116a 100644
--- a/drivers/iio/inkern.c
+++ b/drivers/iio/inkern.c
@@ -601,11 +601,7 @@  static int iio_convert_raw_to_processed_unlocked(struct iio_channel *chan,
 	scale_type = iio_channel_read(chan, &scale_val, &scale_val2,
 					IIO_CHAN_INFO_SCALE);
 	if (scale_type < 0) {
-		/*
-		 * Just pass raw values as processed if no scaling is
-		 * available.
-		 */
-		*processed = raw;
+		*processed = raw * scale;
 		return 0;
 	}