Skip to content

Commit

Permalink
scsi: hpsa: Fix error handling in hpsa_add_sas_host()
Browse files Browse the repository at this point in the history
[ Upstream commit 4ef174a ]

hpsa_sas_port_add_phy() does:
  ...
  sas_phy_add()  -> may return error here
  sas_port_add_phy()
  ...

Whereas hpsa_free_sas_phy() does:
  ...
  sas_port_delete_phy()
  sas_phy_delete()
  ...

If hpsa_sas_port_add_phy() returns an error, hpsa_free_sas_phy() can not be
called to free the memory because the port and the phy have not been added
yet.

Replace hpsa_free_sas_phy() with sas_phy_free() and kfree() to avoid kernel
crash in this case.

Fixes: d04e62b ("hpsa: add in sas transport class")
Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
Link: https://lore.kernel.org/r/20221110151129.394389-1-yangyingliang@huawei.com
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
  • Loading branch information
Yang Yingliang authored and gregkh committed Dec 31, 2022
1 parent d17bca3 commit 9aa5b09
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion drivers/scsi/hpsa.c
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 9aa5b09

Please sign in to comment.