summaryrefslogtreecommitdiffstats
path: root/tools/lib/perf
diff options
context:
space:
mode:
authorIan Rogers <irogers@google.com>2023-03-11 18:15:33 -0800
committerArnaldo Carvalho de Melo <acme@redhat.com>2023-03-13 15:11:34 -0300
commit5dd827e0fa586521416730e2bb8c3846f6dd91fc (patch)
tree3543d5a869c6c75ed04ede7e3cec67420d161a13 /tools/lib/perf
parentf9f60efbfc98a9b228d35a1a98fee0528c1fd3ae (diff)
downloadlinux-5dd827e0fa586521416730e2bb8c3846f6dd91fc.tar.gz
linux-5dd827e0fa586521416730e2bb8c3846f6dd91fc.tar.bz2
linux-5dd827e0fa586521416730e2bb8c3846f6dd91fc.zip
libperf evlist: Avoid a use of evsel idx
Setting the leader iterates the list, so rather than use idx (which may be changed through list reordering) just count the elements and set afterwards. Signed-off-by: Ian Rogers <irogers@google.com> Cc: Adrian Hunter <adrian.hunter@intel.com> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com> Cc: Florian Fischer <florian.fischer@muhq.space> 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: Kajol Jain <kjain@linux.ibm.com> Cc: Kan Liang <kan.liang@linux.intel.com> Cc: Kim Phillips <kim.phillips@amd.com> Cc: Leo Yan <leo.yan@linaro.org> Cc: Mark Rutland <mark.rutland@arm.com> 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: Steinar H. Gunderson <sesse@google.com> Cc: Stephane Eranian <eranian@google.com> Cc: Suzuki Poulouse <suzuki.poulose@arm.com> Cc: Xing Zhengjun <zhengjun.xing@linux.intel.com> Link: https://lore.kernel.org/r/20230312021543.3060328-2-irogers@google.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/lib/perf')
-rw-r--r--tools/lib/perf/evlist.c13
1 files changed, 6 insertions, 7 deletions
diff --git a/tools/lib/perf/evlist.c b/tools/lib/perf/evlist.c
index 61b637f29b82..2d6121e89ccb 100644
--- a/tools/lib/perf/evlist.c
+++ b/tools/lib/perf/evlist.c
@@ -687,15 +687,14 @@ perf_evlist__next_mmap(struct perf_evlist *evlist, struct perf_mmap *map,
void __perf_evlist__set_leader(struct list_head *list, struct perf_evsel *leader)
{
- struct perf_evsel *first, *last, *evsel;
-
- first = list_first_entry(list, struct perf_evsel, node);
- last = list_last_entry(list, struct perf_evsel, node);
-
- leader->nr_members = last->idx - first->idx + 1;
+ struct perf_evsel *evsel;
+ int n = 0;
- __perf_evlist__for_each_entry(list, evsel)
+ __perf_evlist__for_each_entry(list, evsel) {
evsel->leader = leader;
+ n++;
+ }
+ leader->nr_members = n;
}
void perf_evlist__set_leader(struct perf_evlist *evlist)