From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0CFCDC3A5A3 for ; Tue, 27 Aug 2019 08:08:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D3242204EC for ; Tue, 27 Aug 2019 08:08:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1566893291; bh=mmO40OMKYBpLQ8t86cPFUw9lzxw7bu2lLFID7NXlxKc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=eLZB421s4xJHnMFx4iV6woQxGXV+X0w+7wjvyYFsVpNf3+FMulHl+PKi+9XNy/HwO WXW0KKQO5AYEyRCoTGuY2f9SVvgLAEeWEThZ6GoYfX0OoDhyiBWIp/KwtA3E1qwm7/ totEgeQGMrEw6/fEfvCAb9pqs7v8HKvktBCIQNfA= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731455AbfH0IIH (ORCPT ); Tue, 27 Aug 2019 04:08:07 -0400 Received: from mail.kernel.org ([198.145.29.99]:36690 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731928AbfH0IGl (ORCPT ); Tue, 27 Aug 2019 04:06:41 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 2C4B5206BA; Tue, 27 Aug 2019 08:06:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1566893200; bh=mmO40OMKYBpLQ8t86cPFUw9lzxw7bu2lLFID7NXlxKc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=zjTX6kXj9t5Q8A8dpVeDMkQPxsKW/9DhewjYTE3uyWYBUC2KhTX8QwS4DltNgjKbM hJsIyQUWXI9+xxyE5JP/NTAwKQgHg7Qy6I/0vKsJXSnr/77HBeycbeTScxqRzwX+rw loya4XMc5lKQD2gz1UnAfgGGVJM9mZ+eKADZzwDQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, He Zhe , Arnaldo Carvalho de Melo , Alexander Shishkin , Alexey Budankov , Jiri Olsa , Kan Liang , Namhyung Kim , Peter Zijlstra , Stephane Eranian , Sasha Levin Subject: [PATCH 5.2 103/162] perf ftrace: Fix failure to set cpumask when only one cpu is present Date: Tue, 27 Aug 2019 09:50:31 +0200 Message-Id: <20190827072741.861943403@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20190827072738.093683223@linuxfoundation.org> References: <20190827072738.093683223@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org [ 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 Tested-by: Arnaldo Carvalho de Melo Cc: Alexander Shishkin Cc: Alexey Budankov Cc: Jiri Olsa Cc: Kan Liang Cc: Namhyung Kim Cc: Peter Zijlstra Cc: Stephane Eranian 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 Signed-off-by: Sasha Levin --- 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