Received: by 10.223.185.116 with SMTP id b49csp3558918wrg; Tue, 13 Feb 2018 04:18:30 -0800 (PST) X-Google-Smtp-Source: AH8x226wqPQTtVn5dxrG7lmnmw37OZqU/hbg33VwoVzFeRbZHvyJjPVF6Cq88jsGwRnz1LWOLETJ X-Received: by 2002:a17:902:b605:: with SMTP id b5-v6mr995291pls.318.1518524310353; Tue, 13 Feb 2018 04:18:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518524310; cv=none; d=google.com; s=arc-20160816; b=BiNnHXS18xUhvB7XVwyqsTZStvdE1dRf7Ddh17mTwTz3Ar1UzehcWKXEb9WStDuF23 6Fqj3mP1xSHvXN8GY8uEJlnTaMjzOb2xIqP3Rh0isV8NdXIzLVFD17sSTPwQO5ppBaWe wJBsDoQON7sb8vIX6isVjxHW/NqhptzYqkffCUlN6frCxhz7yy5a3Zx8qu0hhzujoywy 5JK7K8/CQuTKXvEOJgjDO9yzjjVt1PWlavPG5/mifyQF2gNCsVjDrTeTk4dr6XkhzsNU z3vE7PMdfWpqDc86elgHHekIy3BTWhJALYMBzO5NWDh43j6oGsbAjXx1rFfGsGDBnsZV O1ww== 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=/AeWER6n8ZImvnLxIx1XwEvNniyA38h1rZUGtIc9rMs=; b=Sz5BeI2+33NOibq7Lz6VqBfN2NlyFPEWp4HuMzwgLfz0oOro9tHRBQGtBQpl+d9mhT Ji/zT8ZiEGHuhseZAnjpTKogsAzTPbsRlll6m/4nZjGjexVJ6HaKENkU9kpNXIni6ixl frTlFtzZkR//i10b+ohfixw4+cHKok9zCUnyrSeu2b9Hy6yJnGGozJUHrp35BO67lSxy NrKdoPhR6dl4TdQRT4D0RzH95RpnxfilTZdyf+L1i2ezxGNkPoSra42zmkbDPr4UbdGa I/QnBz3JDVqsSfePUeuCLE46k1/4XpAVamlfvzYa719RuyNeL8D71quIuUGcj/o1u1Qb R/nQ== 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 s13-v6si7152797plp.787.2018.02.13.04.18.15; Tue, 13 Feb 2018 04:18:30 -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 S935223AbeBMMRF (ORCPT + 99 others); Tue, 13 Feb 2018 07:17:05 -0500 Received: from terminus.zytor.com ([198.137.202.136]:46025 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934945AbeBMMRB (ORCPT ); Tue, 13 Feb 2018 07:17:01 -0500 Received: from terminus.zytor.com (localhost [127.0.0.1]) by terminus.zytor.com (8.15.2/8.15.2) with ESMTP id w1DC6ZRE028598; Tue, 13 Feb 2018 04:06:35 -0800 Received: (from tipbot@localhost) by terminus.zytor.com (8.15.2/8.15.2/Submit) id w1DC6Y7v028589; Tue, 13 Feb 2018 04:06:34 -0800 Date: Tue, 13 Feb 2018 04:06:34 -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: linux-kernel@vger.kernel.org, ak@linux.intel.com, yao.jin@linux.intel.com, tglx@linutronix.de, mingo@kernel.org, acme@redhat.com, hpa@zytor.com, wangnan0@huawei.com, jolsa@kernel.org, peterz@infradead.org, kan.liang@intel.com, namhyung@kernel.org Reply-To: mingo@kernel.org, tglx@linutronix.de, yao.jin@linux.intel.com, linux-kernel@vger.kernel.org, ak@linux.intel.com, wangnan0@huawei.com, hpa@zytor.com, acme@redhat.com, peterz@infradead.org, jolsa@kernel.org, kan.liang@intel.com, 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: a41cf9d483fbf0a97e8b131b6a006f558fdd502d 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: a41cf9d483fbf0a97e8b131b6a006f558fdd502d Gitweb: https://git.kernel.org/tip/a41cf9d483fbf0a97e8b131b6a006f558fdd502d Author: Kan Liang AuthorDate: Thu, 18 Jan 2018 13:26:21 -0800 Committer: Arnaldo Carvalho de Melo CommitDate: Tue, 6 Feb 2018 10:11:50 -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)