[PATCH v2] scsi: hpsa: Fix memory leak in hpsa_undo_allocations_after_kdump_soft_reset()

From: Zilin Guan

Date: Wed Dec 31 2025 - 10:00:08 EST


The h->reply_map is allocated in hpda_alloc_ctlr_info() via kcalloc().
If the controller reset fails during initialization in hpsa_init_one(),
hpsa_undo_allocations_after_kdump_soft_reset() is called to clean up
resources. However, this function frees the controller structure h but
fails to free h->reply_map, leading to a memory leak.

Fix this by freeing h->reply_map before freeing h in the cleanup function.

Fixes: 8b834bff1b73 ("scsi: hpsa: fix selection of reply queue")
Suggested-by: Markus Elfring <Markus.Elfring@xxxxxx>
Co-developed-by: Jianhao Xu <jianhao.xu@xxxxxxxxxx>
Signed-off-by: Jianhao Xu <jianhao.xu@xxxxxxxxxx>
Signed-off-by: Zilin Guan <zilin@xxxxxxxxxx>
---
Changes in v2:
- Remove redundant NULL assignment for h->reply_map.

drivers/scsi/hpsa.c | 1 +
1 file changed, 1 insertion(+)

diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
index 3654b12c5d5a..ce69cd381e9f 100644
--- a/drivers/scsi/hpsa.c
+++ b/drivers/scsi/hpsa.c
@@ -8212,6 +8212,7 @@ static void hpsa_undo_allocations_after_kdump_soft_reset(struct ctlr_info *h)
h->monitor_ctlr_wq = NULL;
}

+ kfree(h->reply_map); /* init_one 1 */
kfree(h); /* init_one 1 */
}

--
2.34.1