clk: nuvoton: Manage MA35D1 mux clocks with the controller
Subsystems (2)
PATCH 1/1 clk: nuvoton: Manage MA35D1 mux clocks with the controller
The MA35D1 muxes remain registered after the platform device releases their register mapping. Use managed registration so both mux helpers unregister their clocks before the registers are unmapped.
This issue was found by our static analysis tool under development.
--- drivers/clk/nuvoton/clk-ma35d1.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
drivers/clk/nuvoton/clk-ma35d1.c +6 -6
@@ -380,9 +380,9 @@ static struct clk_hw *ma35d1_clk_mux_parent(struct device *dev, const char *nameconst struct clk_parent_data *pdata, int num_pdata) { - return clk_hw_register_mux_parent_data(dev, name, pdata, num_pdata, -CLK_SET_RATE_NO_REPARENT ,reg ,shift , - width, 0, &ma35d1_lock); + return devm_clk_hw_register_mux_parent_data_table(dev, name, pdata, num_pdata, +CLK_SET_RATE_NO_REPARENT ,reg ,shift , + width, 0, NULL, &ma35d1_lock); } static struct clk_hw *ma35d1_clk_mux(struct device *dev, const char *name,
@@ -390,9 +390,9 @@ static struct clk_hw *ma35d1_clk_mux(struct device *dev, const char *name,const struct clk_parent_data *pdata, int num_pdata) { - return clk_hw_register_mux_parent_data(dev, name, pdata, num_pdata, -CLK_SET_RATE_NO_REPARENT ,reg ,shift , - width, 0, &ma35d1_lock); + return devm_clk_hw_register_mux_parent_data_table(dev, name, pdata, num_pdata, +CLK_SET_RATE_NO_REPARENT ,reg ,shift , + width, 0, NULL, &ma35d1_lock); } static struct clk_hw *ma35d1_clk_divider(struct device *dev, const char *name,
base-commit: 4dce97c6c265544342e716e62fd24bbb232590c5
Signature · 1 line
2.43.0
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found no new issues in this patch, but noticed 1 related pre-existing issue it does not introduce: - [Critical] clk: nuvoton: use-after-free in…
Thank you for your contribution! Sashiko AI review found no new issues in this patch, but noticed 1 related pre-existing issue it does not introduce:
- [Critical] clk: nuvoton: use-after-free in ma35d1_clocks_probe() [1] --
commit 9ff45d0263efa96de1be9a7ff0a42ea74ccdf3fa
Author: Guangshuo Li <[email protected]>
clk: nuvoton: Manage MA35D1 mux clocks with the controller
This commit converts ma35d1_clk_mux_parent() and ma35d1_clk_mux() to use devm_clk_hw_register_mux_parent_data_table() so that the mux clocks are automatically unregistered when the platform device is removed.
Quoted 18 lines
drivers/clk/nuvoton/clk-ma35d1.c +3
-3@@ -380,9 +380,9 @@ static struct clk_hw *ma35d1_clk_mux_parent(struct device *dev, const char *nameconst struct clk_parent_data *pdata, int num_pdata) { - return clk_hw_register_mux_parent_data(dev, name, pdata, num_pdata, -CLK_SET_RATE_NO_REPARENT ,reg ,shift , - width, 0, &ma35d1_lock); + return devm_clk_hw_register_mux_parent_data_table(dev, name, pdata, num_pdata, +CLK_SET_RATE_NO_REPARENT ,reg ,shift , + width, 0, NULL, &ma35d1_lock); } static struct clk_hw *ma35d1_clk_mux(struct device *dev, const char *name,
drivers/clk/nuvoton/clk-ma35d1.c static struct clk_hw *ma35d1_clk_mux(struct device *dev, const char *name, · line 396
Quoted 10 lines
drivers/clk/nuvoton/clk-ma35d1.c +3
-3@@ -390,9 +390,9 @@ static struct clk_hw *ma35d1_clk_mux(struct device *dev, const char *name,const struct clk_parent_data *pdata, int num_pdata) { - return clk_hw_register_mux_parent_data(dev, name, pdata, num_pdata, -CLK_SET_RATE_NO_REPARENT ,reg ,shift , - width, 0, &ma35d1_lock); + return devm_clk_hw_register_mux_parent_data_table(dev, name, pdata, num_pdata, +CLK_SET_RATE_NO_REPARENT ,reg ,shift , + width, 0, NULL, &ma35d1_lock); }
[Severity: Critical]
This problem wasn't introduced by this patch, but right above ma35d1_clk_mux_parent(), doesn't ma35d1_clk_fixed() also leave its clocks registered on probe failure or driver unbind [1]?
drivers/clk/nuvoton/clk-ma35d1.c:ma35d1_clk_fixed() {
return clk_hw_register_fixed_rate(NULL, name, NULL, 0, rate);
}Because ma35d1_clk_fixed() uses the unmanaged clk_hw_register_fixed_rate() helper instead of devm_clk_hw_register_fixed_rate(), the fixed-rate clocks remain registered in the clock framework and leak after ma35d1_clocks_probe() fails or the device is unbound.
[1] https://sashiko.dev/#/bug/linux-0fffc72d-3bbf-4403-b81b-eac9ff603015
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Quoted 8 lines
The MA35D1 muxes remain registered after the platform device releases their register mapping. Use managed registration so both mux helpers unregister their clocks before the registers are unmapped.
This issue was found by our static analysis tool under development.
Fixes 691521a367cf ("clk: nuvoton: Add clock driver for ma35d1 clock controller")Signed-off-by Guangshuo Li <[email protected]>
This does not apply on top Miquel's work, see clk-nuvoton branch. If the problem is still present, please rebase re-submit.
Signature · 1 line
Jerome