[dpdk-dev,v7,06/15] bus: add helper to find which bus holds a device

Message ID 20170629182206.1072-7-jblunck@infradead.org (mailing list archive)
State Superseded, archived
Headers

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation success Compilation OK

Commit Message

Jan Blunck June 29, 2017, 6:21 p.m. UTC
  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          | 23 +++++++++++++++++++++++
 lib/librte_eal/common/include/rte_bus.h         |  5 +++++
 lib/librte_eal/linuxapp/eal/rte_eal_version.map |  1 +
 4 files changed, 30 insertions(+)
  

Comments

Thomas Monjalon June 30, 2017, 9:16 a.m. UTC | #1
29/06/2017 20:21, Jan Blunck:
> +static int
> +bus_find_device(const struct rte_bus *bus, const void *_dev)
> +{
> +	struct rte_device *dev;
> +
> +	dev = bus->find_device(NULL, cmp_rte_device, _dev);
> +	return !dev;
> +}

The preferred code style is to make explicit the NULL comparisons:
	return dev == NULL;
  
Jan Blunck June 30, 2017, 4:46 p.m. UTC | #2
On Fri, Jun 30, 2017 at 11:16 AM, Thomas Monjalon <thomas@monjalon.net> wrote:
> 29/06/2017 20:21, Jan Blunck:
>> +static int
>> +bus_find_device(const struct rte_bus *bus, const void *_dev)
>> +{
>> +     struct rte_device *dev;
>> +
>> +     dev = bus->find_device(NULL, cmp_rte_device, _dev);
>> +     return !dev;
>> +}
>
> The preferred code style is to make explicit the NULL comparisons:
>         return dev == NULL;

Oh, interesting ... not a lot of C++ programmers around here I guess.

Does this mean you also want me to make integer tests explicit again 0?
  
Thomas Monjalon June 30, 2017, 6:29 p.m. UTC | #3
30/06/2017 18:46, Jan Blunck:
> On Fri, Jun 30, 2017 at 11:16 AM, Thomas Monjalon <thomas@monjalon.net> wrote:
> > 29/06/2017 20:21, Jan Blunck:
> >> +static int
> >> +bus_find_device(const struct rte_bus *bus, const void *_dev)
> >> +{
> >> +     struct rte_device *dev;
> >> +
> >> +     dev = bus->find_device(NULL, cmp_rte_device, _dev);
> >> +     return !dev;
> >> +}
> >
> > The preferred code style is to make explicit the NULL comparisons:
> >         return dev == NULL;
> 
> Oh, interesting ... not a lot of C++ programmers around here I guess.
> 
> Does this mean you also want me to make integer tests explicit again 0?

Good question, I don't know.
I know only this part of the coding rules:
	http://dpdk.org/doc/guides/contributing/coding_style.html#null-pointers
  
Bruce Richardson June 30, 2017, 9:24 p.m. UTC | #4
On Fri, Jun 30, 2017 at 08:29:06PM +0200, Thomas Monjalon wrote:
> 30/06/2017 18:46, Jan Blunck:
> > On Fri, Jun 30, 2017 at 11:16 AM, Thomas Monjalon <thomas@monjalon.net> wrote:
> > > 29/06/2017 20:21, Jan Blunck:
> > >> +static int
> > >> +bus_find_device(const struct rte_bus *bus, const void *_dev)
> > >> +{
> > >> +     struct rte_device *dev;
> > >> +
> > >> +     dev = bus->find_device(NULL, cmp_rte_device, _dev);
> > >> +     return !dev;
> > >> +}
> > >
> > > The preferred code style is to make explicit the NULL comparisons:
> > >         return dev == NULL;
> > 
> > Oh, interesting ... not a lot of C++ programmers around here I guess.
> > 
> > Does this mean you also want me to make integer tests explicit again 0?
> 
> Good question, I don't know.
> I know only this part of the coding rules:
> 	http://dpdk.org/doc/guides/contributing/coding_style.html#null-pointers
> 
Yes, I noticed that gap the other day. IMHO for consistency the integers
should similarly be compared to 0/non-zero explicitly rather than using
"!" operator. The exception I would allow is where a function is named
in such a way that is clearly returns a boolean value as int e.g. a
function "int is_computer_on()".

