diff mbox series

[01/10] net/pfe: check return value

Message ID 1618839289-33224-2-git-send-email-humin29@huawei.com (mailing list archive)
State New
Delegated to: Thomas Monjalon
Headers show
Series fixes for clean code | expand

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Min Hu (Connor) April 19, 2021, 1:34 p.m. UTC
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: stable@dpdk.org

Signed-off-by: Min Hu (Connor) <humin29@huawei.com>
---
 drivers/net/pfe/pfe_ethdev.c | 6 ++++++
 1 file changed, 6 insertions(+)
diff mbox series

Patch

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);