Skip to content

Commit 878b02d

Browse files
crawls-hubabelvesa
authored andcommitted
clk: imx: clk-imx8mp: improve error handling in imx8mp_clocks_probe()
Replace of_iomap() and kzalloc() with devm_of_iomap() and devm_kzalloc() which can automatically release the related memory when the device or driver is removed or unloaded to avoid potential memory leak. In this case, iounmap(anatop_base) in line 427,433 are removed as manual release is not required. Besides, referring to clk-imx8mq.c, check the return code of of_clk_add_hw_provider, if it returns negtive, print error info and unregister hws, which makes the program more robust. Fixes: 9c140d9 ("clk: imx: Add support for i.MX8MP clock driver") Signed-off-by: Yuxing Liu <[email protected]> Reviewed-by: Dongliang Mu <[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 e02ba11 commit 878b02d

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

drivers/clk/imx/clk-imx8mp.c

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -414,25 +414,22 @@ static int imx8mp_clocks_probe(struct platform_device *pdev)
414414
struct device *dev = &pdev->dev;
415415
struct device_node *np;
416416
void __iomem *anatop_base, *ccm_base;
417+
int err;
417418

418419
np = of_find_compatible_node(NULL, NULL, "fsl,imx8mp-anatop");
419-
anatop_base = of_iomap(np, 0);
420+
anatop_base = devm_of_iomap(dev, np, 0, NULL);
420421
of_node_put(np);
421-
if (WARN_ON(!anatop_base))
422-
return -ENOMEM;
422+
if (WARN_ON(IS_ERR(anatop_base)))
423+
return PTR_ERR(anatop_base);
423424

424425
np = dev->of_node;
425426
ccm_base = devm_platform_ioremap_resource(pdev, 0);
426-
if (WARN_ON(IS_ERR(ccm_base))) {
427-
iounmap(anatop_base);
427+
if (WARN_ON(IS_ERR(ccm_base)))
428428
return PTR_ERR(ccm_base);
429-
}
430429

431-
clk_hw_data = kzalloc(struct_size(clk_hw_data, hws, IMX8MP_CLK_END), GFP_KERNEL);
432-
if (WARN_ON(!clk_hw_data)) {
433-
iounmap(anatop_base);
430+
clk_hw_data = devm_kzalloc(dev, struct_size(clk_hw_data, hws, IMX8MP_CLK_END), GFP_KERNEL);
431+
if (WARN_ON(!clk_hw_data))
434432
return -ENOMEM;
435-
}
436433

437434
clk_hw_data->num = IMX8MP_CLK_END;
438435
hws = clk_hw_data->hws;
@@ -722,7 +719,12 @@ static int imx8mp_clocks_probe(struct platform_device *pdev)
722719

723720
imx_check_clk_hws(hws, IMX8MP_CLK_END);
724721

725-
of_clk_add_hw_provider(np, of_clk_hw_onecell_get, clk_hw_data);
722+
err = of_clk_add_hw_provider(np, of_clk_hw_onecell_get, clk_hw_data);
723+
if (err < 0) {
724+
dev_err(dev, "failed to register hws for i.MX8MP\n");
725+
imx_unregister_hw_clocks(hws, IMX8MP_CLK_END);
726+
return err;
727+
}
726728

727729
imx_register_uart_clocks();
728730

0 commit comments

Comments
 (0)