From: SF Markus Elfring <elfring@users.sourceforge.net>
To: linux-block@vger.kernel.org, nbd@other.debian.org,
Josef Bacik <jbacik@fb.com>
Cc: LKML <linux-kernel@vger.kernel.org>, kernel-janitors@vger.kernel.org
Subject: [PATCH] nbd: Use common error handling code in nbd_genl_connect()
Date: Sat, 21 Oct 2017 20:55:20 +0200 [thread overview]
Message-ID: <110a7553-d57c-6a77-a9f7-fdee43a60195@users.sourceforge.net> (raw)
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Sat, 21 Oct 2017 20:50:37 +0200
Add a jump target so that a bit of exception handling can be better reused
at the end of this function.
This issue was detected by using the Coccinelle software.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
drivers/block/nbd.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c
index 883dfebd3014..05bd1fc70ee3 100644
--- a/drivers/block/nbd.c
+++ b/drivers/block/nbd.c
@@ -1585,22 +1585,18 @@ static int nbd_genl_connect(struct sk_buff *skb, struct genl_info *info)
if (ret == 0) {
int new_index;
new_index = nbd_dev_add(-1);
- if (new_index < 0) {
- mutex_unlock(&nbd_index_mutex);
- printk(KERN_ERR "nbd: failed to add new device\n");
- return ret;
- }
+ if (new_index < 0)
+ goto report_failure;
+
nbd = idr_find(&nbd_index_idr, new_index);
}
} else {
nbd = idr_find(&nbd_index_idr, index);
if (!nbd) {
ret = nbd_dev_add(index);
- if (ret < 0) {
- mutex_unlock(&nbd_index_mutex);
- printk(KERN_ERR "nbd: failed to add new device\n");
- return ret;
- }
+ if (ret < 0)
+ goto report_failure;
+
nbd = idr_find(&nbd_index_idr, index);
}
}
@@ -1716,6 +1712,11 @@ static int nbd_genl_connect(struct sk_buff *skb, struct genl_info *info)
if (put_dev)
nbd_put(nbd);
return ret;
+
+report_failure:
+ mutex_unlock(&nbd_index_mutex);
+ pr_err("nbd: failed to add new device\n");
+ return ret;
}
static int nbd_genl_disconnect(struct sk_buff *skb, struct genl_info *info)
--
2.14.2
reply other threads:[~2017-10-21 18:55 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=110a7553-d57c-6a77-a9f7-fdee43a60195@users.sourceforge.net \
--to=elfring@users.sourceforge.net \
--cc=jbacik@fb.com \
--cc=kernel-janitors@vger.kernel.org \
--cc=linux-block@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=nbd@other.debian.org \
/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).