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

perf maps: Re-use __maps__free_maps_by_name()

maps__merge_in() hard codes the steps to free the maps_by_name list. It
seems to not map__put() each element before freeing, and it sets
maps_by_name_sorted to true after freeing, which may be harmless but
is inconsistent with maps__init() and other functions.

maps__maps_by_name_addr() is also quite hard to read because we already
have maps__maps_by_name() and maps__maps_by_address(), but the function
is only used in that place so delete it.

Reviewed-by: Ian Rogers <irogers@google.com>
Signed-off-by: James Clark <james.clark@arm.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: Ingo Molnar <mingo@redhat.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: https://lore.kernel.org/r/20240507141210.195939-3-james.clark@arm.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

James Clark and committed by
Arnaldo Carvalho de Melo
fd81f52e 9fe410a7

+7 -7
+7 -7
tools/perf/util/maps.c
··· 124 124 125 125 } 126 126 127 - static struct map ***maps__maps_by_name_addr(struct maps *maps) 128 - { 129 - return &RC_CHK_ACCESS(maps)->maps_by_name; 130 - } 131 - 132 127 static void maps__set_nr_maps_allocated(struct maps *maps, unsigned int nr_maps_allocated) 133 128 { 134 129 RC_CHK_ACCESS(maps)->nr_maps_allocated = nr_maps_allocated; ··· 279 284 280 285 static void __maps__free_maps_by_name(struct maps *maps) 281 286 { 287 + if (!maps__maps_by_name(maps)) 288 + return; 289 + 282 290 /* 283 291 * Free everything to try to do it from the rbtree in the next search 284 292 */ ··· 289 291 map__put(maps__maps_by_name(maps)[i]); 290 292 291 293 zfree(&RC_CHK_ACCESS(maps)->maps_by_name); 294 + 295 + /* Consistent with maps__init(). When maps_by_name == NULL, maps_by_name_sorted == false */ 296 + maps__set_maps_by_name_sorted(maps, false); 292 297 } 293 298 294 299 static int map__start_cmp(const void *a, const void *b) ··· 1168 1167 } 1169 1168 maps__set_maps_by_address(kmaps, merged_maps_by_address); 1170 1169 maps__set_maps_by_address_sorted(kmaps, true); 1171 - zfree(maps__maps_by_name_addr(kmaps)); 1172 - maps__set_maps_by_name_sorted(kmaps, true); 1170 + __maps__free_maps_by_name(kmaps); 1173 1171 maps__set_nr_maps_allocated(kmaps, merged_nr_maps_allocated); 1174 1172 1175 1173 /* Copy entries before the new_map that can't overlap. */