From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752700AbdDKSNA (ORCPT ); Tue, 11 Apr 2017 14:13:00 -0400 Received: from mail.kernel.org ([198.145.29.136]:51112 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751995AbdDKSM6 (ORCPT ); Tue, 11 Apr 2017 14:12:58 -0400 Date: Tue, 11 Apr 2017 15:12:51 -0300 From: Arnaldo Carvalho de Melo To: David Carrillo-Cisneros Cc: linux-kernel@vger.kernel.org, Peter Zijlstra , Ingo Molnar , Alexander Shishkin , Andi Kleen , Simon Que , Wang Nan , Jiri Olsa , He Kuang , Masami Hiramatsu , Stephane Eranian , Paul Turner Subject: Re: [PATCH 6/7] perf tool: protect empty evlists Message-ID: <20170411181251.GB3275@kernel.org> References: <20170410201432.24807-1-davidcc@google.com> <20170410201432.24807-7-davidcc@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20170410201432.24807-7-davidcc@google.com> X-Url: http://acmel.wordpress.com User-Agent: Mutt/1.8.0 (2017-02-23) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Em Mon, Apr 10, 2017 at 01:14:31PM -0700, David Carrillo-Cisneros escreveu: > A common pattern in in pipe-mode bugs is accessing an empty evlist. > Return NULL to make it easier to catch this problems. This one is far reaching, we need to take care handling all places using these functions, albeit probably most cases will always have an evsel, I looked at builtin-top.c for instance, and I think we need to be more careful here, will leave this for later. - Arnaldo > Signed-off-by: David Carrillo-Cisneros > --- > tools/perf/util/evlist.h | 4 ++++ > 1 file changed, 4 insertions(+) > > diff --git a/tools/perf/util/evlist.h b/tools/perf/util/evlist.h > index 39942995f537..ba4788462325 100644 > --- a/tools/perf/util/evlist.h > +++ b/tools/perf/util/evlist.h > @@ -257,11 +257,15 @@ void perf_evlist__splice_list_tail(struct perf_evlist *evlist, > > static inline struct perf_evsel *perf_evlist__first(struct perf_evlist *evlist) > { > + if (list_empty(&evlist->entries)) > + return NULL; > return list_entry(evlist->entries.next, struct perf_evsel, node); > } > > static inline struct perf_evsel *perf_evlist__last(struct perf_evlist *evlist) > { > + if (list_empty(&evlist->entries)) > + return NULL; > return list_entry(evlist->entries.prev, struct perf_evsel, node); > } > > -- > 2.12.2.715.g7642488e1d-goog