Skip to content

Commit 6578ed8

Browse files
rchatreawilliam
authored andcommitted
vfio/pci: Remove negative check on unsigned vector
User space provides the vector as an unsigned int that is checked early for validity (vfio_set_irqs_validate_and_prepare()). A later negative check of the provided vector is not necessary. Remove the negative check and ensure the type used for the vector is consistent as an unsigned int. Signed-off-by: Reinette Chatre <[email protected]> Reviewed-by: Kevin Tian <[email protected]> Acked-by: Thomas Gleixner <[email protected]> Reviewed-by: Jason Gunthorpe <[email protected]> Link: https://lore.kernel.org/r/28521e1b0b091849952b0ecb8c118729fc8cdc4f.1683740667.git.reinette.chatre@intel.com Signed-off-by: Alex Williamson <[email protected]>
1 parent a65f35c commit 6578ed8

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

drivers/vfio/pci/vfio_pci_intrs.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -317,14 +317,14 @@ static int vfio_msi_enable(struct vfio_pci_core_device *vdev, int nvec, bool msi
317317
}
318318

319319
static int vfio_msi_set_vector_signal(struct vfio_pci_core_device *vdev,
320-
int vector, int fd, bool msix)
320+
unsigned int vector, int fd, bool msix)
321321
{
322322
struct pci_dev *pdev = vdev->pdev;
323323
struct eventfd_ctx *trigger;
324324
int irq, ret;
325325
u16 cmd;
326326

327-
if (vector < 0 || vector >= vdev->num_ctx)
327+
if (vector >= vdev->num_ctx)
328328
return -EINVAL;
329329

330330
irq = pci_irq_vector(pdev, vector);
@@ -399,7 +399,8 @@ static int vfio_msi_set_vector_signal(struct vfio_pci_core_device *vdev,
399399
static int vfio_msi_set_block(struct vfio_pci_core_device *vdev, unsigned start,
400400
unsigned count, int32_t *fds, bool msix)
401401
{
402-
int i, j, ret = 0;
402+
unsigned int i, j;
403+
int ret = 0;
403404

404405
if (start >= vdev->num_ctx || start + count > vdev->num_ctx)
405406
return -EINVAL;
@@ -410,8 +411,8 @@ static int vfio_msi_set_block(struct vfio_pci_core_device *vdev, unsigned start,
410411
}
411412

412413
if (ret) {
413-
for (--j; j >= (int)start; j--)
414-
vfio_msi_set_vector_signal(vdev, j, -1, msix);
414+
for (i = start; i < j; i++)
415+
vfio_msi_set_vector_signal(vdev, i, -1, msix);
415416
}
416417

417418
return ret;
@@ -420,7 +421,7 @@ static int vfio_msi_set_block(struct vfio_pci_core_device *vdev, unsigned start,
420421
static void vfio_msi_disable(struct vfio_pci_core_device *vdev, bool msix)
421422
{
422423
struct pci_dev *pdev = vdev->pdev;
423-
int i;
424+
unsigned int i;
424425
u16 cmd;
425426

426427
for (i = 0; i < vdev->num_ctx; i++) {
@@ -542,7 +543,7 @@ static int vfio_pci_set_msi_trigger(struct vfio_pci_core_device *vdev,
542543
unsigned index, unsigned start,
543544
unsigned count, uint32_t flags, void *data)
544545
{
545-
int i;
546+
unsigned int i;
546547
bool msix = (index == VFIO_PCI_MSIX_IRQ_INDEX) ? true : false;
547548

548549
if (irq_is(vdev, index) && !count && (flags & VFIO_IRQ_SET_DATA_NONE)) {

0 commit comments

Comments
 (0)