Skip to content

Commit 8fb2226

Browse files
Pawel MollKevin Hilman
authored andcommitted
bus: arm-ccn: Move event cleanup routine
The function cleaning up an initialized event was called from the "event_del" handler, instead of being used as the "destroy" callback. In case of events group allocation this caused NULL pointer dereference (as events are added and deleted multiple times then). Fixed now. Signed-off-by: Pawel Moll <mail@pawelmoll.com> Signed-off-by: Kevin Hilman <khilman@linaro.org>
1 parent 95f6e81 commit 8fb2226

1 file changed

Lines changed: 25 additions & 26 deletions

File tree

‎drivers/bus/arm-ccn.c‎

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -586,6 +586,30 @@ static int arm_ccn_pmu_type_eq(u32 a, u32 b)
586586
return 0;
587587
}
588588

589+
static void arm_ccn_pmu_event_destroy(struct perf_event *event)
590+
{
591+
struct arm_ccn *ccn = pmu_to_arm_ccn(event->pmu);
592+
struct hw_perf_event *hw = &event->hw;
593+
594+
if (hw->idx == CCN_IDX_PMU_CYCLE_COUNTER) {
595+
clear_bit(CCN_IDX_PMU_CYCLE_COUNTER, ccn->dt.pmu_counters_mask);
596+
} else {
597+
struct arm_ccn_component *source =
598+
ccn->dt.pmu_counters[hw->idx].source;
599+
600+
if (CCN_CONFIG_TYPE(event->attr.config) == CCN_TYPE_XP &&
601+
CCN_CONFIG_EVENT(event->attr.config) ==
602+
CCN_EVENT_WATCHPOINT)
603+
clear_bit(hw->config_base, source->xp.dt_cmp_mask);
604+
else
605+
clear_bit(hw->config_base, source->pmu_events_mask);
606+
clear_bit(hw->idx, ccn->dt.pmu_counters_mask);
607+
}
608+
609+
ccn->dt.pmu_counters[hw->idx].source = NULL;
610+
ccn->dt.pmu_counters[hw->idx].event = NULL;
611+
}
612+
589613
static int arm_ccn_pmu_event_init(struct perf_event *event)
590614
{
591615
struct arm_ccn *ccn;
@@ -599,6 +623,7 @@ static int arm_ccn_pmu_event_init(struct perf_event *event)
599623
return -ENOENT;
600624

601625
ccn = pmu_to_arm_ccn(event->pmu);
626+
event->destroy = arm_ccn_pmu_event_destroy;
602627

603628
if (hw->sample_period) {
604629
dev_warn(ccn->dev, "Sampling not supported!\n");
@@ -731,30 +756,6 @@ static int arm_ccn_pmu_event_init(struct perf_event *event)
731756
return 0;
732757
}
733758

734-
static void arm_ccn_pmu_event_free(struct perf_event *event)
735-
{
736-
struct arm_ccn *ccn = pmu_to_arm_ccn(event->pmu);
737-
struct hw_perf_event *hw = &event->hw;
738-
739-
if (hw->idx == CCN_IDX_PMU_CYCLE_COUNTER) {
740-
clear_bit(CCN_IDX_PMU_CYCLE_COUNTER, ccn->dt.pmu_counters_mask);
741-
} else {
742-
struct arm_ccn_component *source =
743-
ccn->dt.pmu_counters[hw->idx].source;
744-
745-
if (CCN_CONFIG_TYPE(event->attr.config) == CCN_TYPE_XP &&
746-
CCN_CONFIG_EVENT(event->attr.config) ==
747-
CCN_EVENT_WATCHPOINT)
748-
clear_bit(hw->config_base, source->xp.dt_cmp_mask);
749-
else
750-
clear_bit(hw->config_base, source->pmu_events_mask);
751-
clear_bit(hw->idx, ccn->dt.pmu_counters_mask);
752-
}
753-
754-
ccn->dt.pmu_counters[hw->idx].source = NULL;
755-
ccn->dt.pmu_counters[hw->idx].event = NULL;
756-
}
757-
758759
static u64 arm_ccn_pmu_read_counter(struct arm_ccn *ccn, int idx)
759760
{
760761
u64 res;
@@ -1027,8 +1028,6 @@ static int arm_ccn_pmu_event_add(struct perf_event *event, int flags)
10271028
static void arm_ccn_pmu_event_del(struct perf_event *event, int flags)
10281029
{
10291030
arm_ccn_pmu_event_stop(event, PERF_EF_UPDATE);
1030-
1031-
arm_ccn_pmu_event_free(event);
10321031
}
10331032

10341033
static void arm_ccn_pmu_event_read(struct perf_event *event)

0 commit comments

Comments
 (0)