[01/10] net/pfe: check return value
Checks
Commit Message
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(+)
Comments
On Mon, 19 Apr 2021 21:34:40 +0800
"Min Hu (Connor)" <humin29@huawei.com> wrote:
>
> fd = open("/dev/mem", O_RDWR);
> + if (fd < 0) {
> + PFE_PMD_ERR("Can not open /dev/mem");
> + rc = -EIO;
> + goto err;
> + }
> +
This patch makes sense and should be applied.
But the errno is most like EPERM so maybe:
rc = -errno;
PS: /dev/mem is a bad idea, Linux kernel config often disables
it in distributions. Not sure why this driver can't use UIO or VFIO
like normal devices. This should have been caught during code review.
@@ -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);