summaryrefslogtreecommitdiffstats
path: root/drivers/block/nbd.c
diff options
context:
space:
mode:
authorJosef Bacik <josef@toxicpanda.com>2017-04-06 17:01:56 -0400
committerJens Axboe <axboe@fb.com>2017-04-17 09:58:42 -0600
commit9b1355d5e3f094ef671033f38c4357cd1455c571 (patch)
tree738f0b07a052441761b4ed4e37c761c4dd58da6f /drivers/block/nbd.c
parent1c6286f26301ad154a1c10fb6e68925493dd28ba (diff)
downloadlinux-9b1355d5e3f094ef671033f38c4357cd1455c571.tar.bz2
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 <jbacik@fb.com> Signed-off-by: Jens Axboe <axboe@fb.com>
Diffstat (limited to 'drivers/block/nbd.c')
-rw-r--r--drivers/block/nbd.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c
index b02f2362fdf7..9dcd5ddce94f 100644
--- a/drivers/block/nbd.c
+++ b/drivers/block/nbd.c
@@ -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;