]> git.baikalelectronics.ru Git - kernel.git/commit
scsi: hpsa: Fix error handling in hpsa_add_sas_host()
authorYang Yingliang <yangyingliang@huawei.com>
Thu, 10 Nov 2022 15:11:29 +0000 (23:11 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 31 Dec 2022 12:32:35 +0000 (13:32 +0100)
commit67bcad709279c76a1bb0ec3f612f4e230754f811
tree19bfeb31287a9b8f09ce65ac08529412ae9bba82
parent669cfd56ee33efa11fc932a2010b2c7bbc0739fb
scsi: hpsa: Fix error handling in hpsa_add_sas_host()

[ Upstream commit 4816fb4ebcece4c39bc67f4bd88dbd19258117ff ]

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: ad7a04aed518 ("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>
drivers/scsi/hpsa.c