Skip to content

Commit a1792cd

Browse files
Peter ZijlstraIngo Molnar
authored andcommitted
perf_counter: x86: Fix PMU resource leak
Dave noticed that we leak the PMU resource reservations when we fail the hardware counter init. Reported-by: David Miller <davem@davemloft.net> Signed-off-by: Peter Zijlstra <a.p.zijlstra@chello.nl> Acked-by: David Miller <davem@davemloft.net> LKML-Reference: <1252483487.7746.164.camel@twins> Signed-off-by: Ingo Molnar <mingo@elte.hu>
1 parent 611a546 commit a1792cd

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

arch/x86/kernel/cpu/perf_counter.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -924,6 +924,8 @@ static int __hw_perf_counter_init(struct perf_counter *counter)
924924
if (err)
925925
return err;
926926

927+
counter->destroy = hw_perf_counter_destroy;
928+
927929
/*
928930
* Generate PMC IRQs:
929931
* (keep 'enabled' bit clear for now)
@@ -953,8 +955,6 @@ static int __hw_perf_counter_init(struct perf_counter *counter)
953955
return -EOPNOTSUPP;
954956
}
955957

956-
counter->destroy = hw_perf_counter_destroy;
957-
958958
/*
959959
* Raw event type provide the config in the event structure
960960
*/
@@ -2107,8 +2107,11 @@ const struct pmu *hw_perf_counter_init(struct perf_counter *counter)
21072107
int err;
21082108

21092109
err = __hw_perf_counter_init(counter);
2110-
if (err)
2110+
if (err) {
2111+
if (counter->destroy)
2112+
counter->destroy(counter);
21112113
return ERR_PTR(err);
2114+
}
21122115

21132116
return &pmu;
21142117
}

0 commit comments

Comments
 (0)