Variable 'fd', which may receive negative value when open
"/dev/mem" file.

This patch added checking return value process.

Fixes: 67fc3ff97c39 ("net/pfe: introduce basic functions")
Cc: [email protected]

Signed-off-by: Min Hu (Connor) <[email protected]>
---
 drivers/net/pfe/pfe_ethdev.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/drivers/net/pfe/pfe_ethdev.c b/drivers/net/pfe/pfe_ethdev.c
index 8cf59e2..b4f5591 100644
--- a/drivers/net/pfe/pfe_ethdev.c
+++ b/drivers/net/pfe/pfe_ethdev.c
@@ -1049,6 +1049,12 @@ pmd_pfe_probe(struct rte_vdev_device *vdev)
        g_pfe->cbus_size = cbus_size;
 
        fd = open("/dev/mem", O_RDWR);
+       if (fd < 0) {
+               PFE_PMD_ERR("Can not open /dev/mem");
+               rc = -EIO;
+               goto err;
+       }
+
        g_pfe->cbus_baseaddr = mmap(NULL, cbus_size, PROT_READ | PROT_WRITE,
                                        MAP_SHARED, fd, cbus_addr);
        close(fd);
-- 
2.7.4

Reply via email to