Received: by 10.223.185.116 with SMTP id b49csp1020286wrg; Fri, 16 Feb 2018 10:57:26 -0800 (PST) X-Google-Smtp-Source: AH8x224bmxSUkCK0L3fnH8f/US/FnyKNOX1dqQ88NnRjED04m8MKLm3IET5zXsY5C08OV9GvN66r X-Received: by 10.101.75.11 with SMTP id r11mr5920549pgq.36.1518807446392; Fri, 16 Feb 2018 10:57:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518807446; cv=none; d=google.com; s=arc-20160816; b=AtS9I5gkaNb9vv94do1KWFuQRzC908xruXssYnXdqOxCYlmniT3l9Gc3FGRKSJYJhx 5NlInelG6HF+/9ZabSu3ch+tTn5J4nrp4csNGUE2ZGcfiVWB/feTladXuFpsqbRJfBPu hXTcRJO/T0fExIcViGB0TThx03ivy5h8V8MnS1/x5VmaAG4xi2m3gwHHLlMOf1ap8k79 zHIXtgG9IfgN6gZIrW5HSJc+XYQzuxOcfH4S02punYUzCgFCXhFHmkCStKaLD+SHT10n AM6RdFs9vC/M9bYx4mo1+EP4oBgUca+xrMrRInbPTEJSDLWriiYCQPiD3NmMfORzR6g8 uZmg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-disposition :content-transfer-encoding:mime-version:robot-unsubscribe:robot-id :git-commit-id:subject:to:references:in-reply-to:reply-to:cc :message-id:from:date:arc-authentication-results; bh=6FtOT16ENyz5Zef+8e5A6Bm4OQ/yHrsjNDWsvWUvC9k=; b=IlBPFKYATSKTGw3NCWqYKXrZONJ+lD+dg4vjzoEr/vnbfLG0/ANuIcdY+Wpe/95dRa LfEt3N0A2zxKjJSuG/2d2YGWq08ze54islbxbWR9H5Jjy1wqxFIcJAkR6ck8Kvj4HkgK hbfc2XgXb1IbtHd/iucPwLRzAIiACAkDWjv2Bqj9rLnVzo0cTqQwlfr9BZol5w5mvoXr jCAleoezH5vMYzwRO8k6VNozeuy69jSAbFjI/ZghanRfJxQhe0tfLezvQuhi2ow5+Vwb OaCMjZ88tzNoZttouqmqRW5A/r9WjsVpZGkurHK3vekDvaqfsbPTgvAg3WgkZVwDX2eI 8Qfw== ARC-Authentication-Results: i=1; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f90-v6si1467351plb.684.2018.02.16.10.57.12; Fri, 16 Feb 2018 10:57:26 -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 S932806AbeBPJvd (ORCPT + 99 others); Fri, 16 Feb 2018 04:51:33 -0500 Received: from terminus.zytor.com ([198.137.202.136]:52813 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932677AbeBPJvb (ORCPT ); Fri, 16 Feb 2018 04:51:31 -0500 Received: from terminus.zytor.com (localhost [127.0.0.1]) by terminus.zytor.com (8.15.2/8.15.2) with ESMTP id w1G9anir021771; Fri, 16 Feb 2018 01:36:49 -0800 Received: (from tipbot@localhost) by terminus.zytor.com (8.15.2/8.15.2/Submit) id w1G9anKG021768; Fri, 16 Feb 2018 01:36:49 -0800 Date: Fri, 16 Feb 2018 01:36:49 -0800 X-Authentication-Warning: terminus.zytor.com: tipbot set sender to tipbot@zytor.com using -f From: tip-bot for Kan Liang Message-ID: Cc: tglx@linutronix.de, hpa@zytor.com, ak@linux.intel.com, kan.liang@intel.com, jolsa@kernel.org, mingo@kernel.org, acme@redhat.com, wangnan0@huawei.com, namhyung@kernel.org, linux-kernel@vger.kernel.org, peterz@infradead.org, yao.jin@linux.intel.com Reply-To: tglx@linutronix.de, acme@redhat.com, mingo@kernel.org, jolsa@kernel.org, kan.liang@intel.com, ak@linux.intel.com, hpa@zytor.com, wangnan0@huawei.com, yao.jin@linux.intel.com, peterz@infradead.org, linux-kernel@vger.kernel.org, namhyung@kernel.org In-Reply-To: <1516310792-208685-7-git-send-email-kan.liang@intel.com> References: <1516310792-208685-7-git-send-email-kan.liang@intel.com> To: linux-tip-commits@vger.kernel.org Subject: [tip:perf/urgent] perf mmap: Discard 'prev' in perf_mmap__read() Git-Commit-ID: b4b036b4c76341a5034e872aca3727c4988a7304 X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline X-Spam-Status: No, score=-2.9 required=5.0 tests=ALL_TRUSTED,BAYES_00 autolearn=ham autolearn_force=no version=3.4.1 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on terminus.zytor.com Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit-ID: b4b036b4c76341a5034e872aca3727c4988a7304 Gitweb: https://git.kernel.org/tip/b4b036b4c76341a5034e872aca3727c4988a7304 Author: Kan Liang AuthorDate: Thu, 18 Jan 2018 13:26:21 -0800 Committer: Arnaldo Carvalho de Melo CommitDate: Thu, 15 Feb 2018 09:53:06 -0300 perf mmap: Discard 'prev' in perf_mmap__read() The 'start' and 'prev' variables are duplicates in perf_mmap__read(). Use 'map->prev' to replace 'start' in perf_mmap__read_*(). Suggested-by: Wang Nan Signed-off-by: Kan Liang Acked-by: Jiri Olsa Cc: Andi Kleen Cc: Jin Yao Cc: Namhyung Kim Cc: Peter Zijlstra Cc: Wang Nan Link: http://lkml.kernel.org/r/1516310792-208685-7-git-send-email-kan.liang@intel.com Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/util/mmap.c | 28 ++++++++++------------------ 1 file changed, 10 insertions(+), 18 deletions(-) diff --git a/tools/perf/util/mmap.c b/tools/perf/util/mmap.c index 38fa69d..125bfda 100644 --- a/tools/perf/util/mmap.c +++ b/tools/perf/util/mmap.c @@ -22,29 +22,27 @@ size_t perf_mmap__mmap_len(struct perf_mmap *map) /* When check_messup is true, 'end' must points to a good entry */ static union perf_event *perf_mmap__read(struct perf_mmap *map, - u64 start, u64 end, u64 *prev) + u64 *startp, u64 end) { unsigned char *data = map->base + page_size; union perf_event *event = NULL; - int diff = end - start; + int diff = end - *startp; if (diff >= (int)sizeof(event->header)) { size_t size; - event = (union perf_event *)&data[start & map->mask]; + event = (union perf_event *)&data[*startp & map->mask]; size = event->header.size; - if (size < sizeof(event->header) || diff < (int)size) { - event = NULL; - goto broken_event; - } + if (size < sizeof(event->header) || diff < (int)size) + return NULL; /* * Event straddles the mmap boundary -- header should always * be inside due to u64 alignment of output. */ - if ((start & map->mask) + size != ((start + size) & map->mask)) { - unsigned int offset = start; + if ((*startp & map->mask) + size != ((*startp + size) & map->mask)) { + unsigned int offset = *startp; unsigned int len = min(sizeof(*event), size), cpy; void *dst = map->event_copy; @@ -59,20 +57,15 @@ static union perf_event *perf_mmap__read(struct perf_mmap *map, event = (union perf_event *)map->event_copy; } - start += size; + *startp += size; } -broken_event: - if (prev) - *prev = start; - return event; } union perf_event *perf_mmap__read_forward(struct perf_mmap *map) { u64 head; - u64 old = map->prev; /* * Check if event was unmapped due to a POLLHUP/POLLERR. @@ -82,13 +75,12 @@ union perf_event *perf_mmap__read_forward(struct perf_mmap *map) head = perf_mmap__read_head(map); - return perf_mmap__read(map, old, head, &map->prev); + return perf_mmap__read(map, &map->prev, head); } union perf_event *perf_mmap__read_backward(struct perf_mmap *map) { u64 head, end; - u64 start = map->prev; /* * Check if event was unmapped due to a POLLHUP/POLLERR. @@ -118,7 +110,7 @@ union perf_event *perf_mmap__read_backward(struct perf_mmap *map) else end = head + map->mask + 1; - return perf_mmap__read(map, start, end, &map->prev); + return perf_mmap__read(map, &map->prev, end); } void perf_mmap__read_catchup(struct perf_mmap *map)