In function probe(), it returns directly without unregistered hws
when error occurs.
I fix this by adding 'goto unregister_hws;' on line 295 and
line 310.
Besides, I use devm_kzalloc() instead of kzalloc() to automatically
free the memory using devm_kfree() when error occurs.
Similarly, I replace of_iomap() with devm_of_iomap() to automatically
handle the unused ioremap region. So I delete 'iounmap(anatop_base);'
in unregister_hws.
Fixes: 24defbe194b6 ("clk: imx: add i.MX93 clk")
Signed-off-by: Zhanhao Hu <[email protected]>
Reviewed-by: Dongliang Mu <[email protected]>
---
This issue is found by static analysis and remains untested.
---
drivers/clk/imx/clk-imx93.c | 15 ++++++++-------
1 file changed, 8 insertions(+), 7 deletions(-)
diff --git a/drivers/clk/imx/clk-imx93.c b/drivers/clk/imx/clk-imx93.c
index 07b4a043e449..b6c7c2725906 100644
--- a/drivers/clk/imx/clk-imx93.c
+++ b/drivers/clk/imx/clk-imx93.c
@@ -264,7 +264,7 @@ static int imx93_clocks_probe(struct platform_device *pdev)
void __iomem *base, *anatop_base;
int i, ret;
- clk_hw_data = kzalloc(struct_size(clk_hw_data, hws,
+ clk_hw_data = devm_kzalloc(dev, struct_size(clk_hw_data, hws,
IMX93_CLK_END), GFP_KERNEL);
if (!clk_hw_data)
return -ENOMEM;
@@ -288,10 +288,12 @@ static int imx93_clocks_probe(struct platform_device *pdev)
"sys_pll_pfd2", 1, 2);
np = of_find_compatible_node(NULL, NULL, "fsl,imx93-anatop");
- anatop_base = of_iomap(np, 0);
+ anatop_base = devm_of_iomap(dev, np, 0, NULL);
of_node_put(np);
- if (WARN_ON(!anatop_base))
- return -ENOMEM;
+ if (WARN_ON(IS_ERR(anatop_base))) {
+ ret = PTR_ERR(base);
+ goto unregister_hws;
+ }
clks[IMX93_CLK_ARM_PLL] = imx_clk_fracn_gppll_integer("arm_pll", "osc_24m",
anatop_base + 0x1000,
@@ -304,8 +306,8 @@ static int imx93_clocks_probe(struct platform_device *pdev)
np = dev->of_node;
base = devm_platform_ioremap_resource(pdev, 0);
if (WARN_ON(IS_ERR(base))) {
- iounmap(anatop_base);
- return PTR_ERR(base);
+ ret = PTR_ERR(base);
+ goto unregister_hws;
}
for (i = 0; i < ARRAY_SIZE(root_array); i++) {
@@ -345,7 +347,6 @@ static int imx93_clocks_probe(struct platform_device *pdev)
unregister_hws:
imx_unregister_hw_clocks(clks, IMX93_CLK_END);
- iounmap(anatop_base);
return ret;
}
--
2.34.1
On 4/26/2023 10:25 PM, Zhanhao Hu wrote:
> In function probe(), it returns directly without unregistered hws
> when error occurs.
>
> I fix this by adding 'goto unregister_hws;' on line 295 and
> line 310.
>
> Besides, I use devm_kzalloc() instead of kzalloc() to automatically
> free the memory using devm_kfree() when error occurs.
>
> Similarly, I replace of_iomap() with devm_of_iomap() to automatically
> handle the unused ioremap region. So I delete 'iounmap(anatop_base);'
> in unregister_hws.
>
> Fixes: 24defbe194b6 ("clk: imx: add i.MX93 clk")
> Signed-off-by: Zhanhao Hu<[email protected]>
> Reviewed-by: Dongliang Mu<[email protected]>
Actually the clk driver should never fail, otherwise the system will not
boot. But anyway it is fine to include the changes:
Reviewed-by: Peng Fan <[email protected]>
On 23-04-26 14:25:52, Zhanhao Hu wrote:
> In function probe(), it returns directly without unregistered hws
> when error occurs.
>
> I fix this by adding 'goto unregister_hws;' on line 295 and
> line 310.
Hi Zhanhao,
I like your patch, but there are some things to improve in the commit
message.
Have a read here before rephrasing it:
https://docs.kernel.org/process/submitting-patches.html
Quoting the above doc:
"Describe your changes in imperative mood, e.g. "make xyzzy do frotz"
instead of "[This patch] makes xyzzy do frotz" or "[I] changed xyzzy to
do frotz", as if you are giving orders to the codebase to change its
behaviour."
>
> Besides, I use devm_kzalloc() instead of kzalloc() to automatically
> free the memory using devm_kfree() when error occurs.
So this should be rephrased like:
Use devm_kzalloc instead of kzalloc, to automatically free the memory...
>
> Similarly, I replace of_iomap() with devm_of_iomap() to automatically
> handle the unused ioremap region. So I delete 'iounmap(anatop_base);'
> in unregister_hws.
Same here. Make it imperative rather than mentioning what you're doing
in this patch.
With the commit rephrased in a new version, I'll be more than happy to
apply it.
>
> Fixes: 24defbe194b6 ("clk: imx: add i.MX93 clk")
> Signed-off-by: Zhanhao Hu <[email protected]>
> Reviewed-by: Dongliang Mu <[email protected]>
> ---
> This issue is found by static analysis and remains untested.
> ---
> drivers/clk/imx/clk-imx93.c | 15 ++++++++-------
> 1 file changed, 8 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/clk/imx/clk-imx93.c b/drivers/clk/imx/clk-imx93.c
> index 07b4a043e449..b6c7c2725906 100644
> --- a/drivers/clk/imx/clk-imx93.c
> +++ b/drivers/clk/imx/clk-imx93.c
> @@ -264,7 +264,7 @@ static int imx93_clocks_probe(struct platform_device *pdev)
> void __iomem *base, *anatop_base;
> int i, ret;
>
> - clk_hw_data = kzalloc(struct_size(clk_hw_data, hws,
> + clk_hw_data = devm_kzalloc(dev, struct_size(clk_hw_data, hws,
> IMX93_CLK_END), GFP_KERNEL);
> if (!clk_hw_data)
> return -ENOMEM;
> @@ -288,10 +288,12 @@ static int imx93_clocks_probe(struct platform_device *pdev)
> "sys_pll_pfd2", 1, 2);
>
> np = of_find_compatible_node(NULL, NULL, "fsl,imx93-anatop");
> - anatop_base = of_iomap(np, 0);
> + anatop_base = devm_of_iomap(dev, np, 0, NULL);
> of_node_put(np);
> - if (WARN_ON(!anatop_base))
> - return -ENOMEM;
> + if (WARN_ON(IS_ERR(anatop_base))) {
> + ret = PTR_ERR(base);
> + goto unregister_hws;
> + }
>
> clks[IMX93_CLK_ARM_PLL] = imx_clk_fracn_gppll_integer("arm_pll", "osc_24m",
> anatop_base + 0x1000,
> @@ -304,8 +306,8 @@ static int imx93_clocks_probe(struct platform_device *pdev)
> np = dev->of_node;
> base = devm_platform_ioremap_resource(pdev, 0);
> if (WARN_ON(IS_ERR(base))) {
> - iounmap(anatop_base);
> - return PTR_ERR(base);
> + ret = PTR_ERR(base);
> + goto unregister_hws;
> }
>
> for (i = 0; i < ARRAY_SIZE(root_array); i++) {
> @@ -345,7 +347,6 @@ static int imx93_clocks_probe(struct platform_device *pdev)
>
> unregister_hws:
> imx_unregister_hw_clocks(clks, IMX93_CLK_END);
> - iounmap(anatop_base);
>
> return ret;
> }
> --
> 2.34.1
>