From: Raghava Aditya Renukunta <RaghavaAditya.Renukunta@microsemi.com>
To: jejb@linux.vnet.ibm.com, martin.petersen@oracle.com,
linux-scsi@vger.kernel.org
Cc: David.Carroll@microsemi.com, Gana.Sridaran@microsemi.com,
Scott.Benesh@microsemi.com, jthumshirn@suse.de,
dan.carpenter@oracle.com
Subject: [PATCH V2 05/15] aacraid: Fix memory leak in fib init path
Date: Thu, 16 Feb 2017 12:51:14 -0800 [thread overview]
Message-ID: <20170216205124.20271-6-RaghavaAditya.Renukunta@microsemi.com> (raw)
In-Reply-To: <20170216205124.20271-1-RaghavaAditya.Renukunta@microsemi.com>
aac_fib_map_free frees misaligned fib dma memory, additionally it does not
free up the whole memory.
Fixed by changing the code to free up the correct and full memory
allocation.
Cc: stable@vger.kernel.org
Fixes: e8b12f0fb835223 ([SCSI] aacraid: Add new code for PMC-Sierra's SRC based controller family)
Signed-off-by: Raghava Aditya Renukunta <RaghavaAditya.Renukunta@microsemi.com>
Reviewed-by: David Carroll <David.Carroll@microsemi.com>
---
Changes in V2:
Refactored memory free code to make it easier to understand
drivers/scsi/aacraid/commsup.c | 36 +++++++++++++++++++++---------------
1 file changed, 21 insertions(+), 15 deletions(-)
diff --git a/drivers/scsi/aacraid/commsup.c b/drivers/scsi/aacraid/commsup.c
index e221321..c10954b 100644
--- a/drivers/scsi/aacraid/commsup.c
+++ b/drivers/scsi/aacraid/commsup.c
@@ -95,12 +95,20 @@ static int fib_map_alloc(struct aac_dev *dev)
void aac_fib_map_free(struct aac_dev *dev)
{
- if (dev->hw_fib_va && dev->max_cmd_size) {
- pci_free_consistent(dev->pdev,
- (dev->max_cmd_size *
- (dev->scsi_host_ptr->can_queue + AAC_NUM_MGT_FIB)),
- dev->hw_fib_va, dev->hw_fib_pa);
- }
+ size_t alloc_size;
+ size_t fib_size;
+ int num_fibs;
+
+ if(!dev->hw_fib_va || !dev->max_cmd_size)
+ return;
+
+ num_fibs = dev->scsi_host_ptr->can_queue + AAC_NUM_MGT_FIB;
+ fib_size = dev->max_fib_size + sizeof(struct aac_fib_xporthdr);
+ alloc_size = fib_size * num_fibs + ALIGN32 - 1;
+
+ pci_free_consistent(dev->pdev, alloc_size, dev->hw_fib_va,
+ dev->hw_fib_pa);
+
dev->hw_fib_va = NULL;
dev->hw_fib_pa = 0;
}
@@ -153,22 +161,20 @@ int aac_fib_setup(struct aac_dev * dev)
if (i<0)
return -ENOMEM;
- /* 32 byte alignment for PMC */
- hw_fib_pa = (dev->hw_fib_pa + (ALIGN32 - 1)) & ~(ALIGN32 - 1);
- dev->hw_fib_va = (struct hw_fib *)((unsigned char *)dev->hw_fib_va +
- (hw_fib_pa - dev->hw_fib_pa));
- dev->hw_fib_pa = hw_fib_pa;
memset(dev->hw_fib_va, 0,
(dev->max_cmd_size + sizeof(struct aac_fib_xporthdr)) *
(dev->scsi_host_ptr->can_queue + AAC_NUM_MGT_FIB));
+ /* 32 byte alignment for PMC */
+ hw_fib_pa = (dev->hw_fib_pa + (ALIGN32 - 1)) & ~(ALIGN32 - 1);
+ hw_fib = (struct hw_fib *)((unsigned char *)dev->hw_fib_va +
+ (hw_fib_pa - dev->hw_fib_pa));
+
/* add Xport header */
- dev->hw_fib_va = (struct hw_fib *)((unsigned char *)dev->hw_fib_va +
+ hw_fib = (struct hw_fib *)((unsigned char *)hw_fib +
sizeof(struct aac_fib_xporthdr));
- dev->hw_fib_pa += sizeof(struct aac_fib_xporthdr);
+ hw_fib_pa += sizeof(struct aac_fib_xporthdr);
- hw_fib = dev->hw_fib_va;
- hw_fib_pa = dev->hw_fib_pa;
/*
* Initialise the fibs
*/
--
2.7.4
next prev parent reply other threads:[~2017-02-17 3:28 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-02-16 20:51 [PATCH V2 00/15] aacraid: Fixes and enhancements for arc family Raghava Aditya Renukunta
2017-02-16 20:51 ` [PATCH V2 01/15] aacraid: Fix camel case Raghava Aditya Renukunta
2017-02-16 20:51 ` [PATCH V2 02/15] aacraid: Use correct channel number for raw srb Raghava Aditya Renukunta
2017-02-16 20:51 ` [PATCH V2 03/15] aacraid: Fix for excessive prints on EEH Raghava Aditya Renukunta
2017-02-17 8:21 ` Johannes Thumshirn
2017-02-16 20:51 ` [PATCH V2 04/15] aacraid: Prevent E3 lockup when deleting units Raghava Aditya Renukunta
2017-02-16 20:51 ` Raghava Aditya Renukunta [this message]
2017-02-17 8:22 ` [PATCH V2 05/15] aacraid: Fix memory leak in fib init path Johannes Thumshirn
2017-02-16 20:51 ` [PATCH V2 06/15] aacraid: Added sysfs for driver version Raghava Aditya Renukunta
2017-02-17 8:22 ` Johannes Thumshirn
2017-02-16 20:51 ` [PATCH V2 07/15] aacraid: Fix sync fibs time out on controller reset Raghava Aditya Renukunta
2017-02-16 20:51 ` [PATCH V2 08/15] aacraid: Skip wellness sync on controller failure Raghava Aditya Renukunta
2017-02-16 20:51 ` [PATCH V2 09/15] aacraid: Reload offlined drives after controller reset Raghava Aditya Renukunta
2017-02-16 20:51 ` [PATCH V2 10/15] aacraid: Decrease adapter health check interval Raghava Aditya Renukunta
2017-02-16 20:51 ` [PATCH V2 11/15] aacraid: Skip IOP reset on controller panic(SMART Family) Raghava Aditya Renukunta
2017-02-16 20:51 ` [PATCH V2 12/15] aacraid: Reorder Adapter status check Raghava Aditya Renukunta
2017-02-16 20:51 ` [PATCH V2 13/15] aacraid: Save adapter fib log before an IOP reset Raghava Aditya Renukunta
2017-02-16 20:51 ` [PATCH V2 14/15] aacraid: Fix a potential spinlock double unlock bug Raghava Aditya Renukunta
2017-02-16 20:51 ` [PATCH V2 15/15] aacraid: Update driver version Raghava Aditya Renukunta
2017-02-21 2:53 ` [PATCH V2 00/15] aacraid: Fixes and enhancements for arc family 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=20170216205124.20271-6-RaghavaAditya.Renukunta@microsemi.com \
--to=raghavaaditya.renukunta@microsemi.com \
--cc=David.Carroll@microsemi.com \
--cc=Gana.Sridaran@microsemi.com \
--cc=Scott.Benesh@microsemi.com \
--cc=dan.carpenter@oracle.com \
--cc=jejb@linux.vnet.ibm.com \
--cc=jthumshirn@suse.de \
--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