* [PATCH] soc: microchip: mpfs: Fix a memory leak in mpfs_sys_controller_probe()
@ 2026-02-03 13:03 Felix Gu
2026-02-03 16:00 ` Markus Elfring
2026-02-06 19:52 ` Conor Dooley
0 siblings, 2 replies; 3+ messages in thread
From: Felix Gu @ 2026-02-03 13:03 UTC (permalink / raw)
To: Conor Dooley, Daire McNamara; +Cc: linux-riscv, linux-kernel, Felix Gu
In mpfs_sys_controller_probe(), when of_get_mtd_device_by_node() fails,
the previously allocated sys_controller was leaked.
Add kfree() to fix this.
Fixes: 742aa6c563d2 ("soc: microchip: mpfs: enable access to the system controller's flash")
Signed-off-by: Felix Gu <ustc.gu@gmail.com>
---
drivers/soc/microchip/mpfs-sys-controller.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/drivers/soc/microchip/mpfs-sys-controller.c b/drivers/soc/microchip/mpfs-sys-controller.c
index 30bc45d17d34..a7401cb79e97 100644
--- a/drivers/soc/microchip/mpfs-sys-controller.c
+++ b/drivers/soc/microchip/mpfs-sys-controller.c
@@ -142,8 +142,11 @@ 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");
+ kfree(sys_controller);
+ return ret;
+ }
no_flash:
sys_controller->client.dev = dev;
---
base-commit: 193579fe01389bc21aff0051d13f24e8ea95b47d
change-id: 20260203-mpfs-272dd46bef90
Best regards,
--
Felix Gu <ustc.gu@gmail.com>
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH] soc: microchip: mpfs: Fix a memory leak in mpfs_sys_controller_probe()
2026-02-03 13:03 [PATCH] soc: microchip: mpfs: Fix a memory leak in mpfs_sys_controller_probe() Felix Gu
@ 2026-02-03 16:00 ` Markus Elfring
2026-02-06 19:52 ` Conor Dooley
1 sibling, 0 replies; 3+ messages in thread
From: Markus Elfring @ 2026-02-03 16:00 UTC (permalink / raw)
To: Felix Gu, linux-riscv, Conor Dooley, Daire McNamara; +Cc: LKML, kernel-janitors
> In mpfs_sys_controller_probe(), when of_get_mtd_device_by_node() fails,
> the previously allocated sys_controller was leaked.
>
> Add kfree() to fix this.
https://elixir.bootlin.com/linux/v6.19-rc5/source/drivers/soc/microchip/mpfs-sys-controller.c#L128-L177
* Were any source code analysis tools involved here?
* Would you like to complete the exception handling by using another goto chain?
* How do you think about to increase the application of scope-based resource management?
* See also once more:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/stable-kernel-rules.rst?h=v6.19-rc8#n34
Regards,
Markus
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] soc: microchip: mpfs: Fix a memory leak in mpfs_sys_controller_probe()
2026-02-03 13:03 [PATCH] soc: microchip: mpfs: Fix a memory leak in mpfs_sys_controller_probe() Felix Gu
2026-02-03 16:00 ` Markus Elfring
@ 2026-02-06 19:52 ` Conor Dooley
1 sibling, 0 replies; 3+ messages in thread
From: Conor Dooley @ 2026-02-06 19:52 UTC (permalink / raw)
To: Felix Gu; +Cc: Conor Dooley, Daire McNamara, linux-riscv, linux-kernel
[-- Attachment #1.1: Type: text/plain, Size: 1456 bytes --]
On Tue, Feb 03, 2026 at 09:03:52PM +0800, Felix Gu wrote:
> In mpfs_sys_controller_probe(), when of_get_mtd_device_by_node() fails,
> the previously allocated sys_controller was leaked.
>
> Add kfree() to fix this.
>
> Fixes: 742aa6c563d2 ("soc: microchip: mpfs: enable access to the system controller's flash")
> Signed-off-by: Felix Gu <ustc.gu@gmail.com>
> ---
> drivers/soc/microchip/mpfs-sys-controller.c | 7 +++++--
> 1 file changed, 5 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/soc/microchip/mpfs-sys-controller.c b/drivers/soc/microchip/mpfs-sys-controller.c
> index 30bc45d17d34..a7401cb79e97 100644
> --- a/drivers/soc/microchip/mpfs-sys-controller.c
> +++ b/drivers/soc/microchip/mpfs-sys-controller.c
> @@ -142,8 +142,11 @@ 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");
> + kfree(sys_controller);
> + return ret;
> + }
>
> no_flash:
> sys_controller->client.dev = dev;
This is a duplicate of a patch in my riscv-soc-fixes branch, that for
whatever reason I forgot to push. I'll keep the original but thanks for
your patch.
[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]
[-- Attachment #2: Type: text/plain, Size: 161 bytes --]
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-02-06 19:52 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-02-03 13:03 [PATCH] soc: microchip: mpfs: Fix a memory leak in mpfs_sys_controller_probe() Felix Gu
2026-02-03 16:00 ` Markus Elfring
2026-02-06 19:52 ` Conor Dooley
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox