linux-iio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: SF Markus Elfring <elfring@users.sourceforge.net>
To: linux-iio@vger.kernel.org, Hartmut Knaack <knaack.h@gmx.de>,
	Jonathan Cameron <jic23@kernel.org>,
	Lars-Peter Clausen <lars@metafoo.de>,
	Peter Meerwald-Stadler <pmeerw@pmeerw.net>
Cc: LKML <linux-kernel@vger.kernel.org>, kernel-janitors@vger.kernel.org
Subject: [PATCH] iio/adc/nau7802: Improve unlocking of a mutex in nau7802_read_raw()
Date: Tue, 13 Mar 2018 20:56:25 +0100	[thread overview]
Message-ID: <f2874cab-329b-297f-2b4a-bfc72755123d@users.sourceforge.net> (raw)

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

* Add a jump target so that a call of the function "mutex_unlock" is stored
  only once in this function implementation.

* Replace two calls by goto statements.

This issue was detected by using the Coccinelle software.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 drivers/iio/adc/nau7802.c | 15 +++++----------
 1 file changed, 5 insertions(+), 10 deletions(-)

diff --git a/drivers/iio/adc/nau7802.c b/drivers/iio/adc/nau7802.c
index 8997e74a8847..68d06a492760 100644
--- a/drivers/iio/adc/nau7802.c
+++ b/drivers/iio/adc/nau7802.c
@@ -303,10 +303,8 @@ static int nau7802_read_raw(struct iio_dev *indio_dev,
 		 *   - Channel 2 is value 1 in the CHS register
 		 */
 		ret = i2c_smbus_read_byte_data(st->client, NAU7802_REG_CTRL2);
-		if (ret < 0) {
-			mutex_unlock(&st->lock);
-			return ret;
-		}
+		if (ret < 0)
+			goto unlock;
 
 		if (((ret & NAU7802_CTRL2_CHS_BIT) && !chan->channel) ||
 				(!(ret & NAU7802_CTRL2_CHS_BIT) &&
@@ -316,18 +314,15 @@ static int nau7802_read_raw(struct iio_dev *indio_dev,
 					NAU7802_REG_CTRL2,
 					NAU7802_CTRL2_CHS(chan->channel) |
 					NAU7802_CTRL2_CRS(st->sample_rate));
-
-			if (ret < 0) {
-				mutex_unlock(&st->lock);
-				return ret;
-			}
+			if (ret < 0)
+				goto unlock;
 		}
 
 		if (st->client->irq)
 			ret = nau7802_read_irq(indio_dev, chan, val);
 		else
 			ret = nau7802_read_poll(indio_dev, chan, val);
-
+unlock:
 		mutex_unlock(&st->lock);
 		return ret;
 
-- 
2.16.2

             reply	other threads:[~2018-03-13 19:56 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-03-13 19:56 SF Markus Elfring [this message]
2018-03-18 10:22 ` [PATCH] iio/adc/nau7802: Improve unlocking of a mutex in nau7802_read_raw() 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=f2874cab-329b-297f-2b4a-bfc72755123d@users.sourceforge.net \
    --to=elfring@users.sourceforge.net \
    --cc=jic23@kernel.org \
    --cc=kernel-janitors@vger.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 \
    /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
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).