Skip to content

Commit 9b1355d

Browse files
josefbacikaxboe
authored andcommitted
nbd: put socket in error cases
When adding a new socket we look it up and then try to add it to our configuration. If any of those steps fail we need to make sure we put the socket so we don't leak them. Signed-off-by: Josef Bacik <[email protected]> Signed-off-by: Jens Axboe <[email protected]>
1 parent 1c6286f commit 9b1355d

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

drivers/block/nbd.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -628,16 +628,21 @@ static int nbd_add_socket(struct nbd_device *nbd, struct block_device *bdev,
628628
if (nbd->task_setup != current) {
629629
dev_err(disk_to_dev(nbd->disk),
630630
"Device being setup by another task");
631+
sockfd_put(sock);
631632
return -EINVAL;
632633
}
633634

634635
socks = krealloc(nbd->socks, (nbd->num_connections + 1) *
635636
sizeof(struct nbd_sock *), GFP_KERNEL);
636-
if (!socks)
637+
if (!socks) {
638+
sockfd_put(sock);
637639
return -ENOMEM;
640+
}
638641
nsock = kzalloc(sizeof(struct nbd_sock), GFP_KERNEL);
639-
if (!nsock)
642+
if (!nsock) {
643+
sockfd_put(sock);
640644
return -ENOMEM;
645+
}
641646

642647
nbd->socks = socks;
643648

0 commit comments

Comments
 (0)