Skip to content

Commit e02ba11

Browse files
Zhanhao Huabelvesa
authored andcommitted
clk: imx93: fix memory leak and missing unwind goto in imx93_clocks_probe
In function probe(), it returns directly without unregistered hws when error occurs. Fix this by adding 'goto unregister_hws;' on line 295 and line 310. Use devm_kzalloc() instead of kzalloc() to automatically free the memory using devm_kfree() when error occurs. Replace of_iomap() with devm_of_iomap() to automatically handle the unused ioremap region and delete 'iounmap(anatop_base);' in unregister_hws. Fixes: 24defbe ("clk: imx: add i.MX93 clk") Signed-off-by: Zhanhao Hu <[email protected]> Reviewed-by: Abel Vesa <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Abel Vesa <[email protected]>
1 parent 188d070 commit e02ba11

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

drivers/clk/imx/clk-imx93.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ static int imx93_clocks_probe(struct platform_device *pdev)
264264
void __iomem *base, *anatop_base;
265265
int i, ret;
266266

267-
clk_hw_data = kzalloc(struct_size(clk_hw_data, hws,
267+
clk_hw_data = devm_kzalloc(dev, struct_size(clk_hw_data, hws,
268268
IMX93_CLK_END), GFP_KERNEL);
269269
if (!clk_hw_data)
270270
return -ENOMEM;
@@ -288,10 +288,12 @@ static int imx93_clocks_probe(struct platform_device *pdev)
288288
"sys_pll_pfd2", 1, 2);
289289

290290
np = of_find_compatible_node(NULL, NULL, "fsl,imx93-anatop");
291-
anatop_base = of_iomap(np, 0);
291+
anatop_base = devm_of_iomap(dev, np, 0, NULL);
292292
of_node_put(np);
293-
if (WARN_ON(!anatop_base))
294-
return -ENOMEM;
293+
if (WARN_ON(IS_ERR(anatop_base))) {
294+
ret = PTR_ERR(base);
295+
goto unregister_hws;
296+
}
295297

296298
clks[IMX93_CLK_ARM_PLL] = imx_clk_fracn_gppll_integer("arm_pll", "osc_24m",
297299
anatop_base + 0x1000,
@@ -304,8 +306,8 @@ static int imx93_clocks_probe(struct platform_device *pdev)
304306
np = dev->of_node;
305307
base = devm_platform_ioremap_resource(pdev, 0);
306308
if (WARN_ON(IS_ERR(base))) {
307-
iounmap(anatop_base);
308-
return PTR_ERR(base);
309+
ret = PTR_ERR(base);
310+
goto unregister_hws;
309311
}
310312

311313
for (i = 0; i < ARRAY_SIZE(root_array); i++) {
@@ -345,7 +347,6 @@ static int imx93_clocks_probe(struct platform_device *pdev)
345347

346348
unregister_hws:
347349
imx_unregister_hw_clocks(clks, IMX93_CLK_END);
348-
iounmap(anatop_base);
349350

350351
return ret;
351352
}

0 commit comments

Comments
 (0)