Skip to content
/ linux Public

Commit e3dd5cf

Browse files
GoodLuck612gregkh
authored andcommitted
soc: microchip: mpfs: Fix memory leak in mpfs_sys_controller_probe()
[ Upstream commit 5a741f8 ] 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: 742aa6c ("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> Signed-off-by: Conor Dooley <conor.dooley@microchip.com> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 8f9e054 commit e3dd5cf

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

drivers/soc/microchip/mpfs-sys-controller.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,10 @@ static int mpfs_sys_controller_probe(struct platform_device *pdev)
142142

143143
sys_controller->flash = of_get_mtd_device_by_node(np);
144144
of_node_put(np);
145-
if (IS_ERR(sys_controller->flash))
146-
return dev_err_probe(dev, PTR_ERR(sys_controller->flash), "Failed to get flash\n");
145+
if (IS_ERR(sys_controller->flash)) {
146+
ret = dev_err_probe(dev, PTR_ERR(sys_controller->flash), "Failed to get flash\n");
147+
goto out_free;
148+
}
147149

148150
no_flash:
149151
sys_controller->client.dev = dev;
@@ -155,8 +157,7 @@ static int mpfs_sys_controller_probe(struct platform_device *pdev)
155157
if (IS_ERR(sys_controller->chan)) {
156158
ret = dev_err_probe(dev, PTR_ERR(sys_controller->chan),
157159
"Failed to get mbox channel\n");
158-
kfree(sys_controller);
159-
return ret;
160+
goto out_free;
160161
}
161162

162163
init_completion(&sys_controller->c);
@@ -174,6 +175,10 @@ static int mpfs_sys_controller_probe(struct platform_device *pdev)
174175
dev_info(&pdev->dev, "Registered MPFS system controller\n");
175176

176177
return 0;
178+
179+
out_free:
180+
kfree(sys_controller);
181+
return ret;
177182
}
178183

179184
static void mpfs_sys_controller_remove(struct platform_device *pdev)

0 commit comments

Comments
 (0)