LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Brian Masney <masneyb@onstation.org>
To: jic23@kernel.org, linux-iio@vger.kernel.org
Cc: devel@driverdev.osuosl.org, lars@metafoo.de,
	gregkh@linuxfoundation.org, linux-kernel@vger.kernel.org,
	pmeerw@pmeerw.net, knaack.h@gmx.de, drew.paterson@ams.com
Subject: [PATCH v3 2/9] staging: iio: tsl2x7x: use direct returns
Date: Thu, 10 May 2018 20:12:16 -0400	[thread overview]
Message-ID: <20180511001223.12378-3-masneyb@onstation.org> (raw)
In-Reply-To: <20180511001223.12378-1-masneyb@onstation.org>

This patch changes the functions tsl2x7x_read_event_value() and
tsl2x7x_read_raw() to use direct returns to simplify the code.

Signed-off-by: Brian Masney <masneyb@onstation.org>
---
 drivers/staging/iio/light/tsl2x7x.c | 49 ++++++++++++-------------------------
 1 file changed, 16 insertions(+), 33 deletions(-)

diff --git a/drivers/staging/iio/light/tsl2x7x.c b/drivers/staging/iio/light/tsl2x7x.c
index 3ae2fd19ae9c..c1e726fc87b7 100644
--- a/drivers/staging/iio/light/tsl2x7x.c
+++ b/drivers/staging/iio/light/tsl2x7x.c
@@ -1014,7 +1014,7 @@ static int tsl2x7x_read_event_value(struct iio_dev *indio_dev,
 				    int *val, int *val2)
 {
 	struct tsl2X7X_chip *chip = iio_priv(indio_dev);
-	int ret = -EINVAL, filter_delay, mult;
+	int filter_delay, mult;
 	u8 time;
 
 	switch (info) {
@@ -1023,27 +1023,23 @@ static int tsl2x7x_read_event_value(struct iio_dev *indio_dev,
 			switch (dir) {
 			case IIO_EV_DIR_RISING:
 				*val = chip->settings.als_thresh_high;
-				ret = IIO_VAL_INT;
-				break;
+				return IIO_VAL_INT;
 			case IIO_EV_DIR_FALLING:
 				*val = chip->settings.als_thresh_low;
-				ret = IIO_VAL_INT;
-				break;
+				return IIO_VAL_INT;
 			default:
-				break;
+				return -EINVAL;
 			}
 		} else {
 			switch (dir) {
 			case IIO_EV_DIR_RISING:
 				*val = chip->settings.prox_thres_high;
-				ret = IIO_VAL_INT;
-				break;
+				return IIO_VAL_INT;
 			case IIO_EV_DIR_FALLING:
 				*val = chip->settings.prox_thres_low;
-				ret = IIO_VAL_INT;
-				break;
+				return IIO_VAL_INT;
 			default:
-				break;
+				return -EINVAL;
 			}
 		}
 		break;
@@ -1062,13 +1058,10 @@ static int tsl2x7x_read_event_value(struct iio_dev *indio_dev,
 		filter_delay = *val2 * mult;
 		*val = filter_delay / 1000;
 		*val2 = filter_delay % 1000;
-		ret = IIO_VAL_INT_PLUS_MICRO;
-		break;
+		return IIO_VAL_INT_PLUS_MICRO;
 	default:
-		break;
+		return -EINVAL;
 	}
-
-	return ret;
 }
 
 static int tsl2x7x_read_raw(struct iio_dev *indio_dev,
@@ -1078,7 +1071,6 @@ static int tsl2x7x_read_raw(struct iio_dev *indio_dev,
 			    long mask)
 {
 	struct tsl2X7X_chip *chip = iio_priv(indio_dev);
-	int ret = -EINVAL;
 
 	switch (mask) {
 	case IIO_CHAN_INFO_PROCESSED:
@@ -1086,12 +1078,10 @@ static int tsl2x7x_read_raw(struct iio_dev *indio_dev,
 		case IIO_LIGHT:
 			tsl2x7x_get_lux(indio_dev);
 			*val = chip->als_cur_info.lux;
-			ret = IIO_VAL_INT;
-			break;
+			return IIO_VAL_INT;
 		default:
 			return -EINVAL;
 		}
-		break;
 	case IIO_CHAN_INFO_RAW:
 		switch (chan->type) {
 		case IIO_INTENSITY:
@@ -1100,13 +1090,11 @@ static int tsl2x7x_read_raw(struct iio_dev *indio_dev,
 				*val = chip->als_cur_info.als_ch0;
 			else
 				*val = chip->als_cur_info.als_ch1;
-			ret = IIO_VAL_INT;
-			break;
+			return IIO_VAL_INT;
 		case IIO_PROXIMITY:
 			tsl2x7x_get_prox(indio_dev);
 			*val = chip->prox_data;
-			ret = IIO_VAL_INT;
-			break;
+			return IIO_VAL_INT;
 		default:
 			return -EINVAL;
 		}
@@ -1116,22 +1104,17 @@ static int tsl2x7x_read_raw(struct iio_dev *indio_dev,
 			*val = tsl2x7x_als_gain[chip->settings.als_gain];
 		else
 			*val = tsl2x7x_prox_gain[chip->settings.prox_gain];
-		ret = IIO_VAL_INT;
-		break;
+		return IIO_VAL_INT;
 	case IIO_CHAN_INFO_CALIBBIAS:
 		*val = chip->settings.als_gain_trim;
-		ret = IIO_VAL_INT;
-		break;
+		return IIO_VAL_INT;
 	case IIO_CHAN_INFO_INT_TIME:
 		*val = 0;
 		*val2 = (256 - chip->settings.als_time) * 2720;
-		ret = IIO_VAL_INT_PLUS_MICRO;
-		break;
+		return IIO_VAL_INT_PLUS_MICRO;
 	default:
-		ret = -EINVAL;
+		return -EINVAL;
 	}
-
-	return ret;
 }
 
 static int tsl2x7x_write_raw(struct iio_dev *indio_dev,
-- 
2.14.3

_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

  parent reply	other threads:[~2018-05-11  0:12 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-11  0:12 [PATCH v3 0/9] staging: iio: tsl2x7x: move out of staging Brian Masney
2018-05-11  0:12 ` [PATCH v3 1/9] staging: iio: tsl2x7x: remove unnecessary whitespace Brian Masney
2018-05-12 11:15   ` Jonathan Cameron
2018-05-11  0:12 ` Brian Masney [this message]
2018-05-12 11:16   ` [PATCH v3 2/9] staging: iio: tsl2x7x: use direct returns Jonathan Cameron
2018-05-11  0:12 ` [PATCH v3 3/9] staging: iio: tsl2x7x: turn chip off if IIO device registration fails Brian Masney
2018-05-12 11:16   ` Jonathan Cameron
2018-05-11  0:12 ` [PATCH v3 4/9] staging: iio: tsl2x7x: use macro to populate tsl2X7X_device_info Brian Masney
2018-05-12 11:20   ` Jonathan Cameron
2018-05-11  0:12 ` [PATCH v3 5/9] staging: iio: tsl2x7x: convert to use read_avail Brian Masney
2018-05-12 11:20   ` Jonathan Cameron
2018-05-11  0:12 ` [PATCH v3 6/9] staging: iio: tsl2x7x: correct IIO_EV_INFO_PERIOD values Brian Masney
2018-05-12 11:21   ` Jonathan Cameron
2018-05-11  0:12 ` [PATCH v3 7/9] staging: iio: tsl2x7x: add range checking to tsl2x7x_write_raw Brian Masney
2018-05-12 11:23   ` Jonathan Cameron
2018-05-11  0:12 ` [PATCH v3 8/9] staging: iio: tsl2x7x: rename driver to tsl2772 Brian Masney
2018-05-12 11:25   ` Jonathan Cameron
2018-05-11  0:12 ` [PATCH v3 9/9] staging: iio: tsl2x7x/tsl2772: move out of staging Brian Masney
2018-05-11  0:32   ` Brian Masney
2018-05-12 11:44     ` Jonathan Cameron
2018-05-12 12:36       ` Brian Masney
2018-05-12 17:44         ` Jonathan Cameron

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180511001223.12378-3-masneyb@onstation.org \
    --to=masneyb@onstation.org \
    --cc=devel@driverdev.osuosl.org \
    --cc=drew.paterson@ams.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=jic23@kernel.org \
    --cc=knaack.h@gmx.de \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pmeerw@pmeerw.net \
    --subject='Re: [PATCH v3 2/9] staging: iio: tsl2x7x: use direct returns' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

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).