Skip to content

Commit b782304

Browse files
captain5050acmel
authored andcommitted
perf pmu: Make id const and add missing free
The struct pmu id is initialized from pmu_id that is read into allocated memory from a file, as such it needs free-ing in pmu__delete(). Make the id value const so that we can remove casts in tests. Signed-off-by: Ian Rogers <irogers@google.com> Cc: Adrian Hunter <adrian.hunter@intel.com> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com> Cc: Athira Rajeev <atrajeev@linux.vnet.ibm.com> Cc: Huacai Chen <chenhuacai@kernel.org> Cc: Ingo Molnar <mingo@redhat.com> Cc: James Clark <james.clark@arm.com> Cc: Jiri Olsa <jolsa@kernel.org> Cc: John Garry <john.g.garry@oracle.com> Cc: K Prateek Nayak <kprateek.nayak@amd.com> Cc: Kajol Jain <kjain@linux.ibm.com> Cc: Kan Liang <kan.liang@linux.intel.com> Cc: Leo Yan <leo.yan@linaro.org> Cc: Mark Rutland <mark.rutland@arm.com> Cc: Mike Leach <mike.leach@linaro.org> Cc: Ming Wang <wangming01@loongson.cn> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Ravi Bangoria <ravi.bangoria@amd.com> Cc: Sean Christopherson <seanjc@google.com> Cc: Suzuki Poulouse <suzuki.poulose@arm.com> Cc: Wei Li <liwei391@huawei.com> Cc: Will Deacon <will@kernel.org> Cc: linux-arm-kernel@lists.infradead.org Link: https://lore.kernel.org/r/20230825024002.801955-5-irogers@google.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
1 parent 970ef02 commit b782304

3 files changed

Lines changed: 4 additions & 3 deletions

File tree

tools/perf/tests/pmu-events.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -684,7 +684,7 @@ static struct perf_pmu_test_pmu test_pmus[] = {
684684
.pmu = {
685685
.name = "uncore_sys_ddr_pmu0",
686686
.is_uncore = 1,
687-
.id = (char *)"v8",
687+
.id = "v8",
688688
},
689689
.aliases = {
690690
&sys_ddr_pmu_write_cycles,
@@ -694,7 +694,7 @@ static struct perf_pmu_test_pmu test_pmus[] = {
694694
.pmu = {
695695
.name = "uncore_sys_ccn_pmu4",
696696
.is_uncore = 1,
697-
.id = (char *)"0x01",
697+
.id = "0x01",
698698
},
699699
.aliases = {
700700
&sys_ccn_pmu_read_cycles,

tools/perf/util/pmu.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2056,6 +2056,7 @@ void perf_pmu__delete(struct perf_pmu *pmu)
20562056
zfree(&pmu->default_config);
20572057
zfree(&pmu->name);
20582058
zfree(&pmu->alias_name);
2059+
zfree(&pmu->id);
20592060
free(pmu);
20602061
}
20612062

tools/perf/util/pmu.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ struct perf_pmu {
4949
* @id: Optional PMU identifier read from
5050
* <sysfs>/bus/event_source/devices/<name>/identifier.
5151
*/
52-
char *id;
52+
const char *id;
5353
/**
5454
* @type: Perf event attributed type value, read from
5555
* <sysfs>/bus/event_source/devices/<name>/type.

0 commit comments

Comments
 (0)