From: Tomas Henzl Date: Thu, 2 Mar 2023 23:43:33 +0000 (+0100) Subject: scsi: mpi3mr: Fix mpi3mr_hba_port memory leak in mpi3mr_remove() X-Git-Tag: baikal/mips/sdk6.1~183 X-Git-Url: https://git.baikalelectronics.ru/sdk/?a=commitdiff_plain;h=6f826e3cccecfe2e933636efc869695e49a67e55;p=kernel.git scsi: mpi3mr: Fix mpi3mr_hba_port memory leak in mpi3mr_remove() [ Upstream commit f2634b4dd85b3223ed26ffe58242b31c356c0796 ] Free mpi3mr_hba_port at .remove. Fixes: 33266bf2c87e ("scsi: mpi3mr: Add helper functions to manage device's port") Signed-off-by: Tomas Henzl Link: https://lore.kernel.org/r/20230302234336.25456-4-thenzl@redhat.com Acked-by: Sathya Prakash Veerichetty Signed-off-by: Martin K. Petersen Signed-off-by: Sasha Levin --- diff --git a/drivers/scsi/mpi3mr/mpi3mr_os.c b/drivers/scsi/mpi3mr/mpi3mr_os.c index 6eaeba41072cb..5032b0b5186d4 100644 --- a/drivers/scsi/mpi3mr/mpi3mr_os.c +++ b/drivers/scsi/mpi3mr/mpi3mr_os.c @@ -5077,6 +5077,7 @@ static void mpi3mr_remove(struct pci_dev *pdev) struct workqueue_struct *wq; unsigned long flags; struct mpi3mr_tgt_dev *tgtdev, *tgtdev_next; + struct mpi3mr_hba_port *port, *hba_port_next; if (!shost) return; @@ -5116,6 +5117,16 @@ static void mpi3mr_remove(struct pci_dev *pdev) mpi3mr_free_mem(mrioc); mpi3mr_cleanup_resources(mrioc); + spin_lock_irqsave(&mrioc->sas_node_lock, flags); + list_for_each_entry_safe(port, hba_port_next, &mrioc->hba_port_table_list, list) { + ioc_info(mrioc, + "removing hba_port entry: %p port: %d from hba_port list\n", + port, port->port_id); + list_del(&port->list); + kfree(port); + } + spin_unlock_irqrestore(&mrioc->sas_node_lock, flags); + spin_lock(&mrioc_list_lock); list_del(&mrioc->list); spin_unlock(&mrioc_list_lock);