/Bruce
  
Bruce Richardson June 30, 2017, 9:25 p.m. UTC | #5
On Fri, Jun 30, 2017 at 06:46:31PM +0200, Jan Blunck wrote:
> On Fri, Jun 30, 2017 at 11:16 AM, Thomas Monjalon <thomas@monjalon.net> wrote:
> > 29/06/2017 20:21, Jan Blunck:
> >> +static int
> >> +bus_find_device(const struct rte_bus *bus, const void *_dev)
> >> +{
> >> +     struct rte_device *dev;
> >> +
> >> +     dev = bus->find_device(NULL, cmp_rte_device, _dev);
> >> +     return !dev;
> >> +}
> >
> > The preferred code style is to make explicit the NULL comparisons:
> >         return dev == NULL;
> 
> Oh, interesting ... not a lot of C++ programmers around here I guess.
> 
> Does this mean you also want me to make integer tests explicit again 0?

Please do.
  

Patch

diff --git a/lib/librte_eal/bsdapp/eal/rte_eal_version.map b/lib/librte_eal/bsdapp/eal/rte_eal_version.map
index ed09ab2..f1a0765 100644
--- a/lib/librte_eal/bsdapp/eal/rte_eal_version.map
+++ b/lib/librte_eal/bsdapp/eal/rte_eal_version.map
@@ -163,6 +163,7 @@  DPDK_17.05 {
 	global:
 
 	rte_bus_find;
+	rte_bus_find_by_device;
 	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 3094daa..276cce6 100644
--- a/lib/librte_eal/common/eal_common_bus.c
+++ b/lib/librte_eal/common/eal_common_bus.c
@@ -164,3 +164,26 @@  rte_bus_find(const struct rte_bus *start, rte_bus_cmp_t cmp,
 	}
 	return bus;
 }
+
+static int
+cmp_rte_device(const struct rte_device *dev1, const void *_dev2)
+{
+	const struct rte_device *dev2 = _dev2;
+
+	return dev1 != dev2;
+}
+
+static int
+bus_find_device(const struct rte_bus *bus, const void *_dev)
+{
+	struct rte_device *dev;
+
+	dev = bus->find_device(NULL, cmp_rte_device, _dev);
+	return !dev;
+}
+
+struct rte_bus *
+rte_bus_find_by_device(const struct rte_device *dev)
+{
+	return rte_bus_find(NULL, bus_find_device, (const void *)dev);
+}
diff --git a/lib/librte_eal/common/include/rte_bus.h b/lib/librte_eal/common/include/rte_bus.h
index 052ac8d..f8b3215 100644
--- a/lib/librte_eal/common/include/rte_bus.h
+++ b/lib/librte_eal/common/include/rte_bus.h
@@ -210,6 +210,11 @@  struct rte_bus *rte_bus_find(const struct rte_bus *start, rte_bus_cmp_t cmp,
 			     const void *data);
 
 /**
+ * Find the registered bus for a particular device.
+ */
+struct rte_bus *rte_bus_find_by_device(const struct rte_device *dev);
+
+/**
  * Helper for Bus registration.
  * The constructor has higher priority than PMD constructors.
  */
diff --git a/lib/librte_eal/linuxapp/eal/rte_eal_version.map b/lib/librte_eal/linuxapp/eal/rte_eal_version.map
index 6efa517..6f77222 100644
--- a/lib/librte_eal/linuxapp/eal/rte_eal_version.map
+++ b/lib/librte_eal/linuxapp/eal/rte_eal_version.map
@@ -167,6 +167,7 @@  DPDK_17.05 {
 	global:
 
 	rte_bus_find;
+	rte_bus_find_by_device;
 	rte_cpu_is_supported;
 	rte_intr_free_epoll_fd;
 	rte_log_dump;