From: Remy Horton Date: Wed, 30 Nov 2016 02:47:29 +0000 (+0800) Subject: examples/ethtool: fix querying non-PCI devices X-Git-Tag: spdx-start~5280 X-Git-Url: http://git.droids-corp.org/?a=commitdiff_plain;h=6c66be9a769fdfeee3ca1d4c0d444e23402ce073;p=dpdk.git 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 --- diff --git a/doc/guides/rel_notes/release_17_02.rst b/doc/guides/rel_notes/release_17_02.rst index 3b650388aa..23f335aae9 100644 --- a/doc/guides/rel_notes/release_17_02.rst +++ b/doc/guides/rel_notes/release_17_02.rst @@ -70,6 +70,11 @@ Libraries Examples ~~~~~~~~ +* **examples/ethtool: Fixed crash with non-PCI devices.** + + Querying a non-PCI device was dereferencing non-existent PCI data + resulting in a segmentation fault. + Other ~~~~~ diff --git a/examples/ethtool/lib/rte_ethtool.c b/examples/ethtool/lib/rte_ethtool.c index a1f91d45d3..6f0ce848f2 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(®_info, 0, sizeof(reg_info)); rte_eth_dev_get_reg_info(port_id, ®_info);