Skip to content

Commit

Permalink
nbd: put socket in error cases
Browse files Browse the repository at this point in the history
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 <jbacik@fb.com>
Signed-off-by: Jens Axboe <axboe@fb.com>
  • Loading branch information
Josef Bacik authored and Jens Axboe committed Apr 17, 2017
1 parent 1c6286f commit 9b1355d
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions drivers/block/nbd.c
Original file line number Diff line number Diff line change
Expand Up @@ -628,16 +628,21 @@ static int nbd_add_socket(struct nbd_device *nbd, struct block_device *bdev,
if (nbd->task_setup != current) {
dev_err(disk_to_dev(nbd->disk),
"Device being setup by another task");
sockfd_put(sock);
return -EINVAL;
}

socks = krealloc(nbd->socks, (nbd->num_connections + 1) *
sizeof(struct nbd_sock *), GFP_KERNEL);
if (!socks)
if (!socks) {
sockfd_put(sock);
return -ENOMEM;
}
nsock = kzalloc(sizeof(struct nbd_sock), GFP_KERNEL);
if (!nsock)
if (!nsock) {
sockfd_put(sock);
return -ENOMEM;
}

nbd->socks = socks;

Expand Down

0 comments on commit 9b1355d

Please sign in to comment.