[PATCH] perf_events: fix validate_event bug

From: Stephane Eranian
Date: Tue Nov 24 2009 - 08:27:29 EST


The validate_event() was failing on valid event
combinations. The function was assuming that if
x86_schedule_event() returned 0, it meant error.
But x86_schedule_event() returns the counter index
and 0 is a perfectly valid value. An error is returned
if the function returns a negative value.

Furthermore, validate_event() was also failing for
event groups because the event->pmu was not set until
after hw_perf_event_init().

Signed-off-by: Stephane Eranian <eranian@xxxxxxxxxx>
--
arch/x86/kernel/cpu/perf_event.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
index bd87430..c1bbed1 100644
--- a/arch/x86/kernel/cpu/perf_event.c
+++ b/arch/x86/kernel/cpu/perf_event.c
@@ -2229,10 +2229,10 @@ validate_event(struct cpu_hw_events *cpuc, struct perf_event *event)
{
struct hw_perf_event fake_event = event->hw;

- if (event->pmu != &pmu)
+ if (event->pmu && event->pmu != &pmu)
return 0;

- return x86_schedule_event(cpuc, &fake_event);
+ return x86_schedule_event(cpuc, &fake_event) >= 0;
}

static int validate_group(struct perf_event *event)
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/