[dpdk-dev] [PATCH v4 3/9] bus: add helper to find bus for a particular device

Thomas Monjalon thomas at monjalon.net
Wed Jun 21 14:11:05 CEST 2017


21/06/2017 01:29, Gaetan Rivet:
> +static int
> +cmp_rte_device(const struct rte_device *dev, const void *_dev2)

Better to rename dev into dev1.

> +{
> +	const struct rte_device *dev2 = _dev2;
> +
> +	return !(dev == dev2);

simpler: return dev1 != dev2

[...]
> +static int
> +bus_find_device(const struct rte_bus *bus, const void *_dev)
> +{
> +	struct rte_device *dev;
> +
> +	if (!bus->find_device)

It is preferred to check pointers against NULL.

> +		return -1;
> +	dev = bus->find_device(cmp_rte_device, _dev);
> +	return !dev;

Here also: return dev == NULL:

> +}
> +
> +struct rte_bus *rte_bus_find_by_device(const struct rte_device *dev)
> +{
> +	return rte_bus_find(bus_find_device, (const void *)dev, NULL);
> +}

Nice



More information about the dev mailing list