Commit 2938bedd authored by Dan Carpenter's avatar Dan Carpenter Committed by Martin K. Petersen

scsi: mpi3mr: Fix error handling in mpi3mr_setup_isr()

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.

Link: https://lore.kernel.org/r/YMCJcnmSI4kOIyv/@mwanda
Fixes: 824a1566 ("scsi: mpi3mr: Base driver code")
Signed-off-by: default avatarDan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: default avatarMartin K. Petersen <martin.petersen@oracle.com>
parent d46bdecd
...@@ -665,8 +665,9 @@ static inline int mpi3mr_request_irq(struct mpi3mr_ioc *mrioc, u16 index) ...@@ -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) static int mpi3mr_setup_isr(struct mpi3mr_ioc *mrioc, u8 setup_one)
{ {
unsigned int irq_flags = PCI_IRQ_MSIX; unsigned int irq_flags = PCI_IRQ_MSIX;
u16 max_vectors = 0, i; int max_vectors;
int retval = 0; int retval;
int i;
struct irq_affinity desc = { .pre_vectors = 1}; struct irq_affinity desc = { .pre_vectors = 1};
mpi3mr_cleanup_isr(mrioc); mpi3mr_cleanup_isr(mrioc);
...@@ -687,29 +688,29 @@ static int mpi3mr_setup_isr(struct mpi3mr_ioc *mrioc, u8 setup_one) ...@@ -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; irq_flags |= PCI_IRQ_AFFINITY | PCI_IRQ_ALL_TYPES;
mrioc->op_reply_q_offset = (max_vectors > 1) ? 1 : 0; mrioc->op_reply_q_offset = (max_vectors > 1) ? 1 : 0;
i = pci_alloc_irq_vectors_affinity(mrioc->pdev, retval = pci_alloc_irq_vectors_affinity(mrioc->pdev,
1, max_vectors, irq_flags, &desc); 1, max_vectors, irq_flags, &desc);
if (i <= 0) { if (retval < 0) {
ioc_err(mrioc, "Cannot alloc irq vectors\n"); ioc_err(mrioc, "Cannot alloc irq vectors\n");
goto out_failed; goto out_failed;
} }
if (i != max_vectors) { if (retval != max_vectors) {
ioc_info(mrioc, ioc_info(mrioc,
"allocated vectors (%d) are less than configured (%d)\n", "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 * If only one MSI-x is allocated, then MSI-x 0 will be shared
* between Admin queue and operational queue * between Admin queue and operational queue
*/ */
if (i == 1) if (retval == 1)
mrioc->op_reply_q_offset = 0; mrioc->op_reply_q_offset = 0;
max_vectors = i; max_vectors = retval;
} }
mrioc->intr_info = kzalloc(sizeof(struct mpi3mr_intr_info) * max_vectors, mrioc->intr_info = kzalloc(sizeof(struct mpi3mr_intr_info) * max_vectors,
GFP_KERNEL); GFP_KERNEL);
if (!mrioc->intr_info) { if (!mrioc->intr_info) {
retval = -1; retval = -ENOMEM;
pci_free_irq_vectors(mrioc->pdev); pci_free_irq_vectors(mrioc->pdev);
goto out_failed; goto out_failed;
} }
...@@ -722,7 +723,8 @@ static int mpi3mr_setup_isr(struct mpi3mr_ioc *mrioc, u8 setup_one) ...@@ -722,7 +723,8 @@ static int mpi3mr_setup_isr(struct mpi3mr_ioc *mrioc, u8 setup_one)
} }
mrioc->intr_info_count = max_vectors; mrioc->intr_info_count = max_vectors;
mpi3mr_ioc_enable_intr(mrioc); mpi3mr_ioc_enable_intr(mrioc);
return retval; return 0;
out_failed: out_failed:
mpi3mr_cleanup_isr(mrioc); mpi3mr_cleanup_isr(mrioc);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment