linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Ingo Molnar <mingo@elte.hu>
To: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Namhyung Kim <namhyung.kim@lge.com>,
	Namhyung Kim <namhyung@gmail.com>,
	Paul Mackerras <paulus@samba.org>,
	Arnaldo Carvalho de Melo <acme@ghostprotocols.net>,
	LKML <linux-kernel@vger.kernel.org>,
	Frederic Weisbecker <fweisbec@gmail.com>
Subject: Re: [PATCH] hw breakpoint: Fix possible memory leak
Date: Mon, 27 Feb 2012 11:44:52 +0100	[thread overview]
Message-ID: <20120227104452.GA6082@elte.hu> (raw)
In-Reply-To: <1330338785.11248.49.camel@twins>


* Peter Zijlstra <a.p.zijlstra@chello.nl> wrote:

> On Mon, 2012-02-27 at 12:02 +0900, Namhyung Kim wrote:
> > If kzalloc() for TYPE_DATA failed on a given cpu, previous chunk
> > will be leaked. Fix it.
> 
> so why not fix the error loop? wouldn't putting that err_cpu == cpu
> break after the kfree sort it?

I edited that code earlier today - is the form below OK, or can 
you see a simpler method? It's not yet pushed out so can still 
edit it.

Thanks,

	Ingo

>From f019669c93da6c2094326d07735320d3bf223ffe Mon Sep 17 00:00:00 2001
From: Namhyung Kim <namhyung.kim@lge.com>
Date: Mon, 27 Feb 2012 12:02:19 +0900
Subject: [PATCH] hw breakpoints: Fix possible memory leak

If kzalloc() for TYPE_DATA failed on a given cpu, previous chunk
will be leaked. Fix it.

Signed-off-by: Namhyung Kim <namhyung.kim@lge.com>
Cc: Namhyung Kim <namhyung@gmail.com>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Arnaldo Carvalho de Melo <acme@ghostprotocols.net>
Link: http://lkml.kernel.org/r/1330311739-24302-1-git-send-email-namhyung.kim@lge.com
[ rearranged the code to have a clearer flow ]
Signed-off-by: Ingo Molnar <mingo@elte.hu>
---
 kernel/events/hw_breakpoint.c |    8 +++++---
 1 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/kernel/events/hw_breakpoint.c b/kernel/events/hw_breakpoint.c
index b7971d6..867032d 100644
--- a/kernel/events/hw_breakpoint.c
+++ b/kernel/events/hw_breakpoint.c
@@ -636,10 +636,9 @@ int __init init_hw_breakpoint(void)
 	for_each_possible_cpu(cpu) {
 		for (i = 0; i < TYPE_MAX; i++) {
 			task_bp_pinned = &per_cpu(nr_task_bp_pinned[i], cpu);
-			*task_bp_pinned = kzalloc(sizeof(int) * nr_slots[i],
-						  GFP_KERNEL);
+			*task_bp_pinned = kzalloc(sizeof(int) * nr_slots[i], GFP_KERNEL);
 			if (!*task_bp_pinned)
-				goto err_alloc;
+				goto err_alloc_pinned;
 		}
 	}
 
@@ -649,6 +648,9 @@ int __init init_hw_breakpoint(void)
 
 	return register_die_notifier(&hw_breakpoint_exceptions_nb);
 
+ err_alloc_pinned:
+	while (--i >= 0)
+		kfree(per_cpu(nr_task_bp_pinned[i], cpu));
  err_alloc:
 	for_each_possible_cpu(err_cpu) {
 		if (err_cpu == cpu)

  reply	other threads:[~2012-02-27 10:45 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-02-27  3:02 [PATCH] hw breakpoint: Fix possible memory leak Namhyung Kim
2012-02-27 10:33 ` Peter Zijlstra
2012-02-27 10:44   ` Ingo Molnar [this message]
2012-02-27 11:04     ` Peter Zijlstra
2012-02-27 11:56       ` Ingo Molnar
2012-02-27 13:32         ` Namhyung Kim
2012-02-27 19:40           ` Ingo Molnar
2012-02-27 23:38             ` Frederic Weisbecker
2012-02-28  1:19               ` [PATCH v2] hw breakpoint: Fix a " Namhyung Kim
2012-02-28  9:13                 ` [tip:perf/urgent] perf/hwbp: " tip-bot for Namhyung Kim
2012-02-27 12:45       ` [PATCH] hw breakpoint: Fix " Namhyung Kim
2012-02-27 12:46         ` Peter Zijlstra
2012-02-27 12:50           ` Namhyung Kim

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=20120227104452.GA6082@elte.hu \
    --to=mingo@elte.hu \
    --cc=a.p.zijlstra@chello.nl \
    --cc=acme@ghostprotocols.net \
    --cc=fweisbec@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=namhyung.kim@lge.com \
    --cc=namhyung@gmail.com \
    --cc=paulus@samba.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 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).