diff mbox series

scsi: hpsa: fix error handling in hpsa_add_sas_host()

Message ID 20221110151129.394389-1-yangyingliang@huawei.com
State New
Headers show
Series scsi: hpsa: fix error handling in hpsa_add_sas_host() | expand

Commit Message

Yang Yingliang Nov. 10, 2022, 3:11 p.m. UTC
Here is implenmention of hpsa_sas_port_add_phy():
hpsa_sas_port_add_phy()
  ...
  sas_phy_add()  -> may return error here
  sas_port_add_phy()
  ...

Here is implenmention of hpsa_free_sas_phy():
hpsa_free_sas_phy()
  ...
  sas_port_delete_phy()
  sas_phy_delete()
  ...

If hpsa_sas_port_add_phy() returns error, hpsa_free_sas_phy()
can not be called free the memory, because the port and the
phy have not been added yet. So replace it with sas_phy_free()
and kfree() to avoid kernel crash in this case.

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

Comments

Martin K. Petersen Dec. 1, 2022, 3:45 a.m. UTC | #1
On Thu, 10 Nov 2022 23:11:29 +0800, Yang Yingliang wrote:

> Here is implenmention of hpsa_sas_port_add_phy():
> hpsa_sas_port_add_phy()
>   ...
>   sas_phy_add()  -> may return error here
>   sas_port_add_phy()
>   ...
> 
> [...]

Applied to 6.2/scsi-queue, thanks!

[1/1] scsi: hpsa: fix error handling in hpsa_add_sas_host()
      https://git.kernel.org/mkp/scsi/c/4ef174a3ad9b
diff mbox series

Patch

diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
index f8e832b1bc46..b3f195467e97 100644
--- a/drivers/scsi/hpsa.c
+++ b/drivers/scsi/hpsa.c
@@ -9786,7 +9786,8 @@  static int hpsa_add_sas_host(struct ctlr_info *h)
 	return 0;
 
 free_sas_phy:
-	hpsa_free_sas_phy(hpsa_sas_phy);
+	sas_phy_free(hpsa_sas_phy->phy);
+	kfree(hpsa_sas_phy);
 free_sas_port:
 	hpsa_free_sas_port(hpsa_sas_port);
 free_sas_node: