All of lore.kernel.org
 help / color / mirror / Atom feed
From: Chao Yu <chao2.yu@samsung.com>
To: axboe@kernel.dk
Cc: linux-kernel@vger.kernel.org
Subject: [PATCH] elevator: fix memory leak in ->elevator_init_fn
Date: Fri, 24 Apr 2015 10:08:43 +0800	[thread overview]
Message-ID: <00c701d07e33$acbca360$0635ea20$@samsung.com> (raw)

In ->elevator_init_fn, if we fail to call kzalloc_node, we should release
elevator queue space which is allocated previously, otherwise it will cause
memory leak.

Signed-off-by: Chao Yu <chao2.yu@samsung.com>
---
 block/cfq-iosched.c      | 1 +
 block/deadline-iosched.c | 1 +
 block/noop-iosched.c     | 1 +
 3 files changed, 3 insertions(+)

diff --git a/block/cfq-iosched.c b/block/cfq-iosched.c
index 5da8e6e..2793fb7 100644
--- a/block/cfq-iosched.c
+++ b/block/cfq-iosched.c
@@ -4391,6 +4391,7 @@ static int cfq_init_queue(struct request_queue *q, struct elevator_type *e)
 	cfqd = kzalloc_node(sizeof(*cfqd), GFP_KERNEL, q->node);
 	if (!cfqd) {
 		kobject_put(&eq->kobj);
+		kfree(eq);
 		return -ENOMEM;
 	}
 	eq->elevator_data = cfqd;
diff --git a/block/deadline-iosched.c b/block/deadline-iosched.c
index a753df2..bc6d7d9 100644
--- a/block/deadline-iosched.c
+++ b/block/deadline-iosched.c
@@ -349,6 +349,7 @@ static int deadline_init_queue(struct request_queue *q, struct elevator_type *e)
 	dd = kzalloc_node(sizeof(*dd), GFP_KERNEL, q->node);
 	if (!dd) {
 		kobject_put(&eq->kobj);
+		kfree(eq);
 		return -ENOMEM;
 	}
 	eq->elevator_data = dd;
diff --git a/block/noop-iosched.c b/block/noop-iosched.c
index 3de89d4..1399c78 100644
--- a/block/noop-iosched.c
+++ b/block/noop-iosched.c
@@ -71,6 +71,7 @@ static int noop_init_queue(struct request_queue *q, struct elevator_type *e)
 	nd = kmalloc_node(sizeof(*nd), GFP_KERNEL, q->node);
 	if (!nd) {
 		kobject_put(&eq->kobj);
+		kfree(eq);
 		return -ENOMEM;
 	}
 	eq->elevator_data = nd;
-- 
2.3.3



             reply	other threads:[~2015-04-24  2:09 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-04-24  2:08 Chao Yu [this message]
2015-04-24 13:03 ` [PATCH] elevator: fix memory leak in ->elevator_init_fn Jeff Moyer
  -- strict thread matches above, loose matches on Subject: below --
2015-04-27  5:30 Chao Yu

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='00c701d07e33$acbca360$0635ea20$@samsung.com' \
    --to=chao2.yu@samsung.com \
    --cc=axboe@kernel.dk \
    --cc=linux-kernel@vger.kernel.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.