[dpdk-dev,1/2] examples/kni: check if pci_dev isn't NULL before using it

Message ID 1508154348-10988-2-git-send-email-tdu@semihalf.com (mailing list archive)
State Accepted, archived
Delegated to: Ferruh Yigit
Headers

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation success Compilation OK

Commit Message

Tomasz Duszynski Oct. 16, 2017, 11:45 a.m. UTC
  Since virtual devices, i.e mrvl net pmd, do not touch pci_dev
dereferencing it will cause segmentation fault as by default
it's set to NULL in rte_eth_dev_info_get().

Signed-off-by: Tomasz Duszynski <tdu@semihalf.com>
---
 examples/kni/main.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

--
2.7.4
  

Comments

Ferruh Yigit Oct. 21, 2017, 12:26 a.m. UTC | #1
On 10/16/2017 4:45 AM, Tomasz Duszynski wrote:
> Since virtual devices, i.e mrvl net pmd, do not touch pci_dev
> dereferencing it will cause segmentation fault as by default
> it's set to NULL in rte_eth_dev_info_get().
> 
> Signed-off-by: Tomasz Duszynski <tdu@semihalf.com>

Acked-by: Ferruh Yigit <ferruh.yigit@intel.com>
  
Thomas Monjalon Oct. 24, 2017, 10:05 p.m. UTC | #2
21/10/2017 02:26, Ferruh Yigit:
> On 10/16/2017 4:45 AM, Tomasz Duszynski wrote:
> > Since virtual devices, i.e mrvl net pmd, do not touch pci_dev
> > dereferencing it will cause segmentation fault as by default
> > it's set to NULL in rte_eth_dev_info_get().
> > 
> > Signed-off-by: Tomasz Duszynski <tdu@semihalf.com>
> 
> Acked-by: Ferruh Yigit <ferruh.yigit@intel.com>

Fixed title: examples/kni: check PCI info not NULL before reading

Applied, thanks

The patch 2/2 is left alone as it may be unneeded.
  

Patch

diff --git a/examples/kni/main.c b/examples/kni/main.c
index 6d9e4a6..cb48fb5 100644
--- a/examples/kni/main.c
+++ b/examples/kni/main.c
@@ -805,8 +805,11 @@  kni_alloc(uint16_t port_id)

 			memset(&dev_info, 0, sizeof(dev_info));
 			rte_eth_dev_info_get(port_id, &dev_info);
-			conf.addr = dev_info.pci_dev->addr;
-			conf.id = dev_info.pci_dev->id;
+
+			if (dev_info.pci_dev) {
+				conf.addr = dev_info.pci_dev->addr;
+				conf.id = dev_info.pci_dev->id;
+			}

 			memset(&ops, 0, sizeof(ops));
 			ops.port_id = port_id;