summaryrefslogtreecommitdiff
path: root/examples/ethtool
diff options
context:
space:
mode:
authorRemy Horton <remy.horton@intel.com>2016-11-30 10:47:29 +0800
committerThomas Monjalon <thomas.monjalon@6wind.com>2016-12-20 16:06:41 +0100
commit6c66be9a769fdfeee3ca1d4c0d444e23402ce073 (patch)
tree291355be1b041883a5ecfb27bb851c260ff362a9 /examples/ethtool
parent7dbdc5373c04cc83a7259675038e32c01b21b2a8 (diff)
downloaddpdk-6c66be9a769fdfeee3ca1d4c0d444e23402ce073.zip
dpdk-6c66be9a769fdfeee3ca1d4c0d444e23402ce073.tar.gz
dpdk-6c66be9a769fdfeee3ca1d4c0d444e23402ce073.tar.xz
examples/ethtool: fix querying non-PCI devices
Doing a device information query on a non-PCI device such as vhost was resulting in the dereferencing of a NULL pointer (the absent PCI data), causing a segmentation fault. Fixes: bda68ab9d1e7 ("examples/ethtool: add user-space ethtool sample application") Signed-off-by: Remy Horton <remy.horton@intel.com>
Diffstat (limited to 'examples/ethtool')
-rw-r--r--examples/ethtool/lib/rte_ethtool.c13
1 files changed, 9 insertions, 4 deletions
diff --git a/examples/ethtool/lib/rte_ethtool.c b/examples/ethtool/lib/rte_ethtool.c
index a1f91d4..6f0ce84 100644
--- a/examples/ethtool/lib/rte_ethtool.c
+++ b/examples/ethtool/lib/rte_ethtool.c
@@ -61,10 +61,15 @@ rte_ethtool_get_drvinfo(uint8_t port_id, struct ethtool_drvinfo *drvinfo)
dev_info.driver_name);
snprintf(drvinfo->version, sizeof(drvinfo->version), "%s",
rte_version());
- snprintf(drvinfo->bus_info, sizeof(drvinfo->bus_info),
- "%04x:%02x:%02x.%x",
- dev_info.pci_dev->addr.domain, dev_info.pci_dev->addr.bus,
- dev_info.pci_dev->addr.devid, dev_info.pci_dev->addr.function);
+ if (dev_info.pci_dev)
+ snprintf(drvinfo->bus_info, sizeof(drvinfo->bus_info),
+ "%04x:%02x:%02x.%x",
+ dev_info.pci_dev->addr.domain,
+ dev_info.pci_dev->addr.bus,
+ dev_info.pci_dev->addr.devid,
+ dev_info.pci_dev->addr.function);
+ else
+ snprintf(drvinfo->bus_info, sizeof(drvinfo->bus_info), "N/A");
memset(&reg_info, 0, sizeof(reg_info));
rte_eth_dev_get_reg_info(port_id, &reg_info);