linux-iio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] staging: iio: accel: adis16240: Improve readability on write_raw function
@ 2019-08-10 15:00 Rodrigo
  2019-08-11  8:43 ` Jonathan Cameron
  0 siblings, 1 reply; 4+ messages in thread
From: Rodrigo @ 2019-08-10 15:00 UTC (permalink / raw)
  To: Lars-Peter Clausen, Michael Hennerich, Stefan Popa,
	Jonathan Cameron, Hartmut Knaack, Peter Meerwald-Stadler,
	Greg Kroah-Hartman
  Cc: linux-iio, devel, linux-kernel, kernel-usp, Rodrigo Carvalho

From: Rodrigo Carvalho <rodrigorsdc@gmail.com>

Improve readability by using GENMASK macro, changing switch statement
by if statement and removing unnecessary local variables.

Signed-off-by: Rodrigo Ribeiro Carvalho <rodrigorsdc@gmail.com>
---
 drivers/staging/iio/accel/adis16240.c | 16 +++++++---------
 1 file changed, 7 insertions(+), 9 deletions(-)

diff --git a/drivers/staging/iio/accel/adis16240.c b/drivers/staging/iio/accel/adis16240.c
index 62f4b3b1b457..68f165501389 100644
--- a/drivers/staging/iio/accel/adis16240.c
+++ b/drivers/staging/iio/accel/adis16240.c
@@ -309,17 +309,15 @@ static int adis16240_write_raw(struct iio_dev *indio_dev,
 			       long mask)
 {
 	struct adis *st = iio_priv(indio_dev);
-	int bits = 10;
-	s16 val16;
+	int m;
 	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 -EINVAL;
+	if (mask != IIO_CHAN_INFO_CALIBBIAS)
+		return -EINVAL;
+
+	m = GENMASK(9, 0);
+	addr = adis16240_addresses[chan->scan_index][0];
+	return adis_write_reg_16(st, addr, val & m);
 }
 
 static const struct iio_chan_spec adis16240_channels[] = {
-- 
2.20.1


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

end of thread, other threads:[~2019-08-12  8:57 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-10 15:00 [PATCH] staging: iio: accel: adis16240: Improve readability on write_raw function Rodrigo
2019-08-11  8:43 ` Jonathan Cameron
2019-08-11 16:47   ` Rodrigo Ribeiro
2019-08-12  8:57     ` Jonathan Cameron

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).