Skip to content

Commit d35f767

Browse files
Justin Teemartinkpetersen
authored andcommitted
scsi: lpfc: Call lpfc_sli4_queue_unset() in restart and rmmod paths
During initialization, the driver allocates wq->pring in lpfc_wq_create and lpfc_sli4_queue_unset() is the only place where kfree(wq->pring) is called. There is a possible memory leak in lpfc_sli_brdrestart_s4() (restart) and lpfc_pci_remove_one_s4() (rmmod) paths because there are no calls to lpfc_sli4_queue_unset() to kfree() the wq->pring. Fix by inserting a call to lpfc_sli4_queue_unset() in lpfc_sli_brdrestart_s4() and lpfc_sli4_hba_unset() routines. Also, add a check for the SLI_ACTIVE flag before issuing the Q_DESTROY mailbox command. If not set, then the mailbox command will obviously fail. In such cases, skip issuing the mailbox command and only execute the driver resource clean up portions of the lpfc_*q_destroy routines. Signed-off-by: Justin Tee <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Martin K. Petersen <[email protected]>
1 parent 4c113ac commit d35f767

File tree

2 files changed

+38
-5
lines changed

2 files changed

+38
-5
lines changed

drivers/scsi/lpfc/lpfc_init.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13518,6 +13518,8 @@ lpfc_sli4_hba_unset(struct lpfc_hba *phba)
1351813518
/* Disable FW logging to host memory */
1351913519
lpfc_ras_stop_fwlog(phba);
1352013520

13521+
lpfc_sli4_queue_unset(phba);
13522+
1352113523
/* Reset SLI4 HBA FCoE function */
1352213524
lpfc_pci_function_reset(phba);
1352313525

drivers/scsi/lpfc/lpfc_sli.c

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5293,6 +5293,8 @@ lpfc_sli_brdrestart_s4(struct lpfc_hba *phba)
52935293
"0296 Restart HBA Data: x%x x%x\n",
52945294
phba->pport->port_state, psli->sli_flag);
52955295

5296+
lpfc_sli4_queue_unset(phba);
5297+
52965298
rc = lpfc_sli4_brdreset(phba);
52975299
if (rc) {
52985300
phba->link_state = LPFC_HBA_ERROR;
@@ -17627,6 +17629,9 @@ lpfc_eq_destroy(struct lpfc_hba *phba, struct lpfc_queue *eq)
1762717629
if (!eq)
1762817630
return -ENODEV;
1762917631

17632+
if (!(phba->sli.sli_flag & LPFC_SLI_ACTIVE))
17633+
goto list_remove;
17634+
1763017635
mbox = mempool_alloc(eq->phba->mbox_mem_pool, GFP_KERNEL);
1763117636
if (!mbox)
1763217637
return -ENOMEM;
@@ -17653,10 +17658,12 @@ lpfc_eq_destroy(struct lpfc_hba *phba, struct lpfc_queue *eq)
1765317658
shdr_status, shdr_add_status, rc);
1765417659
status = -ENXIO;
1765517660
}
17661+
mempool_free(mbox, eq->phba->mbox_mem_pool);
1765617662

17663+
list_remove:
1765717664
/* Remove eq from any list */
1765817665
list_del_init(&eq->list);
17659-
mempool_free(mbox, eq->phba->mbox_mem_pool);
17666+
1766017667
return status;
1766117668
}
1766217669

@@ -17684,6 +17691,10 @@ lpfc_cq_destroy(struct lpfc_hba *phba, struct lpfc_queue *cq)
1768417691
/* sanity check on queue memory */
1768517692
if (!cq)
1768617693
return -ENODEV;
17694+
17695+
if (!(phba->sli.sli_flag & LPFC_SLI_ACTIVE))
17696+
goto list_remove;
17697+
1768717698
mbox = mempool_alloc(cq->phba->mbox_mem_pool, GFP_KERNEL);
1768817699
if (!mbox)
1768917700
return -ENOMEM;
@@ -17709,9 +17720,11 @@ lpfc_cq_destroy(struct lpfc_hba *phba, struct lpfc_queue *cq)
1770917720
shdr_status, shdr_add_status, rc);
1771017721
status = -ENXIO;
1771117722
}
17723+
mempool_free(mbox, cq->phba->mbox_mem_pool);
17724+
17725+
list_remove:
1771217726
/* Remove cq from any list */
1771317727
list_del_init(&cq->list);
17714-
mempool_free(mbox, cq->phba->mbox_mem_pool);
1771517728
return status;
1771617729
}
1771717730

