linux-iio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] iio/accel/kxcjk-1013: Improve unlocking of a mutex in three functions
@ 2018-03-13 12:47 SF Markus Elfring
  2018-03-17 22:30 ` Jonathan Cameron
  0 siblings, 1 reply; 2+ messages in thread
From: SF Markus Elfring @ 2018-03-13 12:47 UTC (permalink / raw)
  To: linux-iio, Hartmut Knaack, Jonathan Cameron, Lars-Peter Clausen,
	Michał Mirosław, Peter Meerwald-Stadler
  Cc: LKML, kernel-janitors

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Tue, 13 Mar 2018 13:40:12 +0100

* Add jump targets so that a call of the function "mutex_unlock" is stored
  less often in these function implementations.

* Replace eight calls by goto statements.

This issue was detected by using the Coccinelle software.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 drivers/iio/accel/kxcjk-1013.c | 46 ++++++++++++++++++------------------------
 1 file changed, 20 insertions(+), 26 deletions(-)

diff --git a/drivers/iio/accel/kxcjk-1013.c b/drivers/iio/accel/kxcjk-1013.c
index af53a1084ee5..4adf38b6d939 100644
--- a/drivers/iio/accel/kxcjk-1013.c
+++ b/drivers/iio/accel/kxcjk-1013.c
@@ -765,19 +765,18 @@ static int kxcjk1013_read_raw(struct iio_dev *indio_dev,
 			ret = -EBUSY;
 		else {
 			ret = kxcjk1013_set_power_state(data, true);
-			if (ret < 0) {
-				mutex_unlock(&data->mutex);
-				return ret;
-			}
+			if (ret < 0)
+				goto unlock;
+
 			ret = kxcjk1013_get_acc_reg(data, chan->scan_index);
 			if (ret < 0) {
 				kxcjk1013_set_power_state(data, false);
-				mutex_unlock(&data->mutex);
-				return ret;
+				goto unlock;
 			}
 			*val = sign_extend32(ret >> 4, 11);
 			ret = kxcjk1013_set_power_state(data, false);
 		}
+unlock:
 		mutex_unlock(&data->mutex);
 
 		if (ret < 0)
@@ -905,8 +904,8 @@ static int kxcjk1013_write_event_config(struct iio_dev *indio_dev,
 
 	if (!state && data->motion_trigger_on) {
 		data->ev_enable_state = 0;
-		mutex_unlock(&data->mutex);
-		return 0;
+		ret = 0;
+		goto unlock;
 	}
 
 	/*
@@ -919,23 +918,20 @@ static int kxcjk1013_write_event_config(struct iio_dev *indio_dev,
 	 * is always on so sequence doesn't matter
 	 */
 	ret = kxcjk1013_set_power_state(data, state);
-	if (ret < 0) {
-		mutex_unlock(&data->mutex);
-		return ret;
-	}
+	if (ret < 0)
+		goto unlock;
 
 	ret =  kxcjk1013_setup_any_motion_interrupt(data, state);
 	if (ret < 0) {
 		kxcjk1013_set_power_state(data, false);
 		data->ev_enable_state = 0;
-		mutex_unlock(&data->mutex);
-		return ret;
+		goto unlock;
 	}
 
 	data->ev_enable_state = state;
+unlock:
 	mutex_unlock(&data->mutex);
-
-	return 0;
+	return ret;
 }
 
 static int kxcjk1013_buffer_preenable(struct iio_dev *indio_dev)
@@ -1086,32 +1082,30 @@ static int kxcjk1013_data_rdy_trigger_set_state(struct iio_trigger *trig,
 
 	if (!state && data->ev_enable_state && data->motion_trigger_on) {
 		data->motion_trigger_on = false;
-		mutex_unlock(&data->mutex);
-		return 0;
+		ret = 0;
+		goto unlock;
 	}
 
 	ret = kxcjk1013_set_power_state(data, state);
-	if (ret < 0) {
-		mutex_unlock(&data->mutex);
-		return ret;
-	}
+	if (ret < 0)
+		goto unlock;
+
 	if (data->motion_trig == trig)
 		ret = kxcjk1013_setup_any_motion_interrupt(data, state);
 	else
 		ret = kxcjk1013_setup_new_data_interrupt(data, state);
 	if (ret < 0) {
 		kxcjk1013_set_power_state(data, false);
-		mutex_unlock(&data->mutex);
-		return ret;
+		goto unlock;
 	}
 	if (data->motion_trig == trig)
 		data->motion_trigger_on = state;
 	else
 		data->dready_trigger_on = state;
 
+unlock:
 	mutex_unlock(&data->mutex);
-
-	return 0;
+	return ret;
 }
 
 static const struct iio_trigger_ops kxcjk1013_trigger_ops = {
-- 
2.16.2

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

end of thread, other threads:[~2018-03-17 22:30 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-03-13 12:47 [PATCH] iio/accel/kxcjk-1013: Improve unlocking of a mutex in three functions SF Markus Elfring
2018-03-17 22:30 ` 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).