All of lore.kernel.org
 help / color / mirror / Atom feed
* Possible bug in ftrace_profile_enable_event
@ 2009-10-01  4:50 Paul Mackerras
  2009-10-01  6:20 ` Steven Rostedt
                   ` (4 more replies)
  0 siblings, 5 replies; 12+ messages in thread
From: Paul Mackerras @ 2009-10-01  4:50 UTC (permalink / raw)
  To: Frederic Weisbecker
  Cc: Steven Rostedt, Ingo Molnar, Peter Zijlstra, linux-kernel

I was looking through kernel/trace/trace_event_profile.c and I saw
this code:

static int ftrace_profile_enable_event(struct ftrace_event_call *event)
{
	char *buf;
	int ret = -ENOMEM;

	if (atomic_inc_return(&event->profile_count))
		return 0;

	if (!total_profile_count++) {
		buf = (char *)alloc_percpu(profile_buf_t);
		if (!buf)
			goto fail_buf;

		rcu_assign_pointer(trace_profile_buf, buf);

		buf = (char *)alloc_percpu(profile_buf_t);
		if (!buf)
			goto fail_buf_nmi;

		rcu_assign_pointer(trace_profile_buf_nmi, buf);
	}

	ret = event->profile_enable();
	if (!ret)
		return 0;

	kfree(trace_profile_buf_nmi);
fail_buf_nmi:
	kfree(trace_profile_buf);
fail_buf:
	total_profile_count--;

...

So we only allocate trace_profile_buf and trace_profile_buf_nmi if
total_profile_count was zero on entry, but if we get an error returned
from event->profile_enable(), we free them both unconditionally,
regardless of the value of total_profile_count.  That seems wrong.  Is
there a subtle reason why that is the right thing to do?

(Also, is kfree the appropriate counterpart to alloc_percpu?)

Paul.

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

end of thread, other threads:[~2009-10-08 23:18 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-10-01  4:50 Possible bug in ftrace_profile_enable_event Paul Mackerras
2009-10-01  6:20 ` Steven Rostedt
2009-10-02 12:13 ` Frédéric Weisbecker
2009-10-03 13:47 ` [GIT PULL] tracing: Perf tracing fixes Frederic Weisbecker
2009-10-03 13:57   ` Frederic Weisbecker
2009-10-05 17:54   ` Frederic Weisbecker
2009-10-06 12:30     ` Ingo Molnar
2009-10-03 13:47 ` [PATCH 1/2] tracing: Check total refcount before releasing bufs in profile_enable failure Frederic Weisbecker
2009-10-07  3:08   ` Paul Mackerras
2009-10-08 21:43     ` Frederic Weisbecker
2009-10-08 21:53       ` Paul Mackerras
2009-10-03 13:47 ` [PATCH 2/2] tracing: Use free_percpu instead of kfree Frederic Weisbecker

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.