aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDrew Richardson <drew.richardson@arm.com>2015-07-30 08:27:19 -0700
committerJon Medhurst <tixy@linaro.org>2015-07-31 11:13:11 +0100
commit5d841367afb5252f8db7af1b4a765d0837f5921e (patch)
treee0056d8672e85759adc6b3ea014cd9e93747832d
parent83f711b8f028f2ba6fbd58d49136b33a9fc05c6d (diff)
downloadgator-5d841367afb5252f8db7af1b4a765d0837f5921e.tar.gz
gator: Fix race in perf event setup
Save the result of perf_event_create_kernel_counter to a temporary location so if it fails the error value will not be seen in __read and mistakenly used as pointer. Signed-off-by: Drew Richardson <Drew.Richardson@arm.com> Signed-off-by: Jon Medhurst <tixy@linaro.org>
-rw-r--r--driver/gator_events_perf_pmu.c15
1 files changed, 8 insertions, 7 deletions
diff --git a/driver/gator_events_perf_pmu.c b/driver/gator_events_perf_pmu.c
index d49277d..e62492b 100644
--- a/driver/gator_events_perf_pmu.c
+++ b/driver/gator_events_perf_pmu.c
@@ -136,6 +136,7 @@ static int gator_events_perf_pmu_online(int **buffer, bool migrate)
static void __online_dispatch(int cpu, bool migrate, struct gator_attr *const attr, struct gator_event *const event)
{
perf_overflow_handler_t handler;
+ struct perf_event *pevent;
event->zero = true;
@@ -148,22 +149,22 @@ static void __online_dispatch(int cpu, bool migrate, struct gator_attr *const at
handler = dummy_handler;
#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 1, 0)
- event->pevent = perf_event_create_kernel_counter(event->pevent_attr, cpu, 0, handler);
+ pevent = perf_event_create_kernel_counter(event->pevent_attr, cpu, 0, handler);
#else
- event->pevent = perf_event_create_kernel_counter(event->pevent_attr, cpu, 0, handler, 0);
+ pevent = perf_event_create_kernel_counter(event->pevent_attr, cpu, 0, handler, 0);
#endif
- if (IS_ERR(event->pevent)) {
+ if (IS_ERR(pevent)) {
pr_err("gator: unable to online a counter on cpu %d\n", cpu);
- event->pevent = NULL;
return;
}
- if (event->pevent->state != PERF_EVENT_STATE_ACTIVE) {
+ if (pevent->state != PERF_EVENT_STATE_ACTIVE) {
pr_err("gator: inactive counter on cpu %d\n", cpu);
- perf_event_release_kernel(event->pevent);
- event->pevent = NULL;
+ perf_event_release_kernel(pevent);
return;
}
+
+ event->pevent = pevent;
}
static void gator_events_perf_pmu_online_dispatch(int cpu, bool migrate)