* [PATCH] nfp: Improve unlocking of a mutex in area_cache_get()
@ 2017-10-28 15:18 SF Markus Elfring
2017-10-28 17:04 ` Jakub Kicinski
0 siblings, 1 reply; 2+ messages in thread
From: SF Markus Elfring @ 2017-10-28 15:18 UTC (permalink / raw)
To: netdev, oss-drivers, David S. Miller, Jakub Kicinski, Simon Horman
Cc: LKML, kernel-janitors
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
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] nfp: Improve unlocking of a mutex in area_cache_get()
2017-10-28 15:18 [PATCH] nfp: Improve unlocking of a mutex in area_cache_get() SF Markus Elfring
@ 2017-10-28 17:04 ` Jakub Kicinski
0 siblings, 0 replies; 2+ messages in thread
From: Jakub Kicinski @ 2017-10-28 17:04 UTC (permalink / raw)
To: SF Markus Elfring
Cc: netdev, oss-drivers, David S. Miller, Simon Horman, LKML,
kernel-janitors
On Sat, 28 Oct 2017 17:18:56 +0200, SF Markus Elfring wrote:
> 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>
Acked-by: Jakub Kicinski <jakub.kicinski@netronome.com>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2017-10-28 17:04 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-10-28 15:18 [PATCH] nfp: Improve unlocking of a mutex in area_cache_get() SF Markus Elfring
2017-10-28 17:04 ` Jakub Kicinski
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).