perf/arm-cmn: Fix invalid pointer when access dtc object sharing the same IRQ number
authorTuan Phan <tuanphan@os.amperecomputing.com>
Thu, 17 Jun 2021 16:08:49 +0000 (09:08 -0700)
committerWill Deacon <will@kernel.org>
Thu, 17 Jun 2021 18:45:02 +0000 (19:45 +0100)
When multiple dtcs share the same IRQ number, the irq_friend which
used to refer to dtc object gets calculated incorrect which leads
to invalid pointer.

Fixes: 0ba64770a2f2 ("perf: Add Arm CMN-600 PMU driver")
Signed-off-by: Tuan Phan <tuanphan@os.amperecomputing.com>
Reviewed-by: Robin Murphy <robin.murphy@arm.com>
Link: https://lore.kernel.org/r/1623946129-3290-1-git-send-email-tuanphan@os.amperecomputing.com
Signed-off-by: Will Deacon <will@kernel.org>
drivers/perf/arm-cmn.c

index 4f46f654279d352d4c3a3e8ab084c0f5c62a244a..bc3cba5f8c5dc72e1d8998d604f8083a5998582c 100644 (file)
@@ -1212,7 +1212,7 @@ static int arm_cmn_init_irqs(struct arm_cmn *cmn)
                irq = cmn->dtc[i].irq;
                for (j = i; j--; ) {
                        if (cmn->dtc[j].irq == irq) {
-                               cmn->dtc[j].irq_friend = j - i;
+                               cmn->dtc[j].irq_friend = i - j;
                                goto next;
                        }
                }