* [PATCH] soc: microchip: mpfs: Fix memory leak in mpfs_sys_controller_probe()
@ 2025-12-28 12:48 Zilin Guan
2026-01-15 19:17 ` Conor Dooley
0 siblings, 1 reply; 2+ messages in thread
From: Zilin Guan @ 2025-12-28 12:48 UTC (permalink / raw)
To: conor.dooley
Cc: daire.mcnamara, linux-riscv, linux-kernel, Zilin Guan, Jianhao Xu
In mpfs_sys_controller_probe(), if of_get_mtd_device_by_node() fails,
the function returns immediately without freeing the allocated memory
for sys_controller, leading to a memory leak.
Fix this by jumping to the out_free label to ensure the memory is
properly freed.
Also, consolidate the error handling for the mbox_request_channel()
failure case to use the same label.
Fixes: 742aa6c563d2 ("soc: microchip: mpfs: enable access to the system controller's flash")
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>
---
drivers/soc/microchip/mpfs-sys-controller.c | 13 +++++++++----
1 file changed, 9 insertions(+), 4 deletions(-)
diff --git a/drivers/soc/microchip/mpfs-sys-controller.c b/drivers/soc/microchip/mpfs-sys-controller.c
index 30bc45d17d34..81636cfecd37 100644
--- a/drivers/soc/microchip/mpfs-sys-controller.c
+++ b/drivers/soc/microchip/mpfs-sys-controller.c
@@ -142,8 +142,10 @@ static int mpfs_sys_controller_probe(struct platform_device *pdev)
sys_controller->flash = of_get_mtd_device_by_node(np);
of_node_put(np);
- if (IS_ERR(sys_controller->flash))
- return dev_err_probe(dev, PTR_ERR(sys_controller->flash), "Failed to get flash\n");
+ if (IS_ERR(sys_controller->flash)) {
+ ret = dev_err_probe(dev, PTR_ERR(sys_controller->flash), "Failed to get flash\n");
+ goto out_free;
+ }
no_flash:
sys_controller->client.dev = dev;
@@ -155,8 +157,7 @@ static int mpfs_sys_controller_probe(struct platform_device *pdev)
if (IS_ERR(sys_controller->chan)) {
ret = dev_err_probe(dev, PTR_ERR(sys_controller->chan),
"Failed to get mbox channel\n");
- kfree(sys_controller);
- return ret;
+ goto out_free;
}
init_completion(&sys_controller->c);
@@ -174,6 +175,10 @@ static int mpfs_sys_controller_probe(struct platform_device *pdev)
dev_info(&pdev->dev, "Registered MPFS system controller\n");
return 0;
+
+out_free:
+ kfree(sys_controller);
+ return ret;
}
static void mpfs_sys_controller_remove(struct platform_device *pdev)
--
2.34.1
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH] soc: microchip: mpfs: Fix memory leak in mpfs_sys_controller_probe()
2025-12-28 12:48 [PATCH] soc: microchip: mpfs: Fix memory leak in mpfs_sys_controller_probe() Zilin Guan
@ 2026-01-15 19:17 ` Conor Dooley
0 siblings, 0 replies; 2+ messages in thread
From: Conor Dooley @ 2026-01-15 19:17 UTC (permalink / raw)
To: Zilin Guan
Cc: conor, Conor Dooley, daire.mcnamara, linux-riscv, linux-kernel,
Jianhao Xu
From: Conor Dooley <conor.dooley@microchip.com>
On Sun, 28 Dec 2025 12:48:36 +0000, Zilin Guan wrote:
> In mpfs_sys_controller_probe(), if of_get_mtd_device_by_node() fails,
> the function returns immediately without freeing the allocated memory
> for sys_controller, leading to a memory leak.
>
> Fix this by jumping to the out_free label to ensure the memory is
> properly freed.
>
> [...]
Applied to riscv-soc-fixes, thanks!
[1/1] soc: microchip: mpfs: Fix memory leak in mpfs_sys_controller_probe()
https://git.kernel.org/conor/c/5a741f8cc6fe
Thanks,
Conor.
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-01-15 19:17 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-12-28 12:48 [PATCH] soc: microchip: mpfs: Fix memory leak in mpfs_sys_controller_probe() Zilin Guan
2026-01-15 19:17 ` Conor Dooley
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox