diff mbox series

[v6,2/2] nbd: share nbd_put and return by goto put_nbd

Message ID 20210218122620.228375-3-sunke32@huawei.com (mailing list archive)
State New, archived
Headers show
Series fix a NULL pointer bug and simplify the code | expand

Commit Message

Sun Ke Feb. 18, 2021, 12:26 p.m. UTC
Replace the following two statements by the statement “goto put_nbd;”

	nbd_put(nbd);
	return 0;

Suggested-by: Markus Elfring <Markus.Elfring@web.de>
Signed-off-by: Sun Ke <sunke32@huawei.com>
---
 drivers/block/nbd.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
diff mbox series

Patch

diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c
index 403c1e1fe748..10cbb5caad07 100644
--- a/drivers/block/nbd.c
+++ b/drivers/block/nbd.c
@@ -2027,12 +2027,11 @@  static int nbd_genl_disconnect(struct sk_buff *skb, struct genl_info *info)
 		return -EINVAL;
 	}
 	mutex_unlock(&nbd_index_mutex);
-	if (!refcount_inc_not_zero(&nbd->config_refs)) {
-		nbd_put(nbd);
-		return 0;
-	}
+	if (!refcount_inc_not_zero(&nbd->config_refs))
+		goto put_nbd;
 	nbd_disconnect_and_put(nbd);
 	nbd_config_put(nbd);
+put_nbd:
 	nbd_put(nbd);
 	return 0;
 }