pci: consolidate address comparisons
authorTetsuya Mukawa <mukawa@igel.co.jp>
Wed, 25 Feb 2015 19:32:19 +0000 (04:32 +0900)
committerThomas Monjalon <thomas.monjalon@6wind.com>
Wed, 25 Feb 2015 22:38:00 +0000 (23:38 +0100)
commitc0ce0577e84de15b2d3f6301f0b4ce6826900e9b
treee7b7dade908916a90f59fec16d0d63cbd7dd1f3c
parentcc4fe5c45d09e5c0d75a64b4a1bdae728b886889
pci: consolidate address comparisons

This patch replaces pci_addr_comparison() and memcmp() of pci addresses by
rte_eal_compare_pci_addr().

To compare PCI addresses, rte_eal_compare_pci_addr() doesn't use memcmp().
This is because sizeof(struct rte_pci_addr) returns 6, but actually
this structure is like below.

struct rte_pci_addr {
        uint16_t domain;                /**< Device domain */
        uint8_t bus;                    /**< Device bus */
        uint8_t devid;                  /**< Device ID */
        uint8_t function;               /**< Device function. */
};

If the structure is dynamically allocated in a function without bzero,
last 1 byte may have value. As a result, memcmp may not work.
To avoid such a case, rte_eal_compare_pci_addr() compare following values.

        dev_addr = (addr->domain << 24) | (addr->bus << 16) |
                                (addr->devid << 8) | addr->function;

Signed-off-by: Tetsuya Mukawa <mukawa@igel.co.jp>
lib/librte_eal/bsdapp/eal/eal_pci.c
lib/librte_eal/common/eal_common_pci.c
lib/librte_eal/common/include/rte_pci.h
lib/librte_eal/linuxapp/eal/eal_pci.c
lib/librte_eal/linuxapp/eal/eal_pci_uio.c