Skip to contentSkip to conversation

staging: iio: accel: adis16240: Improve readability on write_raw function

PATCH In review Rodrigo Ribeiro 3 participants 3 messages Aug 13, 2019 – Aug 18, 2019

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 staging: iio: accel: adis16240: Improve readability on write_raw function

Replace shift and minus operation by GENMASK macro and remove the local variables used to store intermediate data.

---
v2:
- Leave switch statement instead of replace by if statement

 drivers/staging/iio/accel/adis16240.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
drivers/staging/iio/accel/adis16240.c +1 -4
index 62f4b3b1b457..82099db4bf0c 100644
@@ -309,15 +309,12 @@ static int adis16240_write_raw(struct iio_dev *indio_dev,
 			       long mask)
 {
 	struct adis *st = iio_priv(indio_dev);
-	int bits = 10;
-	s16 val16;
 	u8 addr;
 
 	switch (mask) {
 	case IIO_CHAN_INFO_CALIBBIAS:
-		val16 = val & ((1 << bits) - 1);
 		addr = adis16240_addresses[chan->scan_index][0];
-		return adis_write_reg_16(st, addr, val16);
+		return adis_write_reg_16(st, addr, val & GENMASK(9, 0));
 	}
 	return -EINVAL;
 }
Signature · 1 line
2.20.1
Reviewed-by on v2 1/1
#1 lore raw
Quoted 5 lines · Rodrigo Ribeiro

[External]

Replace shift and minus operation by GENMASK macro and remove the local variables used to store intermediate data.

Quoted 28 lines

---
v2:
- Leave switch statement instead of replace by if statement

 drivers/staging/iio/accel/adis16240.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
drivers/staging/iio/accel/adis16240.c +1 -4
index 62f4b3b1b457..82099db4bf0c 100644
@@ -309,15 +309,12 @@ static int adis16240_write_raw(struct iio_dev *indio_dev,
 			       long mask)
 {
 	struct adis *st = iio_priv(indio_dev);
-	int bits = 10;
-	s16 val16;
 	u8 addr;
 
 	switch (mask) {
 	case IIO_CHAN_INFO_CALIBBIAS:
-		val16 = val & ((1 << bits) - 1);
 		addr = adis16240_addresses[chan->scan_index][0];
-		return adis_write_reg_16(st, addr, val16);
+		return adis_write_reg_16(st, addr, val & GENMASK(9, 0));
 	}
 	return -EINVAL;
 }
maintainer
#2 lore raw
Quoted 8 lines · Alexandru
Quoted 5 lines · Rodrigo Ribeiro

[External]

Replace shift and minus operation by GENMASK macro and remove the local variables used to store intermediate data.

Applied to the togreg branch of iio.git and pushed out as testing for the autobuilders to play with it.

Thanks,

Jonathan

Quoted 29 lines
Quoted 29 lines

---
v2:
- Leave switch statement instead of replace by if statement

 drivers/staging/iio/accel/adis16240.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
drivers/staging/iio/accel/adis16240.c +1 -4
index 62f4b3b1b457..82099db4bf0c 100644
@@ -309,15 +309,12 @@ static int adis16240_write_raw(struct iio_dev *indio_dev,
 			       long mask)
 {
 	struct adis *st = iio_priv(indio_dev);
-	int bits = 10;
-	s16 val16;
 	u8 addr;
 
 	switch (mask) {
 	case IIO_CHAN_INFO_CALIBBIAS:
-		val16 = val & ((1 << bits) - 1);
 		addr = adis16240_addresses[chan->scan_index][0];
-		return adis_write_reg_16(st, addr, val16);
+		return adis_write_reg_16(st, addr, val & GENMASK(9, 0));
 	}
 	return -EINVAL;
 }