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

Zilin Guan posted 1 patch 1 month, 1 week ago
drivers/scsi/hpsa.c | 1 +
1 file changed, 1 insertion(+)
[PATCH v2] scsi: hpsa: Fix memory leak in hpsa_undo_allocations_after_kdump_soft_reset()
Posted by Zilin Guan 1 month, 1 week ago
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@web.de>
Co-developed-by: Jianhao Xu <jianhao.xu@seu.edu.cn>
Signed-off-by: Jianhao Xu <jianhao.xu@seu.edu.cn>
Signed-off-by: Zilin Guan <zilin@seu.edu.cn>
---
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
Re: [PATCH v2] scsi: hpsa: Fix memory leak in hpsa_undo_allocations_after_kdump_soft_reset()
Posted by Markus Elfring 1 month, 1 week ago
…
> +++ 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 */
>  }

I wonder about the alignment and relevance for these code comments.

Regards,
Markus
Re: [PATCH v2] scsi: hpsa: Fix memory leak in hpsa_undo_allocations_after_kdump_soft_reset()
Posted by Zilin Guan 1 month ago
On Wed, Dec 31, 2025 at 05:25:23PM +0100, Markus Elfring wrote:
> …
> > +++ 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 */
> >  }
> 
> I wonder about the alignment and relevance for these code comments.
> 
> Regards,
> Markus

Hi Markus,

Thank you for your review.

Regarding the alignment, it was an oversight caused by the inconsistency 
between my editor configuration and the Linux kernel's style. I will 
correct this in v3.

As for the code comment, it indicates that the memory being freed here 
was allocated during the first stage of initialization in 
hpsa_init_one(). I included it to maintain consistency with the existing 
kfree(h) line immediately following it.

Best regards,
Zilin Guan
Re: [PATCH v2] scsi: hpsa: Fix memory leak in hpsa_undo_allocations_after_kdump_soft_reset()
Posted by Zilin Guan 1 month ago
On Sat, Jan 03, 2026 at 12:39:10PM +0000, Zilin Guan wrote:
> Hi Markus,
> 
> Thank you for your review.
> 
> Regarding the alignment, it was an oversight caused by the inconsistency 
> between my editor configuration and the Linux kernel's style. I will 
> correct this in v3.

Apologies, please disregard my previous reply.

I realized that the perceived misalignment is actually a tab rendering 
artifact. I have verified that the indentation in v2 is correct and 
aligns perfectly with the surrounding code when applied.

Therefore, v2 is correct as-is and a v3 is not necessary.

Best regards,
Zilin Guan