* [PATCH RESEND] nbd: code clean for nbd_genl_status()
@ 2021-11-04 4:38 Wu Bo
2021-11-04 8:48 ` Christoph Hellwig
2021-11-05 10:01 ` Josef Bacik
0 siblings, 2 replies; 4+ messages in thread
From: Wu Bo @ 2021-11-04 4:38 UTC (permalink / raw)
To: josef, axboe; +Cc: linux-block, nbd, linux-kernel, linfeilong, wubo40
A simple code clean for nbd_genl_status()
Signed-off-by: Wu Bo <wubo40@huawei.com>
---
drivers/block/nbd.c | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c
index b47b2a8..175ea97 100644
--- a/drivers/block/nbd.c
+++ b/drivers/block/nbd.c
@@ -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;
}
--
1.8.3.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH RESEND] nbd: code clean for nbd_genl_status()
2021-11-04 4:38 [PATCH RESEND] nbd: code clean for nbd_genl_status() Wu Bo
@ 2021-11-04 8:48 ` Christoph Hellwig
2021-11-05 1:46 ` Wu Bo
2021-11-05 10:01 ` Josef Bacik
1 sibling, 1 reply; 4+ messages in thread
From: Christoph Hellwig @ 2021-11-04 8:48 UTC (permalink / raw)
To: Wu Bo; +Cc: josef, axboe, linux-block, nbd, linux-kernel, linfeilong
On Thu, Nov 04, 2021 at 12:38:23PM +0800, Wu Bo wrote:
> if (!reply_head) {
> - nlmsg_free(reply);
> goto out;
> }
Please also drop the now pointless braces.
> out:
> + if (reply)
> + nlmsg_free(reply);
Please just use a different label for just unlocking vs also freeing
the reply.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH RESEND] nbd: code clean for nbd_genl_status()
2021-11-04 8:48 ` Christoph Hellwig
@ 2021-11-05 1:46 ` Wu Bo
0 siblings, 0 replies; 4+ messages in thread
From: Wu Bo @ 2021-11-05 1:46 UTC (permalink / raw)
To: Christoph Hellwig
Cc: josef, axboe, linux-block, nbd, linux-kernel, linfeilong
On 2021/11/4 16:48, Christoph Hellwig wrote:
> On Thu, Nov 04, 2021 at 12:38:23PM +0800, Wu Bo wrote:
>> if (!reply_head) {
>> - nlmsg_free(reply);
>> goto out;
>> }
>
> Please also drop the now pointless braces.
>
ok. Will do in v2.
>> out:
>> + 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
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH RESEND] nbd: code clean for nbd_genl_status()
2021-11-04 4:38 [PATCH RESEND] nbd: code clean for nbd_genl_status() Wu Bo
2021-11-04 8:48 ` Christoph Hellwig
@ 2021-11-05 10:01 ` Josef Bacik
1 sibling, 0 replies; 4+ messages in thread
From: Josef Bacik @ 2021-11-05 10:01 UTC (permalink / raw)
To: Wu Bo; +Cc: axboe, linux-block, nbd, linux-kernel, linfeilong
On Thu, Nov 04, 2021 at 12:38:23PM +0800, Wu Bo wrote:
> A simple code clean for nbd_genl_status()
>
> Signed-off-by: Wu Bo <wubo40@huawei.com>
This isn't ok, genlmsg_reply() free's the reply, this introduces a double free.
Thanks,
Josef
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2021-11-05 10:01 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-04 4:38 [PATCH RESEND] nbd: code clean for nbd_genl_status() Wu Bo
2021-11-04 8:48 ` Christoph Hellwig
2021-11-05 1:46 ` Wu Bo
2021-11-05 10:01 ` Josef Bacik
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).