Skip to content

Commit 577ad16

Browse files
MrVanabelvesa
authored andcommitted
clk: imx: imx8mq: correct error handling path
Avoid memory leak in error handling path. It does not make much sense for the SoC without clk driver, to make program behavior correct, let's fix it. Fixes: b805220 ("clk: imx: Add clock driver for i.MX8MQ CCM") Reported-by: kernel test robot <[email protected]> Reported-by: Dan Carpenter <[email protected]> Closes: https://lore.kernel.org/r/[email protected]/ Signed-off-by: Peng Fan <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Abel Vesa <[email protected]>
1 parent 05eeeff commit 577ad16

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

drivers/clk/imx/clk-imx8mq.c

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -288,8 +288,7 @@ static int imx8mq_clocks_probe(struct platform_device *pdev)
288288
void __iomem *base;
289289
int err;
290290

291-
clk_hw_data = kzalloc(struct_size(clk_hw_data, hws,
292-
IMX8MQ_CLK_END), GFP_KERNEL);
291+
clk_hw_data = devm_kzalloc(dev, struct_size(clk_hw_data, hws, IMX8MQ_CLK_END), GFP_KERNEL);
293292
if (WARN_ON(!clk_hw_data))
294293
return -ENOMEM;
295294

@@ -306,10 +305,12 @@ static int imx8mq_clocks_probe(struct platform_device *pdev)
306305
hws[IMX8MQ_CLK_EXT4] = imx_get_clk_hw_by_name(np, "clk_ext4");
307306

308307
np = of_find_compatible_node(NULL, NULL, "fsl,imx8mq-anatop");
309-
base = of_iomap(np, 0);
308+
base = devm_of_iomap(dev, np, 0, NULL);
310309
of_node_put(np);
311-
if (WARN_ON(!base))
312-
return -ENOMEM;
310+
if (WARN_ON(IS_ERR(base))) {
311+
err = PTR_ERR(base);
312+
goto unregister_hws;
313+
}
313314

314315
hws[IMX8MQ_ARM_PLL_REF_SEL] = imx_clk_hw_mux("arm_pll_ref_sel", base + 0x28, 16, 2, pll_ref_sels, ARRAY_SIZE(pll_ref_sels));
315316
hws[IMX8MQ_GPU_PLL_REF_SEL] = imx_clk_hw_mux("gpu_pll_ref_sel", base + 0x18, 16, 2, pll_ref_sels, ARRAY_SIZE(pll_ref_sels));
@@ -395,8 +396,10 @@ static int imx8mq_clocks_probe(struct platform_device *pdev)
395396

396397
np = dev->of_node;
397398
base = devm_platform_ioremap_resource(pdev, 0);
398-
if (WARN_ON(IS_ERR(base)))
399-
return PTR_ERR(base);
399+
if (WARN_ON(IS_ERR(base))) {
400+
err = PTR_ERR(base);
401+
goto unregister_hws;
402+
}
400403

401404
/* CORE */
402405
hws[IMX8MQ_CLK_A53_DIV] = imx8m_clk_hw_composite_core("arm_a53_div", imx8mq_a53_sels, base + 0x8000);

0 commit comments

Comments
 (0)