From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <bruce.richardson@intel.com>
Received: from mga09.intel.com (mga09.intel.com [134.134.136.24])
 by dpdk.org (Postfix) with ESMTP id 8DB8D968
 for <dev@dpdk.org>; Mon, 26 Jun 2017 17:31:04 +0200 (CEST)
Received: from fmsmga004.fm.intel.com ([10.253.24.48])
 by orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384;
 26 Jun 2017 08:31:02 -0700
X-ExtLoop1: 1
X-IronPort-AV: E=Sophos;i="5.39,396,1493708400"; d="scan'208";a="278753927"
Received: from bricha3-mobl3.ger.corp.intel.com ([10.237.221.28])
 by fmsmga004.fm.intel.com with SMTP; 26 Jun 2017 08:30:56 -0700
Received: by  (sSMTP sendmail emulation); Mon, 26 Jun 2017 16:30:55 +0100
Date: Mon, 26 Jun 2017 16:30:55 +0100
From: Bruce Richardson <bruce.richardson@intel.com>
To: Gaetan Rivet <gaetan.rivet@6wind.com>
Cc: dev@dpdk.org, Jan Blunck <jblunck@infradead.org>
Message-ID: <20170626153055.GA101992@bricha3-MOBL3.ger.corp.intel.com>
References: <cover.1498436062.git.gaetan.rivet@6wind.com>
 <ad9258bced8eba6443e0eeb08bde921d3d29cafe.1498436062.git.gaetan.rivet@6wind.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
In-Reply-To: <ad9258bced8eba6443e0eeb08bde921d3d29cafe.1498436062.git.gaetan.rivet@6wind.com>
Organization: Intel Research and =?iso-8859-1?Q?De=ACvel?=
 =?iso-8859-1?Q?opment?= Ireland Ltd.
User-Agent: Mutt/1.8.1 (2017-04-11)
Subject: Re: [dpdk-dev] [PATCH v5 01/12] bus: add bus iterator to find a bus
X-BeenThere: dev@dpdk.org
X-Mailman-Version: 2.1.15
Precedence: list
List-Id: DPDK patches and discussions <dev.dpdk.org>
List-Unsubscribe: <http://dpdk.org/ml/options/dev>,
 <mailto:dev-request@dpdk.org?subject=unsubscribe>
List-Archive: <http://dpdk.org/ml/archives/dev/>
List-Post: <mailto:dev@dpdk.org>
List-Help: <mailto:dev-request@dpdk.org?subject=help>
List-Subscribe: <http://dpdk.org/ml/listinfo/dev>,
 <mailto:dev-request@dpdk.org?subject=subscribe>
X-List-Received-Date: Mon, 26 Jun 2017 15:31:05 -0000

On Mon, Jun 26, 2017 at 02:21:59AM +0200, Gaetan Rivet wrote:
> From: Jan Blunck <jblunck@infradead.org>
> 
> This helper allows to iterate over all registered buses and find one
> matching data used as parameter.
> 
> Signed-off-by: Jan Blunck <jblunck@infradead.org>
> Signed-off-by: Gaetan Rivet <gaetan.rivet@6wind.com>
> ---
>  lib/librte_eal/bsdapp/eal/rte_eal_version.map   |  1 +
>  lib/librte_eal/common/eal_common_bus.c          | 20 ++++++++++++
>  lib/librte_eal/common/include/rte_bus.h         | 43 +++++++++++++++++++++++++
>  lib/librte_eal/linuxapp/eal/rte_eal_version.map |  1 +
>  4 files changed, 65 insertions(+)
> 

Two minor suggestions below. Otherwise:

Acked-by: Bruce Richardson <bruce.richardson@intel.com>

> diff --git a/lib/librte_eal/bsdapp/eal/rte_eal_version.map b/lib/librte_eal/bsdapp/eal/rte_eal_version.map
> index 2e48a73..ed09ab2 100644
> --- a/lib/librte_eal/bsdapp/eal/rte_eal_version.map
> +++ b/lib/librte_eal/bsdapp/eal/rte_eal_version.map
> @@ -162,6 +162,7 @@ DPDK_17.02 {
>  DPDK_17.05 {
>  	global:
>  
> +	rte_bus_find;
>  	rte_cpu_is_supported;
>  	rte_log_dump;
>  	rte_log_register;
> diff --git a/lib/librte_eal/common/eal_common_bus.c b/lib/librte_eal/common/eal_common_bus.c
> index 8f9baf8..4619eb2 100644
> --- a/lib/librte_eal/common/eal_common_bus.c
> +++ b/lib/librte_eal/common/eal_common_bus.c
> @@ -145,3 +145,23 @@ rte_bus_dump(FILE *f)
>  		}
>  	}
>  }
> +
> +struct rte_bus *
> +rte_bus_find(rte_bus_cmp_t cmp,
> +	     const void *data,
> +	     const struct rte_bus *start)
> +{
> +	struct rte_bus *bus = NULL;
> +	int started = start == NULL;

Please put brackets around the "start == NULL" to improve readability.
My first reading of this I assumed it was doing multiple assignment of
both start and started to NULL. To make it extra clear, prefix the
comparison with "!!".

> +
> +	TAILQ_FOREACH(bus, &rte_bus_list, next) {
> +		if (!started) {
> +			if (bus == start)
> +				started = 1;
> +			continue;
> +		}
> +		if (cmp(bus, data) == 0)
> +			break;
> +	}
> +	return bus;
> +}

I also think the name "started" is confusing, and might be better as the
slighly longer "start_found".