Skip to contentSkip to conversation

scsi: mpi3mr: fix few resource leaks

PATCH Applied Tomas Henzl 3 participants 10 messages Mar 2, 2023 – Mar 10, 2023

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

v2 cover scsi: mpi3mr: fix few resource leaks

The series applies on
[PATCH 00/15] mpi3mr: Few Enhancements and minor fixes from 2/24 posted by Ranjan.

V2 - fixed a bug in [PATCH 5/6]

 drivers/scsi/mpi3mr/mpi3mr.h           |  2 ++
 drivers/scsi/mpi3mr/mpi3mr_fw.c        | 50 ++++++++++++++++----------
 drivers/scsi/mpi3mr/mpi3mr_os.c        | 24 +++++++++++++
 drivers/scsi/mpi3mr/mpi3mr_transport.c |  5 +--
 4 files changed, 58 insertions(+), 23 deletions(-)
Signature · 1 line
2.39.1
#1 lore raw

PATCH v2 1/6 scsi: mpi3mr: fix a memory leak

Add a missing kfree.

Fixes f10af057325c ("scsi: mpi3mr: Resource Based Metering")
---
 drivers/scsi/mpi3mr/mpi3mr_fw.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/scsi/mpi3mr/mpi3mr_fw.c +3 -0
index ab8326b532e7..b632e1bb1007 100644
@@ -4403,6 +4403,9 @@ void mpi3mr_free_mem(struct mpi3mr_ioc *mrioc)
 		mrioc->pel_seqnum_virt = NULL;
 	}
 
+	kfree(mrioc->throttle_groups);
+	mrioc->throttle_groups = NULL;
+
 	kfree(mrioc->logdata_buf);
 	mrioc->logdata_buf = NULL;
 
Signature · 1 line
2.39.1
#2 lore raw

PATCH v2 2/6 scsi: mpi3mr: fix a dma memory leak

In reply to Tomas Henzl

A fix for:
DMA-API: pci 0000:83:00.0: device driver has pending DMA allocations while released from device [count=1]

Fixes 32d457d5a2af ("scsi: mpi3mr: Add framework to issue config requests")
---
 drivers/scsi/mpi3mr/mpi3mr_fw.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/scsi/mpi3mr/mpi3mr_fw.c +5 -1
index b632e1bb1007..fa62991f5aee 100644
@@ -4396,7 +4396,11 @@ void mpi3mr_free_mem(struct mpi3mr_ioc *mrioc)
 		    mrioc->admin_req_base, mrioc->admin_req_dma);
 		mrioc->admin_req_base = NULL;
 	}
-
+	if (mrioc->cfg_page) {
+		dma_free_coherent(&mrioc->pdev->dev, mrioc->cfg_page_sz,
+		    mrioc->cfg_page, mrioc->cfg_page_dma);
+		mrioc->cfg_page = NULL;
+	}
 	if (mrioc->pel_seqnum_virt) {
 		dma_free_coherent(&mrioc->pdev->dev, mrioc->pel_seqnum_sz,
 		    mrioc->pel_seqnum_virt, mrioc->pel_seqnum_dma);
Signature · 1 line
2.39.1
#3 lore raw

PATCH v2 3/6 scsi: mpi3mr: fix a memory leak

In reply to Tomas Henzl

Free mpi3mr_hba_port at .remove.

Fixes 42fc9fee116f ("scsi: mpi3mr: Add helper functions to manage device's port")
---
 drivers/scsi/mpi3mr/mpi3mr_os.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
drivers/scsi/mpi3mr/mpi3mr_os.c +11 -0
index 6f9230a079c3..85bd45563686 100644
@@ -5112,6 +5112,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;
@@ -5151,6 +5152,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);
Signature · 1 line
2.39.1
#4 lore raw

PATCH v2 4/6 scsi: mpi3mr: fix a memory leak

In reply to Tomas Henzl

Free mrioc->sas_hba.phy at .remove.

Fixes 42fc9fee116f ("scsi: mpi3mr: Add helper functions to manage device's port")
---
 drivers/scsi/mpi3mr/mpi3mr_os.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/scsi/mpi3mr/mpi3mr_os.c +6 -0
index 85bd45563686..8f17a7953eb4 100644
@@ -5162,6 +5162,12 @@ static void mpi3mr_remove(struct pci_dev *pdev)
 	}
 	spin_unlock_irqrestore(&mrioc->sas_node_lock, flags);
 
+	if (mrioc->sas_hba.num_phys) {
+		kfree(mrioc->sas_hba.phy);
+		mrioc->sas_hba.phy = NULL;
+		mrioc->sas_hba.num_phys = 0;
+	}
+
 	spin_lock(&mrioc_list_lock);
 	list_del(&mrioc->list);
 	spin_unlock(&mrioc_list_lock);
