[PATCH] scsi: elx: Fix memory leak on scsi_add_host_with_dma failure

Chen Changcheng <[email protected]>
Newsgroups org.kernel.vger.linux-scsi,org.kernel.vger.linux-kernel,org.kernel.vger.target-devel
Message-ID <[email protected]>
If scsi_add_host_with_dma() fails in efct_scsi_new_device() or
efct_scsi_new_vport(), the Scsi_Host allocated by scsi_host_alloc()
is never released, causing a memory leak.

The caller's error path has no knowledge of this internal allocation:
 - efct_scsi_new_device's caller (efct_xport_initialize) only frees
   the xport structure, not the Scsi_Host.
 - efct_scsi_new_vport's caller chain (efct_vport_create ->
   fc_vport_setup) only cleans up the fc_vport structure itself,
   not the vport's Scsi_Host allocated inside efct_scsi_new_vport.

Add the missing scsi_host_put() calls before each error return.

Signed-off-by: Chen Changcheng <[email protected]>
---
 drivers/scsi/elx/efct/efct_xport.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/scsi/elx/efct/efct_xport.c b/drivers/scsi/elx/efct/efct_xport.c
index 9dcaef6fc188..61ebbf091d71 100644
--- a/drivers/scsi/elx/efct/efct_xport.c
+++ b/drivers/scsi/elx/efct/efct_xport.c
@@ -416,6 +416,7 @@ efct_scsi_new_device(struct efct *efct)
 				       &efct->pci->dev);
 	if (error) {
 		efc_log_debug(efct, "failed scsi_add_host_with_dma\n");
+		scsi_host_put(shost);
 		return -EIO;
 	}
 
@@ -930,6 +931,7 @@ efct_scsi_new_vport(struct efct *efct, struct device *dev)
 	error = scsi_add_host_with_dma(shost, dev, &efct->pci->dev);
 	if (error) {
 		efc_log_debug(efct, "failed scsi_add_host_with_dma\n");
+		scsi_host_put(shost);
 		return NULL;
 	}
 
-- 
2.25.1
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.