Linux SCSI subsystem development
 help / color / mirror / Atom feed
From: Li Qiang <liq3ea@gmail.com>
To: James.Bottomley@HansenPartnership.com, linux-scsi@vger.kernel.org
Cc: Li Qiang <liq3ea@gmail.com>
Subject: [PATCH] 53c700: fix memory leak of dma non-cosistent memory
Date: Mon, 14 Nov 2016 15:07:58 +0800	[thread overview]
Message-ID: <582962db.0130ed0a.10866.5633@mx.google.com> (raw)

From: Li Qiang <liq3ea@gmail.com>

In NCR_700_detect function, if an error occurs it will return
NULL without freeing the dma non-cosistent memory once allocated.
This patch avoid this.

Signed-off-by: Li Qiang <liq3ea@gmail.com>
---
 drivers/scsi/53c700.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/scsi/53c700.c b/drivers/scsi/53c700.c
index 95e32a4..d5a2ba3 100644
--- a/drivers/scsi/53c700.c
+++ b/drivers/scsi/53c700.c
@@ -332,8 +332,10 @@ struct Scsi_Host *
 		tpnt->proc_name = "53c700";
 
 	host = scsi_host_alloc(tpnt, 4);
-	if (!host)
+	if (!host) {
+		dma_free_noncoherent(hostdata->dev, TOTAL_MEM_SIZE, memory, pScript);
 		return NULL;
+	}
 	memset(hostdata->slots, 0, sizeof(struct NCR_700_command_slot)
 	       * NCR_700_COMMAND_SLOTS_PER_HOST);
 	for (j = 0; j < NCR_700_COMMAND_SLOTS_PER_HOST; j++) {
@@ -394,6 +396,7 @@ struct Scsi_Host *
 
 	if (scsi_add_host(host, dev)) {
 		dev_printk(KERN_ERR, dev, "53c700: scsi_add_host failed\n");
+		dma_free_noncoherent(hostdata->dev, TOTAL_MEM_SIZE, memory, pScript);
 		scsi_host_put(host);
 		return NULL;
 	}
-- 
1.8.3.1


             reply	other threads:[~2016-11-14  7:08 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-11-14  7:07 Li Qiang [this message]
2016-11-17  1:41 ` [PATCH] 53c700: fix memory leak of dma non-cosistent memory Martin K. Petersen
2016-11-17  2:46 ` James Bottomley

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=582962db.0130ed0a.10866.5633@mx.google.com \
    --to=liq3ea@gmail.com \
    --cc=James.Bottomley@HansenPartnership.com \
    --cc=linux-scsi@vger.kernel.org \
    /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