[dpdk-dev] pci: pad vendor and device ID to 4 digits

Message ID 20170623172941.14423-1-daniel.verkamp@intel.com (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

Daniel Verkamp June 23, 2017, 5:29 p.m. UTC
  Some PCI vendor and device IDs have leading zeros.

Signed-off-by: Daniel Verkamp <daniel.verkamp@intel.com>
---
 lib/librte_eal/common/eal_common_pci.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
  

Comments

Stephen Hemminger June 23, 2017, 5:44 p.m. UTC | #1
On Fri, 23 Jun 2017 10:29:41 -0700
Daniel Verkamp <daniel.verkamp@intel.com> wrote:

> Some PCI vendor and device IDs have leading zeros.
> 
> Signed-off-by: Daniel Verkamp <daniel.verkamp@intel.com>
> ---
>  lib/librte_eal/common/eal_common_pci.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/lib/librte_eal/common/eal_common_pci.c b/lib/librte_eal/common/eal_common_pci.c
> index 78b097e..c23421f 100644
> --- a/lib/librte_eal/common/eal_common_pci.c
> +++ b/lib/librte_eal/common/eal_common_pci.c
> @@ -203,7 +203,7 @@ rte_pci_probe_one_driver(struct rte_pci_driver *dr,
>  		return 1;
>  	}
>  
> -	RTE_LOG(INFO, EAL, "  probe driver: %x:%x %s\n", dev->id.vendor_id,
> +	RTE_LOG(INFO, EAL, "  probe driver: %04x:%04x %s\n", dev->id.vendor_id,
>  		dev->id.device_id, dr->driver.name);
>  
>  	if (dr->drv_flags & RTE_PCI_DRV_NEED_MAPPING) {
> @@ -253,7 +253,7 @@ rte_pci_detach_dev(struct rte_pci_device *dev)
>  			loc->domain, loc->bus, loc->devid,
>  			loc->function, dev->device.numa_node);
>  
> -	RTE_LOG(DEBUG, EAL, "  remove driver: %x:%x %s\n", dev->id.vendor_id,
> +	RTE_LOG(DEBUG, EAL, "  remove driver: %04x:%04x %s\n", dev->id.vendor_id,
>  			dev->id.device_id, dr->driver.name);
>  
>  	if (dr->remove && (dr->remove(dev) < 0))
> @@ -427,7 +427,7 @@ pci_dump_one_device(FILE *f, struct rte_pci_device *dev)
>  
>  	fprintf(f, PCI_PRI_FMT, dev->addr.domain, dev->addr.bus,
>  	       dev->addr.devid, dev->addr.function);
> -	fprintf(f, " - vendor:%x device:%x\n", dev->id.vendor_id,
> +	fprintf(f, " - vendor:%04x device:%04x\n", dev->id.vendor_id,
>  	       dev->id.device_id);
>  
>  	for (i = 0; i != sizeof(dev->mem_resource) /

It would be better to use a format consistent with PCI_PRI_FMT, as in:
	RTE_LOG(DEBUG, EAL, "  remove driver: %.4" PRIx16 ":%.4" PRIx16 " %s\n",

Maybe introduce PCI_VENDOR_FMT
#define PCI_VENDOR_FMT   "%.4" PRIx16 ":%.4" PRIx16
  

Patch

diff --git a/lib/librte_eal/common/eal_common_pci.c b/lib/librte_eal/common/eal_common_pci.c
index 78b097e..c23421f 100644
--- a/lib/librte_eal/common/eal_common_pci.c
+++ b/lib/librte_eal/common/eal_common_pci.c
@@ -203,7 +203,7 @@  rte_pci_probe_one_driver(struct rte_pci_driver *dr,
 		return 1;
 	}
 
-	RTE_LOG(INFO, EAL, "  probe driver: %x:%x %s\n", dev->id.vendor_id,
+	RTE_LOG(INFO, EAL, "  probe driver: %04x:%04x %s\n", dev->id.vendor_id,
 		dev->id.device_id, dr->driver.name);
 
 	if (dr->drv_flags & RTE_PCI_DRV_NEED_MAPPING) {
@@ -253,7 +253,7 @@  rte_pci_detach_dev(struct rte_pci_device *dev)
 			loc->domain, loc->bus, loc->devid,
 			loc->function, dev->device.numa_node);
 
-	RTE_LOG(DEBUG, EAL, "  remove driver: %x:%x %s\n", dev->id.vendor_id,
+	RTE_LOG(DEBUG, EAL, "  remove driver: %04x:%04x %s\n", dev->id.vendor_id,
 			dev->id.device_id, dr->driver.name);
 
 	if (dr->remove && (dr->remove(dev) < 0))
@@ -427,7 +427,7 @@  pci_dump_one_device(FILE *f, struct rte_pci_device *dev)
 
 	fprintf(f, PCI_PRI_FMT, dev->addr.domain, dev->addr.bus,
 	       dev->addr.devid, dev->addr.function);
-	fprintf(f, " - vendor:%x device:%x\n", dev->id.vendor_id,
+	fprintf(f, " - vendor:%04x device:%04x\n", dev->id.vendor_id,
 	       dev->id.device_id);
 
 	for (i = 0; i != sizeof(dev->mem_resource) /