Signature · 1 line
2.39.1
#5 lore raw

PATCH v2 5/6 scsi: mpi3mr: fix a memory leak

In reply to Tomas Henzl

Don't allocate memory again in next loop(s).

Fixes fe6db6151565 ("scsi: mpi3mr: Handle offline FW activation in graceful manner")

---
V2 - mpi3mr_create_op_queues may be called repeatedly and without it it interferes with mpi3mr_memset_buffers So let drop the changes around it.

 drivers/scsi/mpi3mr/mpi3mr_fw.c | 41 ++++++++++++++++++---------------
 1 file changed, 23 insertions(+), 18 deletions(-)
drivers/scsi/mpi3mr/mpi3mr_fw.c +23 -18
index fa62991f5aee..081512b46538 100644
@@ -3852,29 +3852,34 @@ int mpi3mr_init_ioc(struct mpi3mr_ioc *mrioc)
 
 	mpi3mr_print_ioc_info(mrioc);
 
-	dprint_init(mrioc, "allocating config page buffers\n");
-	mrioc->cfg_page = dma_alloc_coherent(&mrioc->pdev->dev,
-	    MPI3MR_DEFAULT_CFG_PAGE_SZ, &mrioc->cfg_page_dma, GFP_KERNEL);
 	if (!mrioc->cfg_page) {
-		retval = -1;
-		goto out_failed_noretry;
+		dprint_init(mrioc, "allocating config page buffers\n");
+		mrioc->cfg_page_sz = MPI3MR_DEFAULT_CFG_PAGE_SZ;
+		mrioc->cfg_page = dma_alloc_coherent(&mrioc->pdev->dev,
+		    mrioc->cfg_page_sz, &mrioc->cfg_page_dma, GFP_KERNEL);
+		if (!mrioc->cfg_page) {
+			retval = -1;
+			goto out_failed_noretry;
+		}
 	}
 
