Skip to contentSkip to conversation

53c700: fix memory leak of dma non-cosistent memory

PATCH In review Li Qiang 3 participants 3 messages Nov 14, 2016 – Nov 17, 2016

Subsystems (3)
lore
Share & tools
lore

Li Qiang

author
#0 lore raw

PATCH 1/1 53c700: fix memory leak of dma non-cosistent memory

From: Li Qiang <[email protected]>

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.

---
 drivers/scsi/53c700.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/scsi/53c700.c +4 -1
index 95e32a4..d5a2ba3 100644
@@ -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;
 	}
Signature · 1 line
1.8.3.1
#1 lore raw
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

"Li" == Li Qiang <[email protected]> writes:

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

James: Please review!

Signature · 1 line
Martin K. Petersen	Oracle Linux Engineering
maintainer
#2 lore raw
In reply to Li Qiang
Quoted 7 lines · Li Qiang

From: Li Qiang <[email protected]>

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.

There's not a lot of point doing this, since the memory leak is so tiny and the failures would be instantly noticeable. However:

Quoted 9 lines
---
 drivers/scsi/53c700.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/scsi/53c700.c +0 -0
index 95e32a4..d5a2ba3 100644

drivers/scsi/53c700.c struct Scsi_Host * · line 339

Quoted 9 lines
drivers/scsi/53c700.c +3 -1
@@ -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;
+	}

This you could do.

Quoted 12 lines
drivers/scsi/53c700.c +0 -0
 	memset(hostdata->slots, 0, sizeof(struct
 NCR_700_command_slot)
drivers/scsi/53c700.c +1 -0
 	       * 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);

drivers/scsi/53c700.c struct Scsi_Host * · line 402

Quoted 2 lines
drivers/scsi/53c700.c +0 -0
 		return NULL;
 	}

This I'm not sure about; I'd have to dig more deeply into how the driver works. If the scripts engine is already started, you can't just free the memory it's running from without actually stopping it, otherwise nasty things may happen if something else reuses the memory.
I have a vague feeling that this driver is activation driven rather
than mailbox driven, so it might be OK, but it needs checking.

James