Skip to contentSkip to conversation

iio: accel: sca3000: Use sign_extend32() instead of opencoding sign extension.

PATCH In review Jonathan Cameron 2 participants 3 messages Oct 17, 2021 IIO

lore
Share & tools
lore

Jonathan Cameron

author maintainer
#0 lore raw

PATCH v2 1/1 iio: accel: sca3000: Use sign_extend32() instead of opencoding sign extension.

From: Jonathan Cameron <[email protected]>

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'

---
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(-)
drivers/iio/accel/sca3000.c +1 -2
index cb753a43533c..c6b75308148a 100644
@@ -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,
Signature · 1 line
2.33.1
Reviewed-by on v2 1/1
#1 lore raw
Quoted 10 lines · Jonathan Cameron

From: Jonathan Cameron <[email protected]>

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'

Quoted 22 lines

---
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(-)
drivers/iio/accel/sca3000.c +1 -2
index cb753a43533c..c6b75308148a 100644
@@ -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,
author maintainer
#2 lore raw
Quoted 6 lines · On Sun, 17 Oct 2021 19:17:26 +0200 Lars-Peter Clausen <[email protected]> wrote:
Quoted 5 lines · Jonathan Cameron

From: Jonathan Cameron <[email protected]>

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

Quoted 7 lines
Quoted 5 lines

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

Added missing > to your tag and applied. Thanks

Jonathan

Quoted 25 lines
Quoted 23 lines

---
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(-)
drivers/iio/accel/sca3000.c +1 -2
index cb753a43533c..c6b75308148a 100644
@@ -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,