linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Sreekanth Reddy <sreekanth.reddy@broadcom.com>
To: linux-scsi@vger.kernel.org, hch@infradead.org
Cc: martin.petersen@oracle.com, JBottomley@Parallels.com,
	Sathya.Prakash@broadcom.com, linux-kernel@vger.kernel.org,
	Sreekanth Reddy <Sreekanth.Reddy@broadcom.com>
Subject: [PATCH 02/10] mpt3sas: Fixed memory leaks in driver
Date: Tue, 10 Oct 2017 18:41:15 +0530	[thread overview]
Message-ID: <1507641083-20207-3-git-send-email-Sreekanth.Reddy@broadcom.com> (raw)
In-Reply-To: <1507641083-20207-1-git-send-email-Sreekanth.Reddy@broadcom.com>

Fixed below memory leak in driver,

* While removing Expander devices - we are removing expander
 device entry from the list before freeing it's child devices,
 so while freeing child device we are finding its parent device
 node as NULL and so we are not freeing the child device's
 allocated data structures.
 Updated the driver to remove the expander device from the list
 only after freeing all its child devices.

Signed-off-by: Sreekanth Reddy <Sreekanth.Reddy@broadcom.com>
---
 drivers/scsi/mpt3sas/mpt3sas_scsih.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/drivers/scsi/mpt3sas/mpt3sas_scsih.c b/drivers/scsi/mpt3sas/mpt3sas_scsih.c
index 9594166..600e8ef 100644
--- a/drivers/scsi/mpt3sas/mpt3sas_scsih.c
+++ b/drivers/scsi/mpt3sas/mpt3sas_scsih.c
@@ -5274,8 +5274,6 @@ mpt3sas_expander_remove(struct MPT3SAS_ADAPTER *ioc, u64 sas_address)
 	spin_lock_irqsave(&ioc->sas_node_lock, flags);
 	sas_expander = mpt3sas_scsih_expander_find_by_sas_address(ioc,
 	    sas_address);
-	if (sas_expander)
-		list_del(&sas_expander->list);
 	spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
 	if (sas_expander)
 		_scsih_expander_node_remove(ioc, sas_expander);
@@ -7476,7 +7474,6 @@ _scsih_remove_unresponding_sas_devices(struct MPT3SAS_ADAPTER *ioc)
 	spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
 	list_for_each_entry_safe(sas_expander, sas_expander_next, &tmp_list,
 	    list) {
-		list_del(&sas_expander->list);
 		_scsih_expander_node_remove(ioc, sas_expander);
 	}
 
@@ -8102,7 +8099,6 @@ mpt3sas_scsih_event_callback(struct MPT3SAS_ADAPTER *ioc, u8 msix_index,
  * _scsih_expander_node_remove - removing expander device from list.
  * @ioc: per adapter object
  * @sas_expander: the sas_device object
- * Context: Calling function should acquire ioc->sas_node_lock.
  *
  * Removing object and freeing associated memory from the
  * ioc->sas_expander_list.
@@ -8114,6 +8110,7 @@ _scsih_expander_node_remove(struct MPT3SAS_ADAPTER *ioc,
 	struct _sas_node *sas_expander)
 {
 	struct _sas_port *mpt3sas_port, *next;
+	unsigned long flags;
 
 	/* remove sibling ports attached to this expander */
 	list_for_each_entry_safe(mpt3sas_port, next,
@@ -8141,6 +8138,10 @@ _scsih_expander_node_remove(struct MPT3SAS_ADAPTER *ioc,
 	    sas_expander->handle, (unsigned long long)
 	    sas_expander->sas_address);
 
+	spin_lock_irqsave(&ioc->sas_node_lock, flags);
+	list_del(&sas_expander->list);
+	spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
+
 	kfree(sas_expander->phy);
 	kfree(sas_expander);
 }
-- 
2.4.3

  parent reply	other threads:[~2017-10-10 13:12 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-10-10 13:11 [PATCH 00/10] [SCSI] mpt3sas: Phase15 driver enhancements and fixes Sreekanth Reddy
2017-10-10 13:11 ` [PATCH 01/10] mpt3sas: Processing of Cable Exception events Sreekanth Reddy
2017-10-11 15:17   ` Tomas Henzl
2017-10-10 13:11 ` Sreekanth Reddy [this message]
2017-10-11 15:30   ` [PATCH 02/10] mpt3sas: Fixed memory leaks in driver Tomas Henzl
2017-10-10 13:11 ` [PATCH 03/10] mpt3sas: Reduce memory footprints in kdump kernel Sreekanth Reddy
2017-10-11 15:33   ` Tomas Henzl
2017-10-10 13:11 ` [PATCH 04/10] mpt3sas: Fix removal and addition of vSES device during host reset Sreekanth Reddy
2017-10-11 15:35   ` Tomas Henzl
2017-10-11 15:56     ` James Bottomley
2017-10-11 16:12       ` Tomas Henzl
2017-10-11 17:19         ` James Bottomley
2017-10-11 17:27         ` Martin K. Petersen
2017-10-10 13:11 ` [PATCH 05/10] mpt3sas: Fix IO error occurs on pulling out a drive from RAID1 volume created on two SATA drive Sreekanth Reddy
2017-10-11 15:37   ` Tomas Henzl
2017-10-10 13:11 ` [PATCH 06/10] mpt3sas: Updated MPI headers to v2.00.48 Sreekanth Reddy
2017-10-11 15:42   ` Tomas Henzl
2017-10-10 13:11 ` [PATCH 07/10] mpt3sas: Display chassis slot information of the drive Sreekanth Reddy
2017-10-11 16:00   ` Tomas Henzl
2017-10-10 13:11 ` [PATCH 08/10] mpt3sas: Fix possibility of using invalid Enclosure Handles for SAS device after host reset Sreekanth Reddy
2017-10-11 16:07   ` Tomas Henzl
2017-10-11 16:09   ` Tomas Henzl
2017-10-10 13:11 ` [PATCH 09/10] mpt3sas: Adding support for SAS3616 HBA device Sreekanth Reddy
2017-10-11 16:12   ` Tomas Henzl
2017-10-10 13:11 ` [PATCH 10/10] mpt3sas: Bump mpt3sas driver version to v16.100.00.00 Sreekanth Reddy
2017-10-11 16:13   ` Tomas Henzl
2017-10-11 18:11 ` [PATCH 00/10] [SCSI] mpt3sas: Phase15 driver enhancements and fixes Martin K. Petersen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1507641083-20207-3-git-send-email-Sreekanth.Reddy@broadcom.com \
    --to=sreekanth.reddy@broadcom.com \
    --cc=JBottomley@Parallels.com \
    --cc=Sathya.Prakash@broadcom.com \
    --cc=hch@infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=martin.petersen@oracle.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).