kernel-janitors.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] scsi: mpi3mr: delete unnecessary NULL check
@ 2021-06-09  9:26 Dan Carpenter
  2021-06-09  9:27 ` [PATCH 2/2] scsi: mpi3mr: Fix error handling in mpi3mr_setup_isr() Dan Carpenter
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Dan Carpenter @ 2021-06-09  9:26 UTC (permalink / raw)
  To: James E.J. Bottomley
  Cc: Martin K. Petersen, Hannes Reinecke, Tomas Henzl, Kashyap Desai,
	Himanshu Madhani, linux-scsi, linux-kernel, kernel-janitors

The "mrioc->intr_info" pointer can't be NULL, but if it could then the
second iteration through the loop would Oops.  Let's delete the
confusing and impossible NULL check.

Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
---
 drivers/scsi/mpi3mr/mpi3mr_fw.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/scsi/mpi3mr/mpi3mr_fw.c b/drivers/scsi/mpi3mr/mpi3mr_fw.c
index acb2be62080a..40696b75345d 100644
--- a/drivers/scsi/mpi3mr/mpi3mr_fw.c
+++ b/drivers/scsi/mpi3mr/mpi3mr_fw.c
@@ -3583,8 +3583,7 @@ static void mpi3mr_free_mem(struct mpi3mr_ioc *mrioc)
 
 	for (i = 0; i < mrioc->intr_info_count; i++) {
 		intr_info = mrioc->intr_info + i;
-		if (intr_info)
-			intr_info->op_reply_q = NULL;
+		intr_info->op_reply_q = NULL;
 	}
 
 	kfree(mrioc->req_qinfo);
-- 
2.30.2


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

* [PATCH 2/2] scsi: mpi3mr: Fix error handling in mpi3mr_setup_isr()
  2021-06-09  9:26 [PATCH 1/2] scsi: mpi3mr: delete unnecessary NULL check Dan Carpenter
@ 2021-06-09  9:27 ` Dan Carpenter
  2021-06-10  3:01 ` [PATCH 1/2] scsi: mpi3mr: delete unnecessary NULL check Martin K. Petersen
  2021-06-16  3:48 ` Martin K. Petersen
  2 siblings, 0 replies; 4+ messages in thread
From: Dan Carpenter @ 2021-06-09  9:27 UTC (permalink / raw)
  To: James E.J. Bottomley
  Cc: Martin K. Petersen, Tomas Henzl, Hannes Reinecke, Kashyap Desai,
	Himanshu Madhani, linux-scsi, kernel-janitors

The pci_alloc_irq_vectors_affinity() function returns negative error
codes or it returns a number between the minimum vectors (1 in this
case) and max_vectors.  It won't return zero.  Because "i" is a u16 then
the error handling won't work.  And also if it did work the error code
was not set.

Really "max_vectors" can be an int as well because we're doing a min_t()
on int type.  The other change is that it's better to remove unnecessary
initialization so that static checkers can warn us if there are ever
uninitialized variable bugs introduced in the future.

I changed the error code from -1 (-EPERM) if the kmalloc() failed to
-ENOMEM.  And on success path I changed it from "return retval;" to
"return 0;" which shouldn't affect the compiled code but makes it more
readable.

Fixes: 824a156633df ("scsi: mpi3mr: Base driver code")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
---
 drivers/scsi/mpi3mr/mpi3mr_fw.c | 24 +++++++++++++-----------
 1 file changed, 13 insertions(+), 11 deletions(-)

