lkml.org 
[lkml]   [2019]   [Aug]   [27]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    Patch in this message
    /
    From
    Subject[PATCH 5.2 103/162] perf ftrace: Fix failure to set cpumask when only one cpu is present
    Date
    [ Upstream commit cf30ae726c011e0372fd4c2d588466c8b50a8907 ]

    The buffer containing the string used to set cpumask is overwritten at
    the end of the 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 the cpumask string size.

    Signed-off-by: He Zhe <zhe.he@windriver.com>
    Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
    Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
    Cc: Alexey Budankov <alexey.budankov@linux.intel.com>
    Cc: Jiri Olsa <jolsa@redhat.com>
    Cc: Kan Liang <kan.liang@linux.intel.com>
    Cc: Namhyung Kim <namhyung@kernel.org>
    Cc: Peter Zijlstra <peterz@infradead.org>
    Cc: Stephane Eranian <eranian@google.com>
    Fixes: dc23103278c5 ("perf ftrace: Add support for -a and -C option")
    Link: http://lkml.kernel.org/r/1564734592-15624-1-git-send-email-zhe.he@windriver.com
    Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
    Signed-off-by: Sasha Levin <sashal@kernel.org>
    ---
    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 9c228c55e1fb7..22386ab350504 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.20.1


    \
     
     \ /
      Last update: 2019-08-27 10:08    [W:3.854 / U:0.040 seconds]
    ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site