From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752756AbbIBNzW (ORCPT ); Wed, 2 Sep 2015 09:55:22 -0400 Received: from mx1.redhat.com ([209.132.183.28]:44078 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750743AbbIBNzV (ORCPT ); Wed, 2 Sep 2015 09:55:21 -0400 Date: Wed, 2 Sep 2015 10:55:13 -0300 From: Arnaldo Carvalho de Melo To: pi3orama Cc: Jiri Olsa , "Wangnan (F)" , "masami.hiramatsu.pt@hitachi.com" , Alexei Starovoitov , Jiri Olsa , Namhyung Kim , Zefan Li , acme@kernel.org, "linux-kernel@vger.kernel.org" Subject: Re: [PATCH] perf tools: Don't write to evsel if parser doesn't collect evsel Message-ID: <20150902135513.GJ22331@redhat.com> References: <50399556C9727B4D88A595C8584AAB37525027C2@GSjpTKYDCembx32.service.hitachi.net> <1441176553-116129-1-git-send-email-wangnan0@huawei.com> <55E69D06.4050005@huawei.com> <20150902115415.GH8598@krava.brq.redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Url: http://acmel.wordpress.com User-Agent: Mutt/1.5.20 (2009-12-10) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Em Wed, Sep 02, 2015 at 08:05:54PM +0800, pi3orama escreveu: > 发自我的 iPhone > > 在 2015年9月2日,下午7:54,Jiri Olsa 写道: > >> On Wed, Sep 02, 2015 at 02:53:58PM +0800, Wangnan (F) wrote: > >>> @@ -1252,7 +1262,13 @@ foreach_evsel_in_last_glob(struct perf_evlist *evlist, > >>> struct perf_evsel *last = NULL; > >>> int err; > >>> - if (evlist->nr_entries > 0) > >>> + /* > >>> + * Don't return when list_empty, give func a chance to report > >>> + * error when it found last == NULL. > >>> + * > >>> + * So no need to WARN here, let *func do this. > >>> + */ > >>> + if (!list_empty(&evlist->entries)) > > why is it better than to check evlist->nr_entries? > > evlist->nr_entries is equivalent to !list_empty(&evlist->entries) in here, right? > By checking list we won't rely on the assumption that nr_entries reflects the > actual number of elements in that list, makes the logic of this code more compact. But why would we want to break that assumption? If I see FOO->entries and FOO->nr_entries, it is reasonable to expect that whatever data structure FOO->entries may be has FOO->nr_entries in it, lets not break that assumption. - Arnaldo > Don't you think so? > > At this point they are equivalent, but the whole patch is preventive action.