From patchwork Mon Feb 29 19:22:07 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnaldo Carvalho de Melo X-Patchwork-Id: 63249 Delivered-To: patch@linaro.org Received: by 10.112.199.169 with SMTP id jl9csp1427137lbc; Mon, 29 Feb 2016 11:23:10 -0800 (PST) X-Received: by 10.66.234.166 with SMTP id uf6mr24489882pac.122.1456773788890; Mon, 29 Feb 2016 11:23:08 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e69si44730479pfd.66.2016.02.29.11.23.08; Mon, 29 Feb 2016 11:23:08 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754288AbcB2TWu (ORCPT + 30 others); Mon, 29 Feb 2016 14:22:50 -0500 Received: from bombadil.infradead.org ([198.137.202.9]:56021 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754047AbcB2TW1 (ORCPT ); Mon, 29 Feb 2016 14:22:27 -0500 Received: from [187.65.76.58] (helo=jouet.infradead.org) by bombadil.infradead.org with esmtpsa (Exim 4.80.1 #2 (Red Hat Linux)) id 1aaTOY-0000DG-89; Mon, 29 Feb 2016 19:22:14 +0000 Received: by jouet.infradead.org (Postfix, from userid 1000) id 9FC4E143533; Mon, 29 Feb 2016 16:22:08 -0300 (BRT) From: Arnaldo Carvalho de Melo To: Ingo Molnar Cc: linux-kernel@vger.kernel.org, Wang Nan , Alexei Starovoitov , He Kuang , Jiri Olsa , Li Zefan , Masami Hiramatsu , Namhyung Kim , pi3orama@163.com, Arnaldo Carvalho de Melo Subject: [PATCH 11/11] perf record: Ensure return non-zero rc when mmap fail Date: Mon, 29 Feb 2016 16:22:07 -0300 Message-Id: <1456773727-3005-12-git-send-email-acme@kernel.org> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1456773727-3005-1-git-send-email-acme@kernel.org> References: <1456773727-3005-1-git-send-email-acme@kernel.org> X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Wang Nan perf_evlist__mmap_ex() can fail without setting errno (for example, fail in condition checking. In this case all syscall is success). If this happen, record__open() incorrectly returns 0. Force setting rc is a quick way to avoid this problem, or we have to follow all possible code path in perf_evlist__mmap_ex() to make sure there's at least one system call before returning an error. Signed-off-by: Wang Nan Cc: Alexei Starovoitov Cc: He Kuang Cc: Jiri Olsa Cc: Li Zefan Cc: Masami Hiramatsu Cc: Namhyung Kim Cc: Zefan Li Cc: pi3orama@163.com Link: http://lkml.kernel.org/r/1456479154-136027-30-git-send-email-wangnan0@huawei.com Signed-off-by: He Kuang Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/builtin-record.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) -- 2.5.0 diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c index 46e2772f838e..515510ecc76a 100644 --- a/tools/perf/builtin-record.c +++ b/tools/perf/builtin-record.c @@ -324,7 +324,10 @@ try_again: } else { pr_err("failed to mmap with %d (%s)\n", errno, strerror_r(errno, msg, sizeof(msg))); - rc = -errno; + if (errno) + rc = -errno; + else + rc = -EINVAL; } goto out; }