Commit 7167c574 authored by Sudip Mukherjee's avatar Sudip Mukherjee Committed by Greg Kroah-Hartman

nbd: fix possible memory leak

commit ff6b8090 upstream.

we have already allocated memory for nbd_dev, but we were not
releasing that memory and just returning the error value.
Signed-off-by: default avatarSudip Mukherjee <sudip@vectorindia.org>
Acked-by: default avatarPaul Clements <Paul.Clements@SteelEye.com>
Signed-off-by: default avatarMarkus Pargmann <mpa@pengutronix.de>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 74b8c182
...@@ -803,10 +803,6 @@ static int __init nbd_init(void) ...@@ -803,10 +803,6 @@ static int __init nbd_init(void)
return -EINVAL; return -EINVAL;
} }
nbd_dev = kcalloc(nbds_max, sizeof(*nbd_dev), GFP_KERNEL);
if (!nbd_dev)
return -ENOMEM;
part_shift = 0; part_shift = 0;
if (max_part > 0) { if (max_part > 0) {
part_shift = fls(max_part); part_shift = fls(max_part);
...@@ -828,6 +824,10 @@ static int __init nbd_init(void) ...@@ -828,6 +824,10 @@ static int __init nbd_init(void)
if (nbds_max > 1UL << (MINORBITS - part_shift)) if (nbds_max > 1UL << (MINORBITS - part_shift))
return -EINVAL; return -EINVAL;
nbd_dev = kcalloc(nbds_max, sizeof(*nbd_dev), GFP_KERNEL);
if (!nbd_dev)
return -ENOMEM;
for (i = 0; i < nbds_max; i++) { for (i = 0; i < nbds_max; i++) {
struct gendisk *disk = alloc_disk(1 << part_shift); struct gendisk *disk = alloc_disk(1 << part_shift);
if (!disk) if (!disk)
......
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