mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [GIT PULL] NBD fixes
@ 2015-02-12 13:37 Markus Pargmann
  2015-02-12 13:37 ` [PATCH] nbd: fix possible memory leak Markus Pargmann
  0 siblings, 1 reply; 5+ messages in thread
From: Markus Pargmann @ 2015-02-12 13:37 UTC (permalink / raw)
  To: Jens Axboe; +Cc: nbd-general, linux-kernel, Markus Pargmann

Hi Jens,

This is a pull request for one NBD patch. It fixes a memory leak which occures
when a module parameter has an invalid value.

It is based on v3.19-rc2. If you prefer a different base please let me know.

Best Regards,

Markus


The following changes since commit b7392d2247cfe6771f95d256374f1a8e6a6f48d6:

  Linux 3.19-rc2 (2014-12-28 16:49:37 -0800)

are available in the git repository at:

  git://git.pengutronix.de/git/mpa/linux-nbd.git tags/nbd_fixes_20150212

for you to fetch changes up to 473b3bfe169ca0b2192d7184786429bd75d359da:

  nbd: fix possible memory leak (2015-02-12 13:21:55 +0100)

----------------------------------------------------------------
NBD fixes based on v3.19-rc2

----------------------------------------------------------------
Sudip Mukherjee (1):
      nbd: fix possible memory leak

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

-- 
2.1.4


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

* [PATCH] nbd: fix possible memory leak
  2015-02-12 13:37 [GIT PULL] NBD fixes Markus Pargmann
@ 2015-02-12 13:37 ` Markus Pargmann
  0 siblings, 0 replies; 5+ messages in thread
From: Markus Pargmann @ 2015-02-12 13:37 UTC (permalink / raw)
  To: Jens Axboe
  Cc: nbd-general, linux-kernel, Sudip Mukherjee, Sudip Mukherjee,
	stable, Markus Pargmann

From: Sudip Mukherjee <sudipm.mukherjee@gmail.com>

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>
Acked-by: Paul Clements <Paul.Clements@SteelEye.com>
Cc: <stable@vger.kernel.org>
Signed-off-by: Markus Pargmann <mpa@pengutronix.de>
---
 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 4bc2a5cb9935..a98c41f72c63 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);
@@ -828,6 +824,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);
 		if (!disk)
-- 
2.1.4


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

* [PATCH] nbd: fix possible memory leak
  2015-03-05  8:09 [PULL v2] NBD fixes Markus Pargmann
@ 2015-03-05  8:09 ` Markus Pargmann
  0 siblings, 0 replies; 5+ messages in thread
From: Markus Pargmann @ 2015-03-05  8:09 UTC (permalink / raw)
  To: Jens Axboe
  Cc: linux-kernel, Sudip Mukherjee, Sudip Mukherjee, stable, Markus Pargmann

From: Sudip Mukherjee <sudipm.mukherjee@gmail.com>

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>
Acked-by: Paul Clements <Paul.Clements@SteelEye.com>
Cc: <stable@vger.kernel.org>
Signed-off-by: Markus Pargmann <mpa@pengutronix.de>
---
 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 4bc2a5cb9935..a98c41f72c63 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);
@@ -828,6 +824,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);
 		if (!disk)
-- 
2.1.4


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

* Re: [PATCH] nbd: fix possible memory leak
  2015-01-13 17:19 Sudip Mukherjee
@ 2015-01-26 17:00 ` Paul Clements
  0 siblings, 0 replies; 5+ messages in thread
From: Paul Clements @ 2015-01-26 17:00 UTC (permalink / raw)
  To: Sudip Mukherjee; +Cc: nbd-general, kernel list

Sudip,

On Tue, Jan 13, 2015 at 12:19 PM, 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>
> ---
>
> Hi Paul,
> after seeing your mail about maintainers, just started to see the code.
> this patch is one way, another way can be to bring the kcalloc part below these checks.

Probably better to move the kcalloc below, rather than adding more
branches, wouldn't you agree?

Thanks,
Paul

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

* [PATCH] nbd: fix possible memory leak
@ 2015-01-13 17:19 Sudip Mukherjee
  2015-01-26 17:00 ` Paul Clements
  0 siblings, 1 reply; 5+ messages in thread
From: Sudip Mukherjee @ 2015-01-13 17:19 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>
---

Hi Paul,
after seeing your mail about maintainers, just started to see the code.
this patch is one way, another way can be to bring the kcalloc part below these checks. 

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

diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c
index 4bc2a5c..13ea239 100644
--- a/drivers/block/nbd.c
+++ b/drivers/block/nbd.c
@@ -822,11 +822,15 @@ static int __init nbd_init(void)
 		max_part = (1UL << part_shift) - 1;
 	}
 
-	if ((1UL << part_shift) > DISK_MAX_PARTS)
-		return -EINVAL;
+	if ((1UL << part_shift) > DISK_MAX_PARTS) {
+		err = -EINVAL;
+		goto out_free;
+	}
 
-	if (nbds_max > 1UL << (MINORBITS - part_shift))
-		return -EINVAL;
+	if (nbds_max > 1UL << (MINORBITS - part_shift)) {
+		err = -EINVAL;
+		goto out_free;
+	}
 
 	for (i = 0; i < nbds_max; i++) {
 		struct gendisk *disk = alloc_disk(1 << part_shift);
@@ -889,6 +893,7 @@ out:
 		blk_cleanup_queue(nbd_dev[i].disk->queue);
 		put_disk(nbd_dev[i].disk);
 	}
+out_free:
 	kfree(nbd_dev);
 	return err;
 }
-- 
1.8.1.2


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

end of thread, other threads:[~2015-03-05  8:09 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-02-12 13:37 [GIT PULL] NBD fixes Markus Pargmann
2015-02-12 13:37 ` [PATCH] nbd: fix possible memory leak Markus Pargmann
  -- strict thread matches above, loose matches on Subject: below --
2015-03-05  8:09 [PULL v2] NBD fixes Markus Pargmann
2015-03-05  8:09 ` [PATCH] nbd: fix possible memory leak Markus Pargmann
2015-01-13 17:19 Sudip Mukherjee
2015-01-26 17:00 ` Paul Clements

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®