[PATCH AUTOSEL 5.16 068/109] scsi: pm8001: Fix memory leak in pm8001_chip_fw_flash_update_req()

From: Sasha Levin
Date: Fri Apr 01 2022 - 11:04:11 EST


From: Damien Le Moal <damien.lemoal@xxxxxxxxxxxxxxxxxx>

[ Upstream commit f792a3629f4c4aa4c3703d66b43ce1edcc3ec09a ]

In pm8001_chip_fw_flash_update_build(), if
pm8001_chip_fw_flash_update_build() fails, the struct fw_control_ex
allocated must be freed.

Link: https://lore.kernel.org/r/20220220031810.738362-23-damien.lemoal@xxxxxxxxxxxxxxxxxx
Reviewed-by: Jack Wang <jinpu.wang@xxxxxxxxx>
Signed-off-by: Damien Le Moal <damien.lemoal@xxxxxxxxxxxxxxxxxx>
Signed-off-by: Martin K. Petersen <martin.petersen@xxxxxxxxxx>
Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>
---
drivers/scsi/pm8001/pm8001_hwi.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/scsi/pm8001/pm8001_hwi.c b/drivers/scsi/pm8001/pm8001_hwi.c
index 5325da0e35f7..e1f449dda40b 100644
--- a/drivers/scsi/pm8001/pm8001_hwi.c
+++ b/drivers/scsi/pm8001/pm8001_hwi.c
@@ -4904,8 +4904,10 @@ pm8001_chip_fw_flash_update_req(struct pm8001_hba_info *pm8001_ha,
ccb->ccb_tag = tag;
rc = pm8001_chip_fw_flash_update_build(pm8001_ha, &flash_update_info,
tag);
- if (rc)
+ if (rc) {
+ kfree(fw_control_context);
pm8001_tag_free(pm8001_ha, tag);
+ }

return rc;
}
--
2.34.1