bus/pci: fix return value check of device FD
Checks
Commit Message
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(+)
Comments
On 6/12/2023 6:11 AM, Chenbo Xia wrote:
> 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>
> ---
Acked-by: Anatoly Burakov <anatoly.burakov@intel.com>
12/06/2023 11:47, Burakov, Anatoly:
> On 6/12/2023 6:11 AM, Chenbo Xia wrote:
> > 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>
> > ---
>
> Acked-by: Anatoly Burakov <anatoly.burakov@intel.com>
Applied, thanks.
@@ -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;