mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Markus Pargmann <mpa@pengutronix.de>
To: Jens Axboe <axboe@kernel.dk>
Cc: nbd-general@lists.sourceforge.net, linux-kernel@vger.kernel.org,
	Sudip Mukherjee <sudipm.mukherjee@gmail.com>,
	Sudip Mukherjee <sudip@vectorindia.org>, <stable@vger.kernel.org>,
	Markus Pargmann <mpa@pengutronix.de>
Subject: [PATCH] nbd: fix possible memory leak
Date: Thu, 12 Feb 2015 14:37:15 +0100	[thread overview]
Message-ID: <1423748235-14447-2-git-send-email-mpa@pengutronix.de> (raw)
In-Reply-To: <1423748235-14447-1-git-send-email-mpa@pengutronix.de>

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


  reply	other threads:[~2015-02-12 13:41 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-02-12 13:37 [GIT PULL] NBD fixes Markus Pargmann
2015-02-12 13:37 ` Markus Pargmann [this message]
  -- strict thread matches above, loose matches on Subject: below --
2015-03-05  8:09 [PULL v2] " 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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1423748235-14447-2-git-send-email-mpa@pengutronix.de \
    --to=mpa@pengutronix.de \
    --cc=axboe@kernel.dk \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nbd-general@lists.sourceforge.net \
    --cc=stable@vger.kernel.org \
    --cc=sudip@vectorindia.org \
    --cc=sudipm.mukherjee@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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®