All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] perf: Fix failure to set cpumask when only one cpu
@ 2019-08-02  8:29 zhe.he
  2019-08-02  8:29 ` [PATCH 2/2] perf: Fix writing to illegal memory in handling cpumap mask zhe.he
                   ` (3 more replies)
  0 siblings, 4 replies; 8+ messages in thread
From: zhe.he @ 2019-08-02  8:29 UTC (permalink / raw)
  To: peterz, mingo, acme, alexander.shishkin, jolsa, namhyung,
	kan.liang, eranian, alexey.budankov, linux-kernel, zhe.he

From: He Zhe <zhe.he@windriver.com>

The buffer containing string used to set cpumask is overwritten by end of
string later in cpu_map__snprint_mask due to not enough memory space, when
there is only one cpu. And thus causes the following failure.

$ perf ftrace ls
failed to reset ftrace

This patch fixes the calculation of cpumask string size.

Signed-off-by: He Zhe <zhe.he@windriver.com>
---
 tools/perf/builtin-ftrace.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/perf/builtin-ftrace.c b/tools/perf/builtin-ftrace.c
index 66d5a66..0193128 100644
--- a/tools/perf/builtin-ftrace.c
+++ b/tools/perf/builtin-ftrace.c
@@ -173,7 +173,7 @@ static int set_tracing_cpumask(struct cpu_map *cpumap)
 	int last_cpu;
 
 	last_cpu = cpu_map__cpu(cpumap, cpumap->nr - 1);
-	mask_size = (last_cpu + 3) / 4 + 1;
+	mask_size = last_cpu / 4 + 2; /* one more byte for EOS */
 	mask_size += last_cpu / 32; /* ',' is needed for every 32th cpus */
 
 	cpumask = malloc(mask_size);
-- 
2.7.4


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

end of thread, other threads:[~2019-08-08 20:19 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-08-02  8:29 [PATCH 1/2] perf: Fix failure to set cpumask when only one cpu zhe.he
2019-08-02  8:29 ` [PATCH 2/2] perf: Fix writing to illegal memory in handling cpumap mask zhe.he
2019-08-08 13:36   ` Arnaldo Carvalho de Melo
2019-08-08 20:19   ` [tip:perf/urgent] perf cpumap: " tip-bot for He Zhe
2019-08-02 13:06 ` [PATCH 1/2] perf: Fix failure to set cpumask when only one cpu Jiri Olsa
2019-08-03  5:34   ` He Zhe
2019-08-08 13:29 ` Arnaldo Carvalho de Melo
2019-08-08 20:18 ` [tip:perf/urgent] perf ftrace: Fix failure to set cpumask when only one cpu is present tip-bot for He Zhe

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.