[PATCH] scsi: elx: efct: fix Scsi_Host memory leaks on add failure

From: Guangshuo Li

Date: Sat Sep 19 2026 - 13:49:41 EST


efct_scsi_new_device() and efct_scsi_new_vport() allocate a Scsi_Host
with scsi_host_alloc() before registering it with
scsi_add_host_with_dma().

If scsi_add_host_with_dma() fails, both functions return without
dropping the initial host reference returned by scsi_host_alloc().
Although scsi_add_host_with_dma() unwinds the resources acquired while
adding the host, it does not release that initial reference. As a result,
scsi_host_dev_release() is never reached and the Scsi_Host allocation is
leaked.

Call scsi_host_put() on both failure paths so the initial reference is
dropped and scsi_host_dev_release() can free the host. Also clear
efct->shost on the physical host failure path since it is assigned before
the host is registered.

The issue was identified by a static analysis tool I developed and
confirmed by manual review.

Fixes: 4df84e846624 ("scsi: elx: efct: Driver initialization routines")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Guangshuo Li <lgs201920130244@xxxxxxxxx>
---
drivers/scsi/elx/efct/efct_xport.c | 3 +++
1 file changed, 3 insertions(+)

diff --git a/drivers/scsi/elx/efct/efct_xport.c b/drivers/scsi/elx/efct/efct_xport.c
index 9dcaef6fc188..c00ad9176aee 100644
--- a/drivers/scsi/elx/efct/efct_xport.c
+++ b/drivers/scsi/elx/efct/efct_xport.c
@@ -416,6 +416,8 @@ efct_scsi_new_device(struct efct *efct)
&efct->pci->dev);
if (error) {
efc_log_debug(efct, "failed scsi_add_host_with_dma\n");
+ efct->shost = NULL;
+ scsi_host_put(shost);
return -EIO;
}

@@ -930,6 +932,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.43.0