Em Fri, Aug 02, 2019 at 04:29:51PM +0800, zhe...@windriver.com escreveu:
> From: He Zhe <zhe...@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.

Please next time add this as well:

Fixes: dc23103278c5 ("perf ftrace: Add support for -a and -C option")

Applied,

- Arnaldo
 
> Signed-off-by: He Zhe <zhe...@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

-- 

- Arnaldo

Reply via email to