clk: hisilicon: Fix of_iomap leak in hisi_clk_init
Subsystems (2)
PATCH 1/1 clk: hisilicon: Fix of_iomap leak in hisi_clk_init
Smatch reports:
drivers/clk/hisilicon/clk.c:87 hisi_clk_init() warn: 'base' from of_iomap() not released on lines: 87.
This is because in hisi_clk_init(), base is not released when handle error, which may cause a leak.
To fix this, iounmap is added when handle error.
--- drivers/clk/hisilicon/clk.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/clk/hisilicon/clk.c +2 -0
@@ -84,6 +84,8 @@ struct hisi_clock_data *hisi_clk_init(struct device_node *np, err_data:kfree (clk_data); err: +if (base) +iounmap (base);return NULL ; }EXPORT_SYMBOL_GPL (hisi_clk_init);
Signature · 1 line
2.20.1
Quoted 4 lines
Smatch reports:
drivers/clk/hisilicon/clk.c:87hisi_clk_init()warn: 'base' fromof_iomap()not released on lines: 87.
How do you think about to add any tags (like “Fixes” and “Cc”) accordingly?
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?h=v6.16#n145
…
Quoted 1 line
To fix this, iounmap is added when handle error.
See also once more:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?h=v6.16#n94
…
drivers/clk/hisilicon/clk.c struct hisi_clock_data *hisi_clk_init(struct device_node *np, · line 90
Quoted 9 lines
+++
b/drivers/clk/hisilicon/clk.cdrivers/clk/hisilicon/clk.c +2
-0@@ -84,6 +84,8 @@ struct hisi_clock_data *hisi_clk_init(struct device_node *np, err_data:kfree (clk_data); err: +if (base) +iounmap (base);return NULL ; }
…
* Please return directly after a failed of_iomap() call.
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/coding-style.rst?h=v6.16#n532
* Would it be nicer to use the label “unmap_io”?
* May the statement “clk_data->base = base;” be performed a bit later?
* How do you think about to replace an of_clk_add_provider() call by of_clk_add_hw_provider()?
https://elixir.bootlin.com/linux/v6.16/source/drivers/clk/clk.c#L4996-L5001
Regards,
Markus