Linux RDMA and InfiniBand development
 help / color / mirror / Atom feed
From: Dan Carpenter <dan.carpenter@oracle.com>
To: Cheng Xu <chengyou@linux.alibaba.com>
Cc: Kai Shen <kaishen@linux.alibaba.com>,
	Jason Gunthorpe <jgg@ziepe.ca>, Leon Romanovsky <leon@kernel.org>,
	linux-rdma@vger.kernel.org, kernel-janitors@vger.kernel.org
Subject: [PATCH] RDMA/erdma: signedness bug in erdma_request_vectors()
Date: Wed, 8 Jun 2022 16:47:06 +0300	[thread overview]
Message-ID: <YqCoWrAXeGHPvTfO@kili> (raw)

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


             reply	other threads:[~2022-06-08 13:47 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-08 13:47 Dan Carpenter [this message]
2022-06-09  3:00 ` [PATCH] RDMA/erdma: signedness bug in erdma_request_vectors() Cheng Xu
2022-06-09  6:58   ` Dan Carpenter

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=YqCoWrAXeGHPvTfO@kili \
    --to=dan.carpenter@oracle.com \
    --cc=chengyou@linux.alibaba.com \
    --cc=jgg@ziepe.ca \
    --cc=kaishen@linux.alibaba.com \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=leon@kernel.org \
    --cc=linux-rdma@vger.kernel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox