Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

perf pmus: Fixes always false when compare duplicates aliases

In the previous loop, all the members in the aliases[j-1] have been freed
and set to NULL. But in this loop, the function pmu_alias_is_duplicate()
compares the aliases[j] with the aliases[j-1] that has already been
disposed, so the function will always return false and duplicate aliases
will never be discarded.

If we find duplicate aliases, it skips the zfree aliases[j], which is
accompanied by a memory leak.

We can use the next aliases[j+1] to theck for duplicate aliases to
fixes the aliases NULL pointer dereference, then goto zfree code snippet
to release it.

After patch testing:
$ perf list --unit=hisi_sicl,cpa pmu

uncore cpa:
cpa_p0_rd_dat_32b
[Number of read ops transmitted by the P0 port which size is 32 bytes.
Unit: hisi_sicl,cpa]
cpa_p0_rd_dat_64b
[Number of read ops transmitted by the P0 port which size is 64 bytes.
Unit: hisi_sicl,cpa]

Fixes: c3245d2093c1 ("perf pmu: Abstract alias/event struct")
Signed-off-by: Junhao He <hejunhao3@huawei.com>
Cc: ravi.bangoria@amd.com
Cc: james.clark@arm.com
Cc: prime.zeng@hisilicon.com
Cc: cuigaosheng1@huawei.com
Cc: jonathan.cameron@huawei.com
Cc: linuxarm@huawei.com
Cc: yangyicong@huawei.com
Cc: robh@kernel.org
Cc: renyu.zj@linux.alibaba.com
Cc: kjain@linux.ibm.com
Cc: john.g.garry@oracle.com
Cc: linux-arm-kernel@lists.infradead.org
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Link: https://lore.kernel.org/r/20240614094318.11607-1-hejunhao3@huawei.com

authored by

Junhao He and committed by
Namhyung Kim
dd9a426e 83da316a

+3 -2
+3 -2
tools/perf/util/pmus.c
··· 488 488 qsort(aliases, len, sizeof(struct sevent), cmp_sevent); 489 489 for (int j = 0; j < len; j++) { 490 490 /* Skip duplicates */ 491 - if (j > 0 && pmu_alias_is_duplicate(&aliases[j], &aliases[j - 1])) 492 - continue; 491 + if (j < len - 1 && pmu_alias_is_duplicate(&aliases[j], &aliases[j + 1])) 492 + goto free; 493 493 494 494 print_cb->print_event(print_state, 495 495 aliases[j].pmu_name, ··· 502 502 aliases[j].desc, 503 503 aliases[j].long_desc, 504 504 aliases[j].encoding_desc); 505 + free: 505 506 zfree(&aliases[j].name); 506 507 zfree(&aliases[j].alias); 507 508 zfree(&aliases[j].scale_unit);