lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Date:   Sat, 28 Oct 2017 17:18:56 +0200
From:   SF Markus Elfring <elfring@...rs.sourceforge.net>
To:     netdev@...r.kernel.org, oss-drivers@...ronome.com,
        "David S. Miller" <davem@...emloft.net>,
        Jakub Kicinski <jakub.kicinski@...ronome.com>,
        Simon Horman <simon.horman@...ronome.com>
Cc:     LKML <linux-kernel@...r.kernel.org>,
        kernel-janitors@...r.kernel.org
Subject: [PATCH] nfp: Improve unlocking of a mutex in area_cache_get()

From: Markus Elfring <elfring@...rs.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@...rs.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

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