Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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: b80522040cd3 ("clk: imx: Add clock driver for i.MX8MQ CCM")
Reported-by: kernel test robot <lkp@intel.com>
Reported-by: Dan Carpenter <error27@gmail.com>
Closes: https://lore.kernel.org/r/202309240551.e46NllPa-lkp@intel.com/
Signed-off-by: Peng Fan <peng.fan@nxp.com>
Link: https://lore.kernel.org/r/20231001122618.194498-1-peng.fan@oss.nxp.com
Signed-off-by: Abel Vesa <abel.vesa@linaro.org>

authored by

Peng Fan and committed by
Abel Vesa
577ad169 05eeeff2

+10 -7
+10 -7
drivers/clk/imx/clk-imx8mq.c
··· 288 288 void __iomem *base; 289 289 int err; 290 290 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); 293 292 if (WARN_ON(!clk_hw_data)) 294 293 return -ENOMEM; 295 294 ··· 305 306 hws[IMX8MQ_CLK_EXT4] = imx_get_clk_hw_by_name(np, "clk_ext4"); 306 307 307 308 np = of_find_compatible_node(NULL, NULL, "fsl,imx8mq-anatop"); 308 - base = of_iomap(np, 0); 309 + base = devm_of_iomap(dev, np, 0, NULL); 309 310 of_node_put(np); 310 - if (WARN_ON(!base)) 311 - return -ENOMEM; 311 + if (WARN_ON(IS_ERR(base))) { 312 + err = PTR_ERR(base); 313 + goto unregister_hws; 314 + } 312 315 313 316 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)); 314 317 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)); ··· 396 395 397 396 np = dev->of_node; 398 397 base = devm_platform_ioremap_resource(pdev, 0); 399 - if (WARN_ON(IS_ERR(base))) 400 - return PTR_ERR(base); 398 + if (WARN_ON(IS_ERR(base))) { 399 + err = PTR_ERR(base); 400 + goto unregister_hws; 401 + } 401 402 402 403 /* CORE */ 403 404 hws[IMX8MQ_CLK_A53_DIV] = imx8m_clk_hw_composite_core("arm_a53_div", imx8mq_a53_sels, base + 0x8000);