diff mbox series

iio: proximity: pulsedlight v2: Tidy up an endian issue

Message ID 20191013102600.1463679-1-jic23@kernel.org (mailing list archive)
State New, archived
Headers show
Series iio: proximity: pulsedlight v2: Tidy up an endian issue | expand

Commit Message

Jonathan Cameron Oct. 13, 2019, 10:26 a.m. UTC
From: Jonathan Cameron <Jonathan.Cameron@huawei.com>

Sparse identified the following
CHECK   drivers/iio/proximity/pulsedlight-lidar-lite-v2.c
drivers/iio/proximity/pulsedlight-lidar-lite-v2.c:144:24: warning: cast to restricted __be16
drivers/iio/proximity/pulsedlight-lidar-lite-v2.c:144:24: warning: cast to restricted __be16
drivers/iio/proximity/pulsedlight-lidar-lite-v2.c:144:24: warning: cast to restricted __be16
drivers/iio/proximity/pulsedlight-lidar-lite-v2.c:144:24: warning: cast to restricted __be16

This cleans up by adding a local variable to hold the value whilst
it is __be16 before applying endian converstion into eventual destination.

Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Cc: Matt Ranostay <matt.ranostay@konsulko.com>
---
 drivers/iio/proximity/pulsedlight-lidar-lite-v2.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

Comments

Matt Ranostay Oct. 13, 2019, 5:58 p.m. UTC | #1
On Sun, Oct 13, 2019 at 1:28 PM <jic23@kernel.org> wrote:
>
> From: Jonathan Cameron <Jonathan.Cameron@huawei.com>
>
> Sparse identified the following
> CHECK   drivers/iio/proximity/pulsedlight-lidar-lite-v2.c
> drivers/iio/proximity/pulsedlight-lidar-lite-v2.c:144:24: warning: cast to restricted __be16
> drivers/iio/proximity/pulsedlight-lidar-lite-v2.c:144:24: warning: cast to restricted __be16
> drivers/iio/proximity/pulsedlight-lidar-lite-v2.c:144:24: warning: cast to restricted __be16
> drivers/iio/proximity/pulsedlight-lidar-lite-v2.c:144:24: warning: cast to restricted __be16
>
> This cleans up by adding a local variable to hold the value whilst
> it is __be16 before applying endian converstion into eventual destination.
>
> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
> Cc: Matt Ranostay <matt.ranostay@konsulko.com>

Acked-by: Matt Ranostay <matt.ranostay@konsulko.com>

> ---
>  drivers/iio/proximity/pulsedlight-lidar-lite-v2.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/iio/proximity/pulsedlight-lidar-lite-v2.c b/drivers/iio/proximity/pulsedlight-lidar-lite-v2.c
> index 47af54f14756..5b369645ef49 100644
> --- a/drivers/iio/proximity/pulsedlight-lidar-lite-v2.c
> +++ b/drivers/iio/proximity/pulsedlight-lidar-lite-v2.c
> @@ -136,12 +136,13 @@ static inline int lidar_write_power(struct lidar_data *data, int val)
>
>  static int lidar_read_measurement(struct lidar_data *data, u16 *reg)
>  {
> +       __be16 value;
>         int ret = data->xfer(data, LIDAR_REG_DATA_HBYTE |
>                         (data->i2c_enabled ? LIDAR_REG_DATA_WORD_READ : 0),
> -                       (u8 *) reg, 2);
> +                       (u8 *) &value, 2);
>
>         if (!ret)
> -               *reg = be16_to_cpu(*reg);
> +               *reg = be16_to_cpu(value);
>
>         return ret;
>  }
> --
> 2.23.0
>
Jonathan Cameron Oct. 18, 2019, 6:58 p.m. UTC | #2
On Sun, 13 Oct 2019 20:58:26 +0300
Matt Ranostay <matt.ranostay@konsulko.com> wrote:

> On Sun, Oct 13, 2019 at 1:28 PM <jic23@kernel.org> wrote:
> >
> > From: Jonathan Cameron <Jonathan.Cameron@huawei.com>
> >
> > Sparse identified the following
> > CHECK   drivers/iio/proximity/pulsedlight-lidar-lite-v2.c
> > drivers/iio/proximity/pulsedlight-lidar-lite-v2.c:144:24: warning: cast to restricted __be16
> > drivers/iio/proximity/pulsedlight-lidar-lite-v2.c:144:24: warning: cast to restricted __be16
> > drivers/iio/proximity/pulsedlight-lidar-lite-v2.c:144:24: warning: cast to restricted __be16
> > drivers/iio/proximity/pulsedlight-lidar-lite-v2.c:144:24: warning: cast to restricted __be16
> >
> > This cleans up by adding a local variable to hold the value whilst
> > it is __be16 before applying endian converstion into eventual destination.
> >
> > Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
> > Cc: Matt Ranostay <matt.ranostay@konsulko.com>  
> 
> Acked-by: Matt Ranostay <matt.ranostay@konsulko.com>
Applied. Thanks,

Jonathan

> 
> > ---
> >  drivers/iio/proximity/pulsedlight-lidar-lite-v2.c | 5 +++--
> >  1 file changed, 3 insertions(+), 2 deletions(-)
> >
> > diff --git a/drivers/iio/proximity/pulsedlight-lidar-lite-v2.c b/drivers/iio/proximity/pulsedlight-lidar-lite-v2.c
> > index 47af54f14756..5b369645ef49 100644
> > --- a/drivers/iio/proximity/pulsedlight-lidar-lite-v2.c
> > +++ b/drivers/iio/proximity/pulsedlight-lidar-lite-v2.c
> > @@ -136,12 +136,13 @@ static inline int lidar_write_power(struct lidar_data *data, int val)
> >
> >  static int lidar_read_measurement(struct lidar_data *data, u16 *reg)
> >  {
> > +       __be16 value;
> >         int ret = data->xfer(data, LIDAR_REG_DATA_HBYTE |
> >                         (data->i2c_enabled ? LIDAR_REG_DATA_WORD_READ : 0),
> > -                       (u8 *) reg, 2);
> > +                       (u8 *) &value, 2);
> >
> >         if (!ret)
> > -               *reg = be16_to_cpu(*reg);
> > +               *reg = be16_to_cpu(value);
> >
> >         return ret;
> >  }
> > --
> > 2.23.0
> >
diff mbox series

Patch

diff --git a/drivers/iio/proximity/pulsedlight-lidar-lite-v2.c b/drivers/iio/proximity/pulsedlight-lidar-lite-v2.c
index 47af54f14756..5b369645ef49 100644
--- a/drivers/iio/proximity/pulsedlight-lidar-lite-v2.c
+++ b/drivers/iio/proximity/pulsedlight-lidar-lite-v2.c
@@ -136,12 +136,13 @@  static inline int lidar_write_power(struct lidar_data *data, int val)
 
 static int lidar_read_measurement(struct lidar_data *data, u16 *reg)
 {
+	__be16 value;
 	int ret = data->xfer(data, LIDAR_REG_DATA_HBYTE |
 			(data->i2c_enabled ? LIDAR_REG_DATA_WORD_READ : 0),
-			(u8 *) reg, 2);
+			(u8 *) &value, 2);
 
 	if (!ret)
-		*reg = be16_to_cpu(*reg);
+		*reg = be16_to_cpu(value);
 
 	return ret;
 }