-	mrioc->cfg_page_sz = MPI3MR_DEFAULT_CFG_PAGE_SZ;
-
-	retval = mpi3mr_alloc_reply_sense_bufs(mrioc);
-	if (retval) {
-		ioc_err(mrioc,
-		    "%s :Failed to allocated reply sense buffers %d\n",
-		    __func__, retval);
-		goto out_failed_noretry;
+	if (!mrioc->init_cmds.reply) {
+		retval = mpi3mr_alloc_reply_sense_bufs(mrioc);
+		if (retval) {
+			ioc_err(mrioc,
+			    "%s :Failed to allocated reply sense buffers %d\n",
+			    __func__, retval);
+			goto out_failed_noretry;
+		}
 	}
 
-	retval = mpi3mr_alloc_chain_bufs(mrioc);
-	if (retval) {
-		ioc_err(mrioc, "Failed to allocated chain buffers %d\n",
-		    retval);
-		goto out_failed_noretry;
+	if (!mrioc->chain_sgl_list) {
+		retval = mpi3mr_alloc_chain_bufs(mrioc);
+		if (retval) {
+			ioc_err(mrioc, "Failed to allocated chain buffers %d\n",
+			    retval);
+			goto out_failed_noretry;
+		}
 	}
 
 	retval = mpi3mr_issue_iocinit(mrioc);
Signature · 1 line
2.39.1
#6 lore raw

PATCH v2 6/6 scsi: mpi3mr: fix a memory leak

In reply to Tomas Henzl

Add a missing resource clean up in .remove.

Fixes e22bae30667a ("scsi: mpi3mr: Add expander devices to STL")
---
 drivers/scsi/mpi3mr/mpi3mr.h           | 2 ++
 drivers/scsi/mpi3mr/mpi3mr_os.c        | 7 +++++++
 drivers/scsi/mpi3mr/mpi3mr_transport.c | 5 +----
 3 files changed, 10 insertions(+), 4 deletions(-)
drivers/scsi/mpi3mr/mpi3mr.h +2 -0
index e6a9c81bba33..c5347a004cd5 100644
@@ -1407,4 +1407,6 @@ void mpi3mr_flush_drv_cmds(struct mpi3mr_ioc *mrioc);
 void mpi3mr_flush_cmds_for_unrecovered_controller(struct mpi3mr_ioc *mrioc);
 void mpi3mr_free_enclosure_list(struct mpi3mr_ioc *mrioc);
 int mpi3mr_process_admin_reply_q(struct mpi3mr_ioc *mrioc);
+void mpi3mr_expander_node_remove(struct mpi3mr_ioc *mrioc,
+	struct mpi3mr_sas_node *sas_expander);
 #endif /*MPI3MR_H_INCLUDED*/
drivers/scsi/mpi3mr/mpi3mr_os.c +7 -0
index 8f17a7953eb4..b329e1ee46dc 100644
@@ -5113,6 +5113,7 @@ static void mpi3mr_remove(struct pci_dev *pdev)
 	unsigned long flags;
 	struct mpi3mr_tgt_dev *tgtdev, *tgtdev_next;
 	struct mpi3mr_hba_port *port, *hba_port_next;
+	struct mpi3mr_sas_node *sas_expander, *sas_expander_next;
 
 	if (!shost)
 		return;
@@ -5153,6 +5154,12 @@ static void mpi3mr_remove(struct pci_dev *pdev)
 	mpi3mr_cleanup_resources(mrioc);
 
 	spin_lock_irqsave(&mrioc->sas_node_lock, flags);
+	list_for_each_entry_safe_reverse(sas_expander, sas_expander_next,
+	    &mrioc->sas_expander_list, list) {
+		spin_unlock_irqrestore(&mrioc->sas_node_lock, flags);
+		mpi3mr_expander_node_remove(mrioc, sas_expander);
+		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",
drivers/scsi/mpi3mr/mpi3mr_transport.c +1 -4
index 121fae310692..4d84d5bd173f 100644
@@ -9,9 +9,6 @@
 
 #include "mpi3mr.h"
 
-static void mpi3mr_expander_node_remove(struct mpi3mr_ioc *mrioc,
-	struct mpi3mr_sas_node *sas_expander);
-
 /**
  * mpi3mr_post_transport_req - Issue transport requests and wait
  * @mrioc: Adapter instance reference
@@ -2164,7 +2161,7 @@ int mpi3mr_expander_add(struct mpi3mr_ioc *mrioc, u16 handle)
  *
  * Return nothing.
  */
-static void mpi3mr_expander_node_remove(struct mpi3mr_ioc *mrioc,
+void mpi3mr_expander_node_remove(struct mpi3mr_ioc *mrioc,
 	struct mpi3mr_sas_node *sas_expander)
 {
 	struct mpi3mr_sas_port *mr_sas_port, *next;
Signature · 1 line
2.39.1
#7 lore raw
In reply to Tomas Henzl

Ranjan/Sreekanth,

Quoted 4 lines

The series applies on
[PATCH 00/15] mpi3mr: Few Enhancements and minor fixes from 2/24 posted by Ranjan.

Quoted 8 lines

V2 - fixed a bug in [PATCH 5/6]

 drivers/scsi/mpi3mr/mpi3mr.h           |  2 ++
 drivers/scsi/mpi3mr/mpi3mr_fw.c        | 50 ++++++++++++++++----------
 drivers/scsi/mpi3mr/mpi3mr_os.c        | 24 +++++++++++++
 drivers/scsi/mpi3mr/mpi3mr_transport.c |  5 +--
 4 files changed, 58 insertions(+), 23 deletions(-)

Please review!

Signature · 1 line
Martin K. Petersen	Oracle Linux Engineering
#8 lore raw

V2 looks good, please add this set into 6.3 scsi-fixes.

Quoted 21 lines · Martin K. Petersen

Ranjan/Sreekanth,

Quoted 4 lines

The series applies on
[PATCH 00/15] mpi3mr: Few Enhancements and minor fixes from 2/24 posted by Ranjan.

Quoted 8 lines

V2 - fixed a bug in [PATCH 5/6]

 drivers/scsi/mpi3mr/mpi3mr.h           |  2 ++
 drivers/scsi/mpi3mr/mpi3mr_fw.c        | 50 ++++++++++++++++----------
 drivers/scsi/mpi3mr/mpi3mr_os.c        | 24 +++++++++++++
 drivers/scsi/mpi3mr/mpi3mr_transport.c |  5 +--
 4 files changed, 58 insertions(+), 23 deletions(-)

Please review!

--
Martin K. Petersen Oracle Linux Engineering

Signature · 11 lines
This electronic communication and the information and any files transmitted 
with it, or attached to it, are confidential and are intended solely for 
the use of the individual or entity to whom it is addressed and may contain 
information that is confidential, legally privileged, protected by privacy 
laws, or otherwise restricted from disclosure to anyone else. If you are 
not the intended recipient or the person responsible for delivering the 
e-mail to the intended recipient, you are hereby notified that any use, 
copying, distributing, dissemination, forwarding, printing, or copying of 
this e-mail is strictly prohibited. If you received this e-mail in error, 
please return the e-mail to the sender, delete it from your computer, and 
destroy any printed copy of it.
#9 lore raw
In reply to Tomas Henzl

Tomas,

Quoted 3 lines

The series applies on
[PATCH 00/15] mpi3mr: Few Enhancements and minor fixes from 2/24 posted by Ranjan.

Applied to 6.3/scsi-fixes, thanks!

Signature · 1 line
Martin K. Petersen	Oracle Linux Engineering