summaryrefslogtreecommitdiff
path: root/drivers/perf
diff options
context:
space:
mode:
authorYicong Yang <yangyicong@hisilicon.com>2023-10-24 17:29:53 +0800
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2023-11-20 11:59:13 +0100
commit5d6d45e2d58bdfbbb405bb6e26602b4e530d7631 (patch)
tree5fa77a79d56343e1c14676bf5843115c99aa83d1 /drivers/perf
parent31c99087d1fc35e917440a41e01a971c3243efdd (diff)
downloadlinux-5d6d45e2d58bdfbbb405bb6e26602b4e530d7631.tar.gz
linux-5d6d45e2d58bdfbbb405bb6e26602b4e530d7631.tar.bz2
linux-5d6d45e2d58bdfbbb405bb6e26602b4e530d7631.zip
drivers/perf: hisi_pcie: Check the type first in pmu::event_init()
[ Upstream commit 6d7d51e88e21c0af1ca96a3617afef334bfeffcf ] 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: 8404b0fbc7fb ("drivers/perf: hisi: Add driver for HiSilicon PCIe PMU") Signed-off-by: Yicong Yang <yangyicong@hisilicon.com> Link: https://lore.kernel.org/r/20231024092954.42297-2-yangyicong@huawei.com Signed-off-by: Will Deacon <will@kernel.org> Signed-off-by: Sasha Levin <sashal@kernel.org>
Diffstat (limited to 'drivers/perf')
-rw-r--r--drivers/perf/hisilicon/hisi_pcie_pmu.c7
1 files changed, 4 insertions, 3 deletions
diff --git a/drivers/perf/hisilicon/hisi_pcie_pmu.c b/drivers/perf/hisilicon/hisi_pcie_pmu.c
index 5a00adb2de8c..051efffc44c8 100644
--- a/drivers/perf/hisilicon/hisi_pcie_pmu.c
+++ b/drivers/perf/hisilicon/hisi_pcie_pmu.c
@@ -353,6 +353,10 @@ static int hisi_pcie_pmu_event_init(struct perf_event *event)
struct hisi_pcie_pmu *pcie_pmu = to_pcie_pmu(event->pmu);
struct hw_perf_event *hwc = &event->hw;
+ /* Check the type first before going on, otherwise it's not our event */
+ if (event->attr.type != event->pmu->type)
+ return -ENOENT;
+
event->cpu = pcie_pmu->on_cpu;
if (EXT_COUNTER_IS_USED(hisi_pcie_get_event(event)))
@@ -360,9 +364,6 @@ static int hisi_pcie_pmu_event_init(struct perf_event *event)
else
hwc->event_base = HISI_PCIE_CNT;
- if (event->attr.type != event->pmu->type)
- return -ENOENT;
-
/* Sampling is not supported. */
if (is_sampling_event(event) || event->attach_state & PERF_ATTACH_TASK)
return -EOPNOTSUPP;