soc: microchip: mpfs: Fix memory leak in mpfs_sys_controller_probe()
Subsystems (3)
PATCH 1/1 soc: microchip: mpfs: Fix memory leak in mpfs_sys_controller_probe()
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.
--- drivers/soc/microchip/mpfs-sys-controller.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-)
drivers/soc/microchip/mpfs-sys-controller.c +9 -4
@@ -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)
Signature · 1 line
2.34.1
From: Conor Dooley <[email protected]>
Quoted 8 lines · Zilin Guan
In
mpfs_sys_controller_probe(), ifof_get_mtd_device_by_node()fails, the function returns immediately without freeing the allocated memory forsys_controller, leading to a memory leak.Fix this by jumping to the
out_freelabel 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.