summaryrefslogtreecommitdiffstats
path: root/kernel/events/callchain.c
diff options
context:
space:
mode:
authorFrederic Weisbecker <fweisbec@gmail.com>2013-07-23 02:31:00 +0200
committerIngo Molnar <mingo@kernel.org>2013-07-30 22:29:12 +0200
commit90983b16078ab0fdc58f0dab3e8e3da79c9579a2 (patch)
tree7cae7a4dfc4f86014446e300e600ce666fbd012a /kernel/events/callchain.c
parentperf: Fix branch stack refcount leak on callchain init failure (diff)
downloadlinux-90983b16078ab0fdc58f0dab3e8e3da79c9579a2.tar.xz
linux-90983b16078ab0fdc58f0dab3e8e3da79c9579a2.zip
perf: Sanitize get_callchain_buffer()
In case of allocation failure, get_callchain_buffer() keeps the refcount incremented for the current event. As a result, when get_callchain_buffers() returns an error, we must cleanup what it did by cancelling its last refcount with a call to put_callchain_buffers(). This is a hack in order to be able to call free_event() after that failure. The original purpose of that was to simplify the failure path. But this error handling is actually counter intuitive, ugly and not very easy to follow because one expect to see the resources used to perform a service to be cleaned by the callee if case of failure, not by the caller. So lets clean this up by cancelling the refcount from get_callchain_buffer() in case of failure. And correctly free the event accordingly in perf_event_alloc(). Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com> Cc: Jiri Olsa <jolsa@redhat.com> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Arnaldo Carvalho de Melo <acme@redhat.com> Cc: Stephane Eranian <eranian@google.com> Signed-off-by: Peter Zijlstra <peterz@infradead.org> Link: http://lkml.kernel.org/r/1374539466-4799-3-git-send-email-fweisbec@gmail.com Signed-off-by: Ingo Molnar <mingo@kernel.org>
Diffstat (limited to 'kernel/events/callchain.c')
-rw-r--r--kernel/events/callchain.c2
1 files changed, 2 insertions, 0 deletions
diff --git a/kernel/events/callchain.c b/kernel/events/callchain.c
index c77206184b8b..76a8bc5f6265 100644
--- a/kernel/events/callchain.c
+++ b/kernel/events/callchain.c
@@ -117,6 +117,8 @@ int get_callchain_buffers(void)
err = alloc_callchain_buffers();
exit:
mutex_unlock(&callchain_mutex);
+ if (err)
+ atomic_dec(&nr_callchain_events);
return err;
}