mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: SF Markus Elfring <elfring@users.sourceforge.net>
To: netdev@vger.kernel.org, oss-drivers@netronome.com,
	"David S. Miller" <davem@davemloft.net>,
	Jakub Kicinski <jakub.kicinski@netronome.com>,
	Simon Horman <simon.horman@netronome.com>
Cc: LKML <linux-kernel@vger.kernel.org>, kernel-janitors@vger.kernel.org
Subject: [PATCH] nfp: Improve unlocking of a mutex in area_cache_get()
Date: Sat, 28 Oct 2017 17:18:56 +0200	[thread overview]
Message-ID: <b543c761-6931-ad0a-f12c-c2152c7bcd72@users.sourceforge.net> (raw)

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Sat, 28 Oct 2017 17:12:10 +0200

Add a jump target so that a call of the function "mutex_unlock" is stored
only once at the end of this function implementation.
Replace four calls by goto statements.

This issue was detected by using the Coccinelle software.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 .../ethernet/netronome/nfp/nfpcore/nfp_cppcore.c   | 28 ++++++++++------------
 1 file changed, 12 insertions(+), 16 deletions(-)

diff --git a/drivers/net/ethernet/netronome/nfp/nfpcore/nfp_cppcore.c b/drivers/net/ethernet/netronome/nfp/nfpcore/nfp_cppcore.c
index 04dd5758ecf5..e864793b7ca0 100644
--- a/drivers/net/ethernet/netronome/nfp/nfpcore/nfp_cppcore.c
+++ b/drivers/net/ethernet/netronome/nfp/nfpcore/nfp_cppcore.c
@@ -822,10 +822,8 @@ area_cache_get(struct nfp_cpp *cpp, u32 id,
 
 	mutex_lock(&cpp->area_cache_mutex);
 
-	if (list_empty(&cpp->area_cache_list)) {
-		mutex_unlock(&cpp->area_cache_mutex);
-		return NULL;
-	}
+	if (list_empty(&cpp->area_cache_list))
+		goto unlock;
 
 	addr += *offset;
 
@@ -843,10 +841,8 @@ area_cache_get(struct nfp_cpp *cpp, u32 id,
 
 	/* Can we fit in the cache entry? */
 	if (round_down(addr + length - 1, cache->size) !=
-	    round_down(addr, cache->size)) {
-		mutex_unlock(&cpp->area_cache_mutex);
-		return NULL;
-	}
+	    round_down(addr, cache->size))
+		goto unlock;
 
 	/* If id != 0, we will need to release it */
 	if (cache->id) {
@@ -863,23 +859,23 @@ area_cache_get(struct nfp_cpp *cpp, u32 id,
 	if (cpp->op->area_init) {
 		err = cpp->op->area_init(cache->area,
 					 id, cache->addr, cache->size);
-		if (err < 0) {
-			mutex_unlock(&cpp->area_cache_mutex);
-			return NULL;
-		}
+		if (err < 0)
+			goto unlock;
 	}
 
 	/* Attempt to acquire */
 	err = nfp_cpp_area_acquire(cache->area);
-	if (err < 0) {
-		mutex_unlock(&cpp->area_cache_mutex);
-		return NULL;
-	}
+	if (err < 0)
+		goto unlock;
 
 exit:
 	/* Adjust offset */
 	*offset = addr - cache->addr;
 	return cache;
+
+unlock:
+	mutex_unlock(&cpp->area_cache_mutex);
+	return NULL;
 }
 
 static void
-- 
2.14.3

             reply	other threads:[~2017-10-28 15:19 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-10-28 15:18 SF Markus Elfring [this message]
2017-10-28 17:04 ` Jakub Kicinski

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=b543c761-6931-ad0a-f12c-c2152c7bcd72@users.sourceforge.net \
    --to=elfring@users.sourceforge.net \
    --cc=davem@davemloft.net \
    --cc=jakub.kicinski@netronome.com \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=oss-drivers@netronome.com \
    --cc=simon.horman@netronome.com \
    /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

all inboxes | Powered by JetHome®