All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] iio: accel: sca3000: Use sign_extend32() instead of opencoding sign extension.
@ 2021-10-17 16:03 Jonathan Cameron
  2021-10-17 17:17 ` Lars-Peter Clausen
  0 siblings, 1 reply; 3+ messages in thread
From: Jonathan Cameron @ 2021-10-17 16:03 UTC (permalink / raw)
  To: linux-iio; +Cc: Lars-Peter Clausen, Jonathan Cameron, Dan Carpenter

From: Jonathan Cameron <Jonathan.Cameron@huawei.com>

Whilst nice to get rid of this non obvious code, this also clears a
static checker warning:

drivers/iio/accel/sca3000.c:734 sca3000_read_raw()
warn: no-op. '((*val) << 19) >> 19'

Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
---
v2: 
Use the right sign bit (thanks Lars!)
Should be bit 12 for a 13 bit value.

 drivers/iio/accel/sca3000.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/iio/accel/sca3000.c b/drivers/iio/accel/sca3000.c
index cb753a43533c..c6b75308148a 100644
--- a/drivers/iio/accel/sca3000.c
+++ b/drivers/iio/accel/sca3000.c
@@ -731,8 +731,7 @@ static int sca3000_read_raw(struct iio_dev *indio_dev,
 				return ret;
 			}
 			*val = (be16_to_cpup((__be16 *)st->rx) >> 3) & 0x1FFF;
-			*val = ((*val) << (sizeof(*val) * 8 - 13)) >>
-				(sizeof(*val) * 8 - 13);
+			*val = sign_extend32(*val, 12);
 		} else {
 			/* get the temperature when available */
 			ret = sca3000_read_data_short(st,
-- 
2.33.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] iio: accel: sca3000: Use sign_extend32() instead of opencoding sign extension.
  2021-10-17 16:03 [PATCH v2] iio: accel: sca3000: Use sign_extend32() instead of opencoding sign extension Jonathan Cameron
@ 2021-10-17 17:17 ` Lars-Peter Clausen
  2021-10-17 17:37   ` Jonathan Cameron
  0 siblings, 1 reply; 3+ messages in thread
From: Lars-Peter Clausen @ 2021-10-17 17:17 UTC (permalink / raw)
  To: Jonathan Cameron, linux-iio; +Cc: Jonathan Cameron, Dan Carpenter

On 10/17/21 6:03 PM, Jonathan Cameron wrote:
> From: Jonathan Cameron <Jonathan.Cameron@huawei.com>
>
> Whilst nice to get rid of this non obvious code, this also clears a
> static checker warning:
>
> drivers/iio/accel/sca3000.c:734 sca3000_read_raw()
> warn: no-op. '((*val) << 19) >> 19'
>
> Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

Reviewed-by: Lars-Peter Clausen <lars@metafoo.de

> ---
> v2:
> Use the right sign bit (thanks Lars!)
> Should be bit 12 for a 13 bit value.
>
>   drivers/iio/accel/sca3000.c | 3 +--
>   1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/drivers/iio/accel/sca3000.c b/drivers/iio/accel/sca3000.c
> index cb753a43533c..c6b75308148a 100644
> --- a/drivers/iio/accel/sca3000.c
> +++ b/drivers/iio/accel/sca3000.c
> @@ -731,8 +731,7 @@ static int sca3000_read_raw(struct iio_dev *indio_dev,
>   				return ret;
>   			}
>   			*val = (be16_to_cpup((__be16 *)st->rx) >> 3) & 0x1FFF;
> -			*val = ((*val) << (sizeof(*val) * 8 - 13)) >>
> -				(sizeof(*val) * 8 - 13);
> +			*val = sign_extend32(*val, 12);
>   		} else {
>   			/* get the temperature when available */
>   			ret = sca3000_read_data_short(st,



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] iio: accel: sca3000: Use sign_extend32() instead of opencoding sign extension.
  2021-10-17 17:17 ` Lars-Peter Clausen
@ 2021-10-17 17:37   ` Jonathan Cameron
  0 siblings, 0 replies; 3+ messages in thread
From: Jonathan Cameron @ 2021-10-17 17:37 UTC (permalink / raw)
  To: Lars-Peter Clausen; +Cc: linux-iio, Jonathan Cameron, Dan Carpenter

On Sun, 17 Oct 2021 19:17:26 +0200
Lars-Peter Clausen <lars@metafoo.de> wrote:

> On 10/17/21 6:03 PM, Jonathan Cameron wrote:
> > From: Jonathan Cameron <Jonathan.Cameron@huawei.com>
> >
> > Whilst nice to get rid of this non obvious code, this also clears a
> > static checker warning:
> >
> > drivers/iio/accel/sca3000.c:734 sca3000_read_raw()
> > warn: no-op. '((*val) << 19) >> 19'
> >
> > Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
> > Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>  
> 
> Reviewed-by: Lars-Peter Clausen <lars@metafoo.de

Added missing > to your tag and applied.  Thanks

Jonathan

> 
> > ---
> > v2:
> > Use the right sign bit (thanks Lars!)
> > Should be bit 12 for a 13 bit value.
> >
> >   drivers/iio/accel/sca3000.c | 3 +--
> >   1 file changed, 1 insertion(+), 2 deletions(-)
> >
> > diff --git a/drivers/iio/accel/sca3000.c b/drivers/iio/accel/sca3000.c
> > index cb753a43533c..c6b75308148a 100644
> > --- a/drivers/iio/accel/sca3000.c
> > +++ b/drivers/iio/accel/sca3000.c
> > @@ -731,8 +731,7 @@ static int sca3000_read_raw(struct iio_dev *indio_dev,
> >   				return ret;
> >   			}
> >   			*val = (be16_to_cpup((__be16 *)st->rx) >> 3) & 0x1FFF;
> > -			*val = ((*val) << (sizeof(*val) * 8 - 13)) >>
> > -				(sizeof(*val) * 8 - 13);
> > +			*val = sign_extend32(*val, 12);
> >   		} else {
> >   			/* get the temperature when available */
> >   			ret = sca3000_read_data_short(st,  
> 
> 


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-10-17 17:32 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-17 16:03 [PATCH v2] iio: accel: sca3000: Use sign_extend32() instead of opencoding sign extension Jonathan Cameron
2021-10-17 17:17 ` Lars-Peter Clausen
2021-10-17 17:37   ` Jonathan Cameron

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.