Skip to contentSkip to conversation

nbd: code clean for nbd_genl_status()

PATCH RESEND In review Wu Bo 3 participants 4 messages Nov 4, 2021 – Nov 5, 2021

Subsystems (2)
lore
Share & tools
lore

Wu Bo

author
#0 lore raw

PATCH RESEND 1/1 nbd: code clean for nbd_genl_status()

A simple code clean for nbd_genl_status()

---
 drivers/block/nbd.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/block/nbd.c +2 -3
index b47b2a8..175ea97 100644
@@ -2375,7 +2375,6 @@ static int nbd_genl_status(struct sk_buff *skb, struct genl_info *info)
 	reply_head = genlmsg_put_reply(reply, info, &nbd_genl_family, 0,
 				       NBD_CMD_STATUS);
 	if (!reply_head) {
-		nlmsg_free(reply);
 		goto out;
 	}
 
@@ -2383,7 +2382,6 @@ static int nbd_genl_status(struct sk_buff *skb, struct genl_info *info)
 	if (index == -1) {
 		ret = idr_for_each(&nbd_index_idr, &status_cb, reply);
 		if (ret) {
-			nlmsg_free(reply);
 			goto out;
 		}
 	} else {
@@ -2392,7 +2390,6 @@ static int nbd_genl_status(struct sk_buff *skb, struct genl_info *info)
 		if (nbd) {
 			ret = populate_nbd_status(nbd, reply);
 			if (ret) {
-				nlmsg_free(reply);
 				goto out;
 			}
 		}
@@ -2401,6 +2398,8 @@ static int nbd_genl_status(struct sk_buff *skb, struct genl_info *info)
 	genlmsg_end(reply, reply_head);
 	ret = genlmsg_reply(reply, info);
 out:
+	if (reply)
+		nlmsg_free(reply);
 	mutex_unlock(&nbd_index_mutex);
 	return ret;
 }
Signature · 1 line
1.8.3.1
#1 lore raw

drivers/block/nbd.c static int nbd_genl_status(struct sk_buff *skb, struct genl_info *info) · line 2379

Quoted 4 lines · Wu Bo
drivers/block/nbd.c +0 -1
 	if (!reply_head) {
-		nlmsg_free(reply);
 		goto out;
 	}

Please also drop the now pointless braces.

drivers/block/nbd.c static int nbd_genl_status(struct sk_buff *skb, struct genl_info *info) · line 2402

Quoted 3 lines

out:

drivers/block/nbd.c +2 -0
+	if (reply)
+		nlmsg_free(reply);

Please just use a different label for just unlocking vs also freeing the reply.

author
#2 lore raw
Quoted 8 lines · Christoph Hellwig

drivers/block/nbd.c static int nbd_genl_status(struct sk_buff *skb, struct genl_info *info) · line 2379

Quoted 4 lines · Wu Bo
  	if (!reply_head) {
drivers/block/nbd.c +0 -1
-		nlmsg_free(reply);
  		goto out;
  	}

Please also drop the now pointless braces.

ok. Will do in v2.

Quoted 7 lines

drivers/block/nbd.c static int nbd_genl_status(struct sk_buff *skb, struct genl_info *info) · line 2402

Quoted 3 lines

out:

drivers/block/nbd.c +2 -0
+	if (reply)
+		nlmsg_free(reply);

Please just use a different label for just unlocking vs also freeing the reply.
.

ok. Will do in v2.

Thanks.

Wu Bo