Skip to content

Commit 6d7d51e

Browse files
Yicong Yangwilldeacon
authored andcommitted
drivers/perf: hisi_pcie: Check the type first in pmu::event_init()
Check whether the event type matches the PMU type firstly in pmu::event_init() before touching the event. Otherwise we'll change the events of others and lead to incorrect results. Since in perf_init_event() we may call every pmu's event_init() in a certain case, we should not modify the event if it's not ours. Fixes: 8404b0f ("drivers/perf: hisi: Add driver for HiSilicon PCIe PMU") Signed-off-by: Yicong Yang <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Will Deacon <[email protected]>
1 parent ab33c66 commit 6d7d51e

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

drivers/perf/hisilicon/hisi_pcie_pmu.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -353,16 +353,17 @@ static int hisi_pcie_pmu_event_init(struct perf_event *event)
353353
struct hisi_pcie_pmu *pcie_pmu = to_pcie_pmu(event->pmu);
354354
struct hw_perf_event *hwc = &event->hw;
355355

356+
/* Check the type first before going on, otherwise it's not our event */
357+
if (event->attr.type != event->pmu->type)
358+
return -ENOENT;
359+
356360
event->cpu = pcie_pmu->on_cpu;
357361

358362
if (EXT_COUNTER_IS_USED(hisi_pcie_get_event(event)))
359363
hwc->event_base = HISI_PCIE_EXT_CNT;
360364
else
361365
hwc->event_base = HISI_PCIE_CNT;
362366

363-
if (event->attr.type != event->pmu->type)
364-
return -ENOENT;
365-
366367
/* Sampling is not supported. */
367368
if (is_sampling_event(event) || event->attach_state & PERF_ATTACH_TASK)
368369
return -EOPNOTSUPP;

0 commit comments

Comments
 (0)