diff --git a/drivers/scsi/mpi3mr/mpi3mr_fw.c b/drivers/scsi/mpi3mr/mpi3mr_fw.c
index 40696b75345d..88db2f0e13fd 100644
--- a/drivers/scsi/mpi3mr/mpi3mr_fw.c
+++ b/drivers/scsi/mpi3mr/mpi3mr_fw.c
@@ -665,8 +665,9 @@ static inline int mpi3mr_request_irq(struct mpi3mr_ioc *mrioc, u16 index)
 static int mpi3mr_setup_isr(struct mpi3mr_ioc *mrioc, u8 setup_one)
 {
 	unsigned int irq_flags = PCI_IRQ_MSIX;
-	u16 max_vectors = 0, i;
-	int retval = 0;
+	int max_vectors;
+	int retval;
+	int i;
 	struct irq_affinity desc = { .pre_vectors =  1};
 
 	mpi3mr_cleanup_isr(mrioc);
@@ -687,29 +688,29 @@ static int mpi3mr_setup_isr(struct mpi3mr_ioc *mrioc, u8 setup_one)
 	irq_flags |= PCI_IRQ_AFFINITY | PCI_IRQ_ALL_TYPES;
 
 	mrioc->op_reply_q_offset = (max_vectors > 1) ? 1 : 0;
-	i = pci_alloc_irq_vectors_affinity(mrioc->pdev,
-	    1, max_vectors, irq_flags, &desc);
-	if (i <= 0) {
+	retval = pci_alloc_irq_vectors_affinity(mrioc->pdev,
+				1, max_vectors, irq_flags, &desc);
+	if (retval < 0) {
 		ioc_err(mrioc, "Cannot alloc irq vectors\n");
 		goto out_failed;
 	}
-	if (i != max_vectors) {
+	if (retval != max_vectors) {
 		ioc_info(mrioc,
 		    "allocated vectors (%d) are less than configured (%d)\n",
-		    i, max_vectors);
+		    retval, max_vectors);
 		/*
 		 * If only one MSI-x is allocated, then MSI-x 0 will be shared
 		 * between Admin queue and operational queue
 		 */
-		if (i == 1)
+		if (retval == 1)
 			mrioc->op_reply_q_offset = 0;
 
-		max_vectors = i;
+		max_vectors = retval;
 	}
 	mrioc->intr_info = kzalloc(sizeof(struct mpi3mr_intr_info) * max_vectors,
 	    GFP_KERNEL);
 	if (!mrioc->intr_info) {
-		retval = -1;
+		retval = -ENOMEM;
 		pci_free_irq_vectors(mrioc->pdev);
 		goto out_failed;
 	}
@@ -722,7 +723,8 @@ static int mpi3mr_setup_isr(struct mpi3mr_ioc *mrioc, u8 setup_one)
 	}
 	mrioc->intr_info_count = max_vectors;
 	mpi3mr_ioc_enable_intr(mrioc);
-	return retval;
+	return 0;
+
 out_failed:
 	mpi3mr_cleanup_isr(mrioc);
 
-- 
2.30.2


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

* Re: [PATCH 1/2] scsi: mpi3mr: delete unnecessary NULL check
  2021-06-09  9:26 [PATCH 1/2] scsi: mpi3mr: delete unnecessary NULL check Dan Carpenter
  2021-06-09  9:27 ` [PATCH 2/2] scsi: mpi3mr: Fix error handling in mpi3mr_setup_isr() Dan Carpenter
@ 2021-06-10  3:01 ` Martin K. Petersen
  2021-06-16  3:48 ` Martin K. Petersen
  2 siblings, 0 replies; 4+ messages in thread
From: Martin K. Petersen @ 2021-06-10  3:01 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: James E.J. Bottomley, Martin K. Petersen, Hannes Reinecke,
	Tomas Henzl, Kashyap Desai, Himanshu Madhani, linux-scsi,
	linux-kernel, kernel-janitors


Dan,

> The "mrioc->intr_info" pointer can't be NULL, but if it could then the
> second iteration through the loop would Oops.  Let's delete the
> confusing and impossible NULL check.

Applied 1+2 to 5.14/scsi-staging, thanks!

-- 
Martin K. Petersen	Oracle Linux Engineering

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

* Re: [PATCH 1/2] scsi: mpi3mr: delete unnecessary NULL check
  2021-06-09  9:26 [PATCH 1/2] scsi: mpi3mr: delete unnecessary NULL check Dan Carpenter
  2021-06-09  9:27 ` [PATCH 2/2] scsi: mpi3mr: Fix error handling in mpi3mr_setup_isr() Dan Carpenter
  2021-06-10  3:01 ` [PATCH 1/2] scsi: mpi3mr: delete unnecessary NULL check Martin K. Petersen
@ 2021-06-16  3:48 ` Martin K. Petersen
  2 siblings, 0 replies; 4+ messages in thread
From: Martin K. Petersen @ 2021-06-16  3:48 UTC (permalink / raw)
  To: Dan Carpenter, James E.J. Bottomley
  Cc: Martin K . Petersen, linux-kernel, Hannes Reinecke, Tomas Henzl,
	Himanshu Madhani, kernel-janitors, linux-scsi, Kashyap Desai

On Wed, 9 Jun 2021 12:26:02 +0300, Dan Carpenter wrote:

> The "mrioc->intr_info" pointer can't be NULL, but if it could then the
> second iteration through the loop would Oops.  Let's delete the
> confusing and impossible NULL check.

Applied to 5.14/scsi-queue, thanks!

[1/2] scsi: mpi3mr: delete unnecessary NULL check
      https://git.kernel.org/mkp/scsi/c/d46bdecd9f3c
[2/2] scsi: mpi3mr: Fix error handling in mpi3mr_setup_isr()
      https://git.kernel.org/mkp/scsi/c/2938bedd0efa

-- 
Martin K. Petersen	Oracle Linux Engineering

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

end of thread, other threads:[~2021-06-16  3:49 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-09  9:26 [PATCH 1/2] scsi: mpi3mr: delete unnecessary NULL check Dan Carpenter
2021-06-09  9:27 ` [PATCH 2/2] scsi: mpi3mr: Fix error handling in mpi3mr_setup_isr() Dan Carpenter
2021-06-10  3:01 ` [PATCH 1/2] scsi: mpi3mr: delete unnecessary NULL check Martin K. Petersen
2021-06-16  3:48 ` Martin K. Petersen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).