LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* [PATCH v2] nbd: fix possible memory leak
@ 2015-01-27 12:38 Sudip Mukherjee
  2015-01-27 14:16 ` Paul Clements
  2015-01-28 20:13 ` [Nbd] " Markus Pargmann
  0 siblings, 2 replies; 3+ messages in thread
From: Sudip Mukherjee @ 2015-01-27 12:38 UTC (permalink / raw)
  To: Paul Clements; +Cc: Sudip Mukherjee, nbd-general, linux-kernel

we have already allocated memory for nbd_dev, but we were not
releasing that memory and just returning the error value.

Signed-off-by: Sudip Mukherjee <sudip@vectorindia.org>
---

v2: moved kcalloc after the returns.

 drivers/block/nbd.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c
index 4bc2a5c..db93c75 100644
--- a/drivers/block/nbd.c
+++ b/drivers/block/nbd.c
@@ -803,10 +803,6 @@ static int __init nbd_init(void)
 		return -EINVAL;
 	}
 
-	nbd_dev = kcalloc(nbds_max, sizeof(*nbd_dev), GFP_KERNEL);
-	if (!nbd_dev)
-		return -ENOMEM;
-
 	part_shift = 0;
 	if (max_part > 0) {
 		part_shift = fls(max_part);
@@ -827,6 +823,10 @@ static int __init nbd_init(void)
 
 	if (nbds_max > 1UL << (MINORBITS - part_shift))
 		return -EINVAL;
+
+	nbd_dev = kcalloc(nbds_max, sizeof(*nbd_dev), GFP_KERNEL);
+	if (!nbd_dev)
+		return -ENOMEM;
 
 	for (i = 0; i < nbds_max; i++) {
 		struct gendisk *disk = alloc_disk(1 << part_shift);
-- 
1.8.1.2


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] nbd: fix possible memory leak
  2015-01-27 12:38 [PATCH v2] nbd: fix possible memory leak Sudip Mukherjee
@ 2015-01-27 14:16 ` Paul Clements
  2015-01-28 20:13 ` [Nbd] " Markus Pargmann
  1 sibling, 0 replies; 3+ messages in thread
From: Paul Clements @ 2015-01-27 14:16 UTC (permalink / raw)
  To: Sudip Mukherjee; +Cc: nbd-general, kernel list

On Tue, Jan 27, 2015 at 7:38 AM, Sudip Mukherjee
<sudipm.mukherjee@gmail.com> wrote:
> we have already allocated memory for nbd_dev, but we were not
> releasing that memory and just returning the error value.
>
> Signed-off-by: Sudip Mukherjee <sudip@vectorindia.org>

Looks good to me.

Acked-by: Paul Clements <Paul.Clements@SteelEye.com>

> ---
>
> v2: moved kcalloc after the returns.
>
>  drivers/block/nbd.c | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c
> index 4bc2a5c..db93c75 100644
> --- a/drivers/block/nbd.c
> +++ b/drivers/block/nbd.c
> @@ -803,10 +803,6 @@ static int __init nbd_init(void)
>                 return -EINVAL;
>         }
>
> -       nbd_dev = kcalloc(nbds_max, sizeof(*nbd_dev), GFP_KERNEL);
> -       if (!nbd_dev)
> -               return -ENOMEM;
> -
>         part_shift = 0;
>         if (max_part > 0) {
>                 part_shift = fls(max_part);
> @@ -827,6 +823,10 @@ static int __init nbd_init(void)
>
>         if (nbds_max > 1UL << (MINORBITS - part_shift))
>                 return -EINVAL;
> +
> +       nbd_dev = kcalloc(nbds_max, sizeof(*nbd_dev), GFP_KERNEL);
> +       if (!nbd_dev)
> +               return -ENOMEM;
>
>         for (i = 0; i < nbds_max; i++) {
>                 struct gendisk *disk = alloc_disk(1 << part_shift);
> --
> 1.8.1.2
>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Nbd] [PATCH v2] nbd: fix possible memory leak
  2015-01-27 12:38 [PATCH v2] nbd: fix possible memory leak Sudip Mukherjee
  2015-01-27 14:16 ` Paul Clements
@ 2015-01-28 20:13 ` Markus Pargmann
  1 sibling, 0 replies; 3+ messages in thread
From: Markus Pargmann @ 2015-01-28 20:13 UTC (permalink / raw)
  To: Sudip Mukherjee; +Cc: Paul Clements, nbd-general, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 607 bytes --]

On Tue, Jan 27, 2015 at 06:08:22PM +0530, Sudip Mukherjee wrote:
> we have already allocated memory for nbd_dev, but we were not
> releasing that memory and just returning the error value.
> 
> Signed-off-by: Sudip Mukherjee <sudip@vectorindia.org>

Thanks, applied.

Regards,

Markus

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2015-01-28 20:13 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-01-27 12:38 [PATCH v2] nbd: fix possible memory leak Sudip Mukherjee
2015-01-27 14:16 ` Paul Clements
2015-01-28 20:13 ` [Nbd] " Markus Pargmann

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).