linux-perf-users.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] perf stat: allocation check when calculating cache instance ID
@ 2024-05-27  9:03 yskelg
  2024-05-28 18:56 ` Namhyung Kim
  0 siblings, 1 reply; 3+ messages in thread
From: yskelg @ 2024-05-27  9:03 UTC (permalink / raw)
  To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
	Namhyung Kim, Mark Rutland, Alexander Shishkin, Jiri Olsa,
	Ian Rogers, Adrian Hunter, Liang, Kan
  Cc: Gautham Shenoy, K Prateek Nayak, skhan, Austin Kim, shjy180909,
	linux-perf-users, linux-kernel, linux-kernel-mentees,
	Yunseong Kim

From: Yunseong Kim <yskelg@gmail.com>

Adds an allocation check for cpu_map before perf_cpu_map__min() accessing

Signed-off-by: Yunseong Kim <yskelg@gmail.com>
---
 tools/perf/builtin-stat.c | 24 +++++++++++++-----------
 1 file changed, 13 insertions(+), 11 deletions(-)

diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
index 35f79b48e8dc..1f238824abb2 100644
--- a/tools/perf/builtin-stat.c
+++ b/tools/perf/builtin-stat.c
@@ -1291,20 +1291,22 @@ static struct option stat_options[] = {
  */
 static int cpu__get_cache_id_from_map(struct perf_cpu cpu, char *map)
 {
-	int id;
+	int id = cpu.cpu;
 	struct perf_cpu_map *cpu_map = perf_cpu_map__new(map);
 
-	/*
-	 * If the map contains no CPU, consider the current CPU to
-	 * be the first online CPU in the cache domain else use the
-	 * first online CPU of the cache domain as the ID.
-	 */
-	id = perf_cpu_map__min(cpu_map).cpu;
-	if (id == -1)
-		id = cpu.cpu;
+	if (cpu_map) {
+		/*
+		 * If the map contains no CPU, consider the current CPU to
+		 * be the first online CPU in the cache domain else use the
+		 * first online CPU of the cache domain as the ID.
+		 */
+		id = perf_cpu_map__min(cpu_map).cpu;
+		if (id == -1)
+			id = cpu.cpu;
 
-	/* Free the perf_cpu_map used to find the cache ID */
-	perf_cpu_map__put(cpu_map);
+		/* Free the perf_cpu_map used to find the cache ID */
+		perf_cpu_map__put(cpu_map);
+	}
 
 	return id;
 }
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-05-30 11:43 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-05-27  9:03 [PATCH] perf stat: allocation check when calculating cache instance ID yskelg
2024-05-28 18:56 ` Namhyung Kim
2024-05-30 11:43   ` Yunseong Kim

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).