All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] RDMA/erdma: signedness bug in erdma_request_vectors()
@ 2022-06-08 13:47 Dan Carpenter
  2022-06-09  3:00 ` Cheng Xu
  0 siblings, 1 reply; 3+ messages in thread
From: Dan Carpenter @ 2022-06-08 13:47 UTC (permalink / raw)
  To: Cheng Xu
  Cc: Kai Shen, Jason Gunthorpe, Leon Romanovsky, linux-rdma, kernel-janitors

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")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
---
 drivers/infiniband/hw/erdma/erdma_main.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/drivers/infiniband/hw/erdma/erdma_main.c b/drivers/infiniband/hw/erdma/erdma_main.c
index 7c6728aebff0..078bb1c8c9bf 100644
--- a/drivers/infiniband/hw/erdma/erdma_main.c
+++ b/drivers/infiniband/hw/erdma/erdma_main.c
@@ -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;
 }
-- 
2.35.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] RDMA/erdma: signedness bug in erdma_request_vectors()
  2022-06-08 13:47 [PATCH] RDMA/erdma: signedness bug in erdma_request_vectors() Dan Carpenter
@ 2022-06-09  3:00 ` Cheng Xu
  2022-06-09  6:58   ` Dan Carpenter
  0 siblings, 1 reply; 3+ messages in thread
From: Cheng Xu @ 2022-06-09  3:00 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: Kai Shen, Jason Gunthorpe, Leon Romanovsky, linux-rdma, kernel-janitors



On 6/8/22 9:47 PM, Dan Carpenter wrote:
> 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")
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>

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

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] RDMA/erdma: signedness bug in erdma_request_vectors()
  2022-06-09  3:00 ` Cheng Xu
@ 2022-06-09  6:58   ` Dan Carpenter
  0 siblings, 0 replies; 3+ messages in thread
From: Dan Carpenter @ 2022-06-09  6:58 UTC (permalink / raw)
  To: Cheng Xu
  Cc: Kai Shen, Jason Gunthorpe, Leon Romanovsky, linux-rdma, kernel-janitors

On Thu, Jun 09, 2022 at 11:00:03AM +0800, Cheng Xu wrote:
> 
> 
> On 6/8/22 9:47 PM, Dan Carpenter wrote:
> > 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")
> > Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> 
> 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


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-06-09  6:59 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-08 13:47 [PATCH] RDMA/erdma: signedness bug in erdma_request_vectors() Dan Carpenter
2022-06-09  3:00 ` Cheng Xu
2022-06-09  6:58   ` Dan Carpenter

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.