diff mbox series

[v1,1/1] iio: pressure: dlhl60d: Don't take garbage into consideration when reading data

Message ID 20220726142048.4494-1-andriy.shevchenko@linux.intel.com (mailing list archive)
State Accepted
Headers show
Series [v1,1/1] iio: pressure: dlhl60d: Don't take garbage into consideration when reading data | expand

Commit Message

Andy Shevchenko July 26, 2022, 2:20 p.m. UTC
Both pressure and temperature are 24-bit long. Use proper accessors
instead of overlapping readings.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/iio/pressure/dlhl60d.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

Comments

Jonathan Cameron July 31, 2022, 12:33 p.m. UTC | #1
On Tue, 26 Jul 2022 17:20:48 +0300
Andy Shevchenko <andriy.shevchenko@linux.intel.com> wrote:

> Both pressure and temperature are 24-bit long. Use proper accessors
> instead of overlapping readings.
> 
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Looks correct to me, but it made me scratch my head just enough that I'd
like Tomislav to take a look if possible.  So give me a poke if this
hasn't progressed in a few weeks time.

Thanks,

Jonathan

> ---
>  drivers/iio/pressure/dlhl60d.c | 5 ++---
>  1 file changed, 2 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/iio/pressure/dlhl60d.c b/drivers/iio/pressure/dlhl60d.c
> index 5f6bb3603a8b..f0b0d198c6d4 100644
> --- a/drivers/iio/pressure/dlhl60d.c
> +++ b/drivers/iio/pressure/dlhl60d.c
> @@ -129,9 +129,8 @@ static int dlh_read_direct(struct dlh_state *st,
>  	if (ret)
>  		return ret;
>  
> -	*pressure = get_unaligned_be32(&st->rx_buf[1]) >> 8;
> -	*temperature = get_unaligned_be32(&st->rx_buf[3]) &
> -		GENMASK(DLH_NUM_TEMP_BITS - 1, 0);
> +	*pressure = get_unaligned_be24(&st->rx_buf[1]);
> +	*temperature = get_unaligned_be24(&st->rx_buf[4]);
>  
>  	return 0;
>  }
Jonathan Cameron Aug. 14, 2022, 5:15 p.m. UTC | #2
On Sun, 31 Jul 2022 13:33:57 +0100
Jonathan Cameron <jic23@kernel.org> wrote:

> On Tue, 26 Jul 2022 17:20:48 +0300
> Andy Shevchenko <andriy.shevchenko@linux.intel.com> wrote:
> 
> > Both pressure and temperature are 24-bit long. Use proper accessors
> > instead of overlapping readings.
> > 
> > Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>  
> Looks correct to me, but it made me scratch my head just enough that I'd
> like Tomislav to take a look if possible.  So give me a poke if this
> hasn't progressed in a few weeks time.

Long enough.

Applied to the togreg branch of iio.git and pushed out as testing.

Thanks,

Jonathan

> 
> Thanks,
> 
> Jonathan
> 
> > ---
> >  drivers/iio/pressure/dlhl60d.c | 5 ++---
> >  1 file changed, 2 insertions(+), 3 deletions(-)
> > 
> > diff --git a/drivers/iio/pressure/dlhl60d.c b/drivers/iio/pressure/dlhl60d.c
> > index 5f6bb3603a8b..f0b0d198c6d4 100644
> > --- a/drivers/iio/pressure/dlhl60d.c
> > +++ b/drivers/iio/pressure/dlhl60d.c
> > @@ -129,9 +129,8 @@ static int dlh_read_direct(struct dlh_state *st,
> >  	if (ret)
> >  		return ret;
> >  
> > -	*pressure = get_unaligned_be32(&st->rx_buf[1]) >> 8;
> > -	*temperature = get_unaligned_be32(&st->rx_buf[3]) &
> > -		GENMASK(DLH_NUM_TEMP_BITS - 1, 0);
> > +	*pressure = get_unaligned_be24(&st->rx_buf[1]);
> > +	*temperature = get_unaligned_be24(&st->rx_buf[4]);
> >  
> >  	return 0;
> >  }  
>
diff mbox series

Patch

diff --git a/drivers/iio/pressure/dlhl60d.c b/drivers/iio/pressure/dlhl60d.c
index 5f6bb3603a8b..f0b0d198c6d4 100644
--- a/drivers/iio/pressure/dlhl60d.c
+++ b/drivers/iio/pressure/dlhl60d.c
@@ -129,9 +129,8 @@  static int dlh_read_direct(struct dlh_state *st,
 	if (ret)
 		return ret;
 
-	*pressure = get_unaligned_be32(&st->rx_buf[1]) >> 8;
-	*temperature = get_unaligned_be32(&st->rx_buf[3]) &
-		GENMASK(DLH_NUM_TEMP_BITS - 1, 0);
+	*pressure = get_unaligned_be24(&st->rx_buf[1]);
+	*temperature = get_unaligned_be24(&st->rx_buf[4]);
 
 	return 0;
 }