diff mbox series

scsi: hpsa: fix possible memory leak in hpsa_add_sas_device()

Message ID 20221111043012.1074466-1-yangyingliang@huawei.com (mailing list archive)
State Accepted
Headers show
Series scsi: hpsa: fix possible memory leak in hpsa_add_sas_device() | expand

Commit Message

Yang Yingliang Nov. 11, 2022, 4:30 a.m. UTC
If hpsa_sas_port_add_rphy() returns error, the 'rphy' allocated
in sas_end_device_alloc() need be free, fix this by calling
sas_rphy_free() in the error path.

Fixes: d04e62b9d63a ("hpsa: add in sas transport class")
Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
---
 drivers/scsi/hpsa.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Comments

Martin K. Petersen Nov. 26, 2022, 12:18 a.m. UTC | #1
Yang,

> If hpsa_sas_port_add_rphy() returns error, the 'rphy' allocated
> in sas_end_device_alloc() need be free, fix this by calling
> sas_rphy_free() in the error path.

Applied to 6.2/scsi-staging, thanks!
Martin K. Petersen Dec. 1, 2022, 3:45 a.m. UTC | #2
On Fri, 11 Nov 2022 12:30:12 +0800, Yang Yingliang wrote:

> If hpsa_sas_port_add_rphy() returns error, the 'rphy' allocated
> in sas_end_device_alloc() need be free, fix this by calling
> sas_rphy_free() in the error path.
> 
> 

Applied to 6.2/scsi-queue, thanks!

[1/1] scsi: hpsa: fix possible memory leak in hpsa_add_sas_device()
      https://git.kernel.org/mkp/scsi/c/fda34a5d304d
diff mbox series

Patch

diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
index b3f195467e97..1d2cad257dab 100644
--- a/drivers/scsi/hpsa.c
+++ b/drivers/scsi/hpsa.c
@@ -9823,10 +9823,12 @@  static int hpsa_add_sas_device(struct hpsa_sas_node *hpsa_sas_node,
 
 	rc = hpsa_sas_port_add_rphy(hpsa_sas_port, rphy);
 	if (rc)
-		goto free_sas_port;
+		goto free_sas_rphy;
 
 	return 0;
 
+free_sas_rphy:
+	sas_rphy_free(rphy);
 free_sas_port:
 	hpsa_free_sas_port(hpsa_sas_port);
 	device->sas_port = NULL;