linux-iio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] iio/pressure/mpl3115: Improve unlocking of a mutex in mpl3115_trigger_handler()
@ 2017-10-26 14:23 SF Markus Elfring
  2017-10-26 16:21 ` Jonathan Cameron
  0 siblings, 1 reply; 2+ messages in thread
From: SF Markus Elfring @ 2017-10-26 14:23 UTC (permalink / raw)
  To: linux-iio, Hartmut Knaack, Jonathan Cameron, Lars-Peter Clausen,
	Peter Meerwald-Stadler, Peter Rosin
  Cc: LKML, kernel-janitors

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Thu, 26 Oct 2017 16:10:46 +0200

Adjust jump targets so that a call of the function "mutex_unlock" is stored
at the end of this function implementation.
Replace three calls by goto statements.

This issue was detected by using the Coccinelle software.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 drivers/iio/pressure/mpl3115.c | 26 ++++++++++++--------------
 1 file changed, 12 insertions(+), 14 deletions(-)

diff --git a/drivers/iio/pressure/mpl3115.c b/drivers/iio/pressure/mpl3115.c
index 7537547fb7ee..f39e6f42a9c0 100644
--- a/drivers/iio/pressure/mpl3115.c
+++ b/drivers/iio/pressure/mpl3115.c
@@ -152,38 +152,36 @@ static irqreturn_t mpl3115_trigger_handler(int irq, void *p)
 
 	mutex_lock(&data->lock);
 	ret = mpl3115_request(data);
-	if (ret < 0) {
-		mutex_unlock(&data->lock);
-		goto done;
-	}
+	if (ret < 0)
+		goto unlock;
 
 	memset(buffer, 0, sizeof(buffer));
 	if (test_bit(0, indio_dev->active_scan_mask)) {
 		ret = i2c_smbus_read_i2c_block_data(data->client,
 			MPL3115_OUT_PRESS, 3, &buffer[pos]);
-		if (ret < 0) {
-			mutex_unlock(&data->lock);
-			goto done;
-		}
+		if (ret < 0)
+			goto unlock;
+
 		pos += 4;
 	}
 
 	if (test_bit(1, indio_dev->active_scan_mask)) {
 		ret = i2c_smbus_read_i2c_block_data(data->client,
 			MPL3115_OUT_TEMP, 2, &buffer[pos]);
-		if (ret < 0) {
-			mutex_unlock(&data->lock);
-			goto done;
-		}
+		if (ret < 0)
+			goto unlock;
 	}
 	mutex_unlock(&data->lock);
 
 	iio_push_to_buffers_with_timestamp(indio_dev, buffer,
 		iio_get_time_ns(indio_dev));
-
-done:
+notify_trigger:
 	iio_trigger_notify_done(indio_dev->trig);
 	return IRQ_HANDLED;
+
+unlock:
+	mutex_unlock(&data->lock);
+	goto notify_trigger;
 }
 
 static const struct iio_chan_spec mpl3115_channels[] = {
-- 
2.14.3

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

end of thread, other threads:[~2017-10-26 16:21 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-10-26 14:23 [PATCH] iio/pressure/mpl3115: Improve unlocking of a mutex in mpl3115_trigger_handler() SF Markus Elfring
2017-10-26 16:21 ` 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).