Skip to contentSkip to conversation

RDMA/erdma: signedness bug in erdma_request_vectors()

PATCH In review Dan Carpenter 2 participants 3 messages Jun 8, 2022 – Jun 9, 2022

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 RDMA/erdma: signedness bug in erdma_request_vectors()

The dev->attrs.irq_num variable is a u32 so the error handling won't work. In this code we are passing "1" as the minimum number of IRQs and if it cannot allocate the minimum number of IRQs then the function returns -ENOSPC. This means that it cannot return 0 here.

Fix the signedness bug by using a "int ret;" and preserve the error code instead of always returning -ENOSPC.

Fixes d4d7a22521c9 ("RDMA/erdma: Add the erdma module")
---
 drivers/infiniband/hw/erdma/erdma_main.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
drivers/infiniband/hw/erdma/erdma_main.c +5 -4
index 7c6728aebff0..078bb1c8c9bf 100644
@@ -185,14 +185,15 @@ static void erdma_dwqe_resource_init(struct erdma_dev *dev)
 static int erdma_request_vectors(struct erdma_dev *dev)
 {
 	int expect_irq_num = min(num_possible_cpus() + 1, ERDMA_NUM_MSIX_VEC);
+	int ret;
 
-	dev->attrs.irq_num = pci_alloc_irq_vectors(dev->pdev, 1, expect_irq_num,
-						   PCI_IRQ_MSIX);
-	if (dev->attrs.irq_num <= 0) {
+	ret = pci_alloc_irq_vectors(dev->pdev, 1, expect_irq_num, PCI_IRQ_MSIX);
+	if (ret < 0) {
 		dev_err(&dev->pdev->dev, "request irq vectors failed(%d)\n",
 			dev->attrs.irq_num);
-		return -ENOSPC;
+		return ret;
 	}
+	dev->attrs.irq_num = ret;
 
 	return 0;
 }
Signature · 1 line
2.35.1
maintainer
#1 lore raw
Quoted 10 lines · Dan Carpenter

The dev->attrs.irq_num variable is a u32 so the error handling won't work. In this code we are passing "1" as the minimum number of IRQs and if it cannot allocate the minimum number of IRQs then the function returns -ENOSPC. This means that it cannot return 0 here.

Fix the signedness bug by using a "int ret;" and preserve the error code instead of always returning -ENOSPC.

Fixes d4d7a22521c9 ("RDMA/erdma: Add the erdma module")

Since this bug is found in the initial upstream patch of our new driver, I would squash your changes into the relevant patch in our next version patch set to make the commit history cleaner.

Thanks,
Cheng Xu

#2 lore raw
Quoted 11 lines · Cheng Xu
Quoted 8 lines · Dan Carpenter

The dev->attrs.irq_num variable is a u32 so the error handling won't work. In this code we are passing "1" as the minimum number of IRQs and if it cannot allocate the minimum number of IRQs then the function returns -ENOSPC. This means that it cannot return 0 here.

Fix the signedness bug by using a "int ret;" and preserve the error code instead of always returning -ENOSPC.

Quoted 6 lines
Quoted 2 lines
Fixes d4d7a22521c9 ("RDMA/erdma: Add the erdma module")

Since this bug is found in the initial upstream patch of our new driver, I would squash your changes into the relevant patch in our next version patch set to make the commit history cleaner.

Sure, no problem.

regards,
dan carpenter