From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751222AbdEBPMI (ORCPT ); Tue, 2 May 2017 11:12:08 -0400 Received: from mail.kernel.org ([198.145.29.136]:60138 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750727AbdEBPMG (ORCPT ); Tue, 2 May 2017 11:12:06 -0400 Date: Tue, 2 May 2017 12:12:00 -0300 From: Arnaldo Carvalho de Melo To: Taeung Song Cc: linux-kernel@vger.kernel.org, Jiri Olsa , Namhyung Kim Subject: Re: [PATCH 2/7] perf config: Check list empty before showing configs Message-ID: <20170502151200.GA7891@kernel.org> References: <1493209268-5543-1-git-send-email-treeze.taeung@gmail.com> <1493209268-5543-3-git-send-email-treeze.taeung@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1493209268-5543-3-git-send-email-treeze.taeung@gmail.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 Wed, Apr 26, 2017 at 09:21:03PM +0900, Taeung Song escreveu: > If existent config files contains nothing, > the sections list in config_set can be empty. > > So check not only NULL pointer of config_set but > also the list in config_set. > +++ b/tools/perf/builtin-config.c > @@ -75,7 +75,7 @@ static int show_spec_config(struct perf_config_set *set, const char *var) > struct perf_config_section *section; > struct perf_config_item *item; > > - if (set == NULL) > + if (set == NULL || list_empty(&set->sections)) > return -1; But should we consider an error to have an empty config file? I don't think so :-\ - Arnaldo > > perf_config_items__for_each_entry(&set->sections, section) { > @@ -105,7 +105,7 @@ static int show_config(struct perf_config_set *set) > struct perf_config_section *section; > struct perf_config_item *item; > > - if (set == NULL) > + if (set == NULL || list_empty(&set->sections)) > return -1; > > perf_config_set__for_each_entry(set, section, item) { > diff --git a/tools/perf/util/config.c b/tools/perf/util/config.c > index 8d724f0..492c862 100644 > --- a/tools/perf/util/config.c > +++ b/tools/perf/util/config.c > @@ -707,7 +707,7 @@ int perf_config(config_fn_t fn, void *data) > struct perf_config_section *section; > struct perf_config_item *item; > > - if (config_set == NULL) > + if (config_set == NULL || list_empty(&config_set->sections)) > return -1; > > perf_config_set__for_each_entry(config_set, section, item) { > -- > 2.7.4