Commit 9b1355d5 authored by Josef Bacik's avatar Josef Bacik Committed by Jens Axboe

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: default avatarJosef Bacik <jbacik@fb.com>
Signed-off-by: default avatarJens Axboe <axboe@fb.com>
parent 1c6286f2
...@@ -628,16 +628,21 @@ static int nbd_add_socket(struct nbd_device *nbd, struct block_device *bdev, ...@@ -628,16 +628,21 @@ static int nbd_add_socket(struct nbd_device *nbd, struct block_device *bdev,
if (nbd->task_setup != current) { if (nbd->task_setup != current) {
dev_err(disk_to_dev(nbd->disk), dev_err(disk_to_dev(nbd->disk),
"Device being setup by another task"); "Device being setup by another task");
sockfd_put(sock);
return -EINVAL; return -EINVAL;
} }
socks = krealloc(nbd->socks, (nbd->num_connections + 1) * socks = krealloc(nbd->socks, (nbd->num_connections + 1) *
sizeof(struct nbd_sock *), GFP_KERNEL); sizeof(struct nbd_sock *), GFP_KERNEL);
if (!socks) if (!socks) {
sockfd_put(sock);
return -ENOMEM; return -ENOMEM;
}
nsock = kzalloc(sizeof(struct nbd_sock), GFP_KERNEL); nsock = kzalloc(sizeof(struct nbd_sock), GFP_KERNEL);
if (!nsock) if (!nsock) {
sockfd_put(sock);
return -ENOMEM; return -ENOMEM;
}
nbd->socks = socks; nbd->socks = socks;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment