All of lore.kernel.org
 help / color / mirror / Atom feed
From: Chenbo Xia <chenbo.xia@intel.com>
To: dev@dpdk.org
Cc: anatoly.burakov@intel.com
Subject: [PATCH] bus/pci: fix return value check of device FD
Date: Mon, 12 Jun 2023 13:11:27 +0800	[thread overview]
Message-ID: <20230612051127.44418-1-chenbo.xia@intel.com> (raw)

Fixing return value check of rte_intr_dev_fd_get() to make sure
negative device FD will not be used later.

Coverity issue: 385380, 385373
Fixes: 095cf6e68b28 ("bus/pci: introduce MMIO read/write")
Fixes: 4b741542ecde ("bus/pci: avoid depending on private kernel value")

Signed-off-by: Chenbo Xia <chenbo.xia@intel.com>
---
 drivers/bus/pci/linux/pci_vfio.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/drivers/bus/pci/linux/pci_vfio.c b/drivers/bus/pci/linux/pci_vfio.c
index ef8f9f4197..e634de8322 100644
--- a/drivers/bus/pci/linux/pci_vfio.c
+++ b/drivers/bus/pci/linux/pci_vfio.c
@@ -71,6 +71,8 @@ pci_vfio_read_config(const struct rte_pci_device *dev,
 	int fd;
 
 	fd = rte_intr_dev_fd_get(dev->intr_handle);
+	if (fd < 0)
+		return -1;
 
 	if (pci_vfio_get_region(dev, VFIO_PCI_CONFIG_REGION_INDEX,
 				&size, &offset) != 0)
@@ -90,6 +92,8 @@ pci_vfio_write_config(const struct rte_pci_device *dev,
 	int fd;
 
 	fd = rte_intr_dev_fd_get(dev->intr_handle);
+	if (fd < 0)
+		return -1;
 
 	if (pci_vfio_get_region(dev, VFIO_PCI_CONFIG_REGION_INDEX,
 				&size, &offset) != 0)
@@ -1369,6 +1373,8 @@ pci_vfio_mmio_read(const struct rte_pci_device *dev, int bar,
 	int fd;
 
 	fd = rte_intr_dev_fd_get(dev->intr_handle);
+	if (fd < 0)
+		return -1;
 
 	if (pci_vfio_get_region(dev, bar, &size, &offset) != 0)
 		return -1;
@@ -1387,6 +1393,8 @@ pci_vfio_mmio_write(const struct rte_pci_device *dev, int bar,
 	int fd;
 
 	fd = rte_intr_dev_fd_get(dev->intr_handle);
+	if (fd < 0)
+		return -1;
 
 	if (pci_vfio_get_region(dev, bar, &size, &offset) != 0)
 		return -1;
-- 
2.17.1


             reply	other threads:[~2023-06-12  5:37 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-12  5:11 Chenbo Xia [this message]
2023-06-12  9:47 ` [PATCH] bus/pci: fix return value check of device FD Burakov, Anatoly
2023-06-12 16:36   ` Thomas Monjalon

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230612051127.44418-1-chenbo.xia@intel.com \
    --to=chenbo.xia@intel.com \
    --cc=anatoly.burakov@intel.com \
    --cc=dev@dpdk.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.