diff mbox series

[v2,4/8] iio: inkern: return valid type on raw to processed conversion

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

Commit Message

Liam Beguin June 7, 2021, 2:47 p.m. UTC
From: Liam Beguin <lvb@xiphos.com>

iio_convert_raw_to_processed_unlocked() applies the offset and scale of
a channel on it's raw value.
The processed value returned is always an integer. Return IIO_VAL_INT so
that consumers can use this return value directly.

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

Comments

Jonathan Cameron June 9, 2021, 8:32 p.m. UTC | #1
On Mon,  7 Jun 2021 10:47:14 -0400
Liam Beguin <liambeguin@gmail.com> wrote:

> From: Liam Beguin <lvb@xiphos.com>
> 
> iio_convert_raw_to_processed_unlocked() applies the offset and scale of
> a channel on it's raw value.
> The processed value returned is always an integer. Return IIO_VAL_INT so
> that consumers can use this return value directly.
> 
> Signed-off-by: Liam Beguin <lvb@xiphos.com>
This looks likely to cause breakage given that return value will go to
consumers directly via iio_convert_raw_to_processed()

Looks like this will break lmp91000 which checks for error as

if (ret)

> ---
>  drivers/iio/inkern.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/iio/inkern.c b/drivers/iio/inkern.c
> index 0b5667f22b1d..00d234e87234 100644
> --- a/drivers/iio/inkern.c
> +++ b/drivers/iio/inkern.c
> @@ -618,7 +618,7 @@ static int iio_convert_raw_to_processed_unlocked(struct iio_channel *chan,
>  		 * raw value and return.
>  		 */
>  		*processed = raw * scale;
> -		return 0;
> +		return IIO_VAL_INT;
>  	}
>  
>  	switch (scale_type) {
> @@ -652,7 +652,7 @@ static int iio_convert_raw_to_processed_unlocked(struct iio_channel *chan,
>  		return -EINVAL;
>  	}
>  
> -	return 0;
> +	return IIO_VAL_INT;
>  }
>  
>  int iio_convert_raw_to_processed(struct iio_channel *chan, int raw,
Liam Beguin June 9, 2021, 9:46 p.m. UTC | #2
On Wed Jun 9, 2021 at 4:32 PM EDT, Jonathan Cameron wrote:
> On Mon, 7 Jun 2021 10:47:14 -0400
> Liam Beguin <liambeguin@gmail.com> wrote:
>
> > From: Liam Beguin <lvb@xiphos.com>
> > 
> > iio_convert_raw_to_processed_unlocked() applies the offset and scale of
> > a channel on it's raw value.
> > The processed value returned is always an integer. Return IIO_VAL_INT so
> > that consumers can use this return value directly.
> > 
> > Signed-off-by: Liam Beguin <lvb@xiphos.com>
> This looks likely to cause breakage given that return value will go to
> consumers directly via iio_convert_raw_to_processed()
>
> Looks like this will break lmp91000 which checks for error as
>
> if (ret)
>

IIO_VAL_INT seems like a better return value here since the consumer
gets an integer. I can look at existing consumers and patch those too.
Or would you rather I drop this patch?

> > ---
> >  drivers/iio/inkern.c | 4 ++--
> >  1 file changed, 2 insertions(+), 2 deletions(-)
> > 
> > diff --git a/drivers/iio/inkern.c b/drivers/iio/inkern.c
> > index 0b5667f22b1d..00d234e87234 100644
> > --- a/drivers/iio/inkern.c
> > +++ b/drivers/iio/inkern.c
> > @@ -618,7 +618,7 @@ static int iio_convert_raw_to_processed_unlocked(struct iio_channel *chan,
> >  		 * raw value and return.
> >  		 */
> >  		*processed = raw * scale;
> > -		return 0;
> > +		return IIO_VAL_INT;
> >  	}
> >  
> >  	switch (scale_type) {
> > @@ -652,7 +652,7 @@ static int iio_convert_raw_to_processed_unlocked(struct iio_channel *chan,
> >  		return -EINVAL;
> >  	}
> >  
> > -	return 0;
> > +	return IIO_VAL_INT;
> >  }
> >  
> >  int iio_convert_raw_to_processed(struct iio_channel *chan, int raw,
Jonathan Cameron June 10, 2021, 9:08 a.m. UTC | #3
On Wed, 09 Jun 2021 17:46:58 -0400
"Liam Beguin" <liambeguin@gmail.com> wrote:

> On Wed Jun 9, 2021 at 4:32 PM EDT, Jonathan Cameron wrote:
> > On Mon, 7 Jun 2021 10:47:14 -0400
> > Liam Beguin <liambeguin@gmail.com> wrote:
> >  
> > > From: Liam Beguin <lvb@xiphos.com>
> > > 
> > > iio_convert_raw_to_processed_unlocked() applies the offset and scale of
> > > a channel on it's raw value.
> > > The processed value returned is always an integer. Return IIO_VAL_INT so
> > > that consumers can use this return value directly.
> > > 
> > > Signed-off-by: Liam Beguin <lvb@xiphos.com>  
> > This looks likely to cause breakage given that return value will go to
> > consumers directly via iio_convert_raw_to_processed()
> >
> > Looks like this will break lmp91000 which checks for error as
> >
> > if (ret)
> >  
> 
> IIO_VAL_INT seems like a better return value here since the consumer
> gets an integer. I can look at existing consumers and patch those too.
> Or would you rather I drop this patch?
If we were looking at actually allowing this to return other types,
then I'd agree with updating callers appropriately.

For now we aren't doing that, so the only question is success or fail.
So I'd drop this one.

Most consumers don't care about IIO types.

Jonathan

> 
> > > ---
> > >  drivers/iio/inkern.c | 4 ++--
> > >  1 file changed, 2 insertions(+), 2 deletions(-)
> > > 
> > > diff --git a/drivers/iio/inkern.c b/drivers/iio/inkern.c
> > > index 0b5667f22b1d..00d234e87234 100644
> > > --- a/drivers/iio/inkern.c
> > > +++ b/drivers/iio/inkern.c
> > > @@ -618,7 +618,7 @@ static int iio_convert_raw_to_processed_unlocked(struct iio_channel *chan,
> > >  		 * raw value and return.
> > >  		 */
> > >  		*processed = raw * scale;
> > > -		return 0;
> > > +		return IIO_VAL_INT;
> > >  	}
> > >  
> > >  	switch (scale_type) {
> > > @@ -652,7 +652,7 @@ static int iio_convert_raw_to_processed_unlocked(struct iio_channel *chan,
> > >  		return -EINVAL;
> > >  	}
> > >  
> > > -	return 0;
> > > +	return IIO_VAL_INT;
> > >  }
> > >  
> > >  int iio_convert_raw_to_processed(struct iio_channel *chan, int raw,  
>
diff mbox series

Patch

diff --git a/drivers/iio/inkern.c b/drivers/iio/inkern.c
index 0b5667f22b1d..00d234e87234 100644
--- a/drivers/iio/inkern.c
+++ b/drivers/iio/inkern.c
@@ -618,7 +618,7 @@  static int iio_convert_raw_to_processed_unlocked(struct iio_channel *chan,
 		 * raw value and return.
 		 */
 		*processed = raw * scale;
-		return 0;
+		return IIO_VAL_INT;
 	}
 
 	switch (scale_type) {
@@ -652,7 +652,7 @@  static int iio_convert_raw_to_processed_unlocked(struct iio_channel *chan,
 		return -EINVAL;
 	}
 
-	return 0;
+	return IIO_VAL_INT;
 }
 
 int iio_convert_raw_to_processed(struct iio_channel *chan, int raw,