[dpdk-dev,v7,06/15] bus: add helper to find which bus holds a device
Checks
Commit Message
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
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;
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?
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
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
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.
@@ -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;
@@ -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);
+}
@@ -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.
*/
@@ -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;