@@ -17739,6 +17752,10 @@ lpfc_mq_destroy(struct lpfc_hba *phba, struct lpfc_queue *mq)
1773917752
/* sanity check on queue memory */
1774017753
if (!mq)
1774117754
return -ENODEV;
17755+
17756+
if (!(phba->sli.sli_flag & LPFC_SLI_ACTIVE))
17757+
goto list_remove;
17758+
1774217759
mbox = mempool_alloc(mq->phba->mbox_mem_pool, GFP_KERNEL);
1774317760
if (!mbox)
1774417761
return -ENOMEM;
@@ -17764,9 +17781,11 @@ lpfc_mq_destroy(struct lpfc_hba *phba, struct lpfc_queue *mq)
1776417781
shdr_status, shdr_add_status, rc);
1776517782
status = -ENXIO;
1776617783
}
17784+
mempool_free(mbox, mq->phba->mbox_mem_pool);
17785+
17786+
list_remove:
1776717787
/* Remove mq from any list */
1776817788
list_del_init(&mq->list);
17769-
mempool_free(mbox, mq->phba->mbox_mem_pool);
1777017789
return status;
1777117790
}
1777217791

@@ -17794,6 +17813,10 @@ lpfc_wq_destroy(struct lpfc_hba *phba, struct lpfc_queue *wq)
1779417813
/* sanity check on queue memory */
1779517814
if (!wq)
1779617815
return -ENODEV;
17816+
17817+
if (!(phba->sli.sli_flag & LPFC_SLI_ACTIVE))
17818+
goto list_remove;
17819+
1779717820
mbox = mempool_alloc(wq->phba->mbox_mem_pool, GFP_KERNEL);
1779817821
if (!mbox)
1779917822
return -ENOMEM;
@@ -17818,11 +17841,13 @@ lpfc_wq_destroy(struct lpfc_hba *phba, struct lpfc_queue *wq)
1781817841
shdr_status, shdr_add_status, rc);
1781917842
status = -ENXIO;
1782017843
}
17844+
mempool_free(mbox, wq->phba->mbox_mem_pool);
17845+
17846+
list_remove:
1782117847
/* Remove wq from any list */
1782217848
list_del_init(&wq->list);
1782317849
kfree(wq->pring);
1782417850
wq->pring = NULL;
17825-
mempool_free(mbox, wq->phba->mbox_mem_pool);
1782617851
return status;
1782717852
}
1782817853

@@ -17852,6 +17877,10 @@ lpfc_rq_destroy(struct lpfc_hba *phba, struct lpfc_queue *hrq,
1785217877
/* sanity check on queue memory */
1785317878
if (!hrq || !drq)
1785417879
return -ENODEV;
17880+
17881+
if (!(phba->sli.sli_flag & LPFC_SLI_ACTIVE))
17882+
goto list_remove;
17883+
1785517884
mbox = mempool_alloc(hrq->phba->mbox_mem_pool, GFP_KERNEL);
1785617885
if (!mbox)
1785717886
return -ENOMEM;
@@ -17892,9 +17921,11 @@ lpfc_rq_destroy(struct lpfc_hba *phba, struct lpfc_queue *hrq,
1789217921
shdr_status, shdr_add_status, rc);
1789317922
status = -ENXIO;
1789417923
}
17924+
mempool_free(mbox, hrq->phba->mbox_mem_pool);
17925+
17926+
list_remove:
1789517927
list_del_init(&hrq->list);
1789617928
list_del_init(&drq->list);
17897-
mempool_free(mbox, hrq->phba->mbox_mem_pool);
1789817929
return status;
1789917930
}
1790017931

0 commit comments

Comments
 (0)