clk: clk-loongson2: Fix two small issues
Subsystems (4)
v3 cover clk: clk-loongson2: Fix two small issues
V3:
patch(2/2):
- Correct the array of pointers address;
- Collect both patches together.
Link to V2:
https://lore.kernel.org/all/[email protected]
https://lore.kernel.org/all/[email protected]
V2:
patch(2/2):
- Add Gustavo A. R. Silva to cc list;
- Populate the onecell data with -ENOENT error pointers to avoid returning NULL, for it is a valid clock.
Link to V1:
https://lore.kernel.org/all/[email protected]/
Binbin Zhou (2):
clk: clk-loongson2: Switch to use
devm_clk_hw_register_fixed_rate_parent_data()
clk: clk-loongson2: Fix the number count of clk provider
drivers/clk/clk-loongson2.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
base-commit: 590a094e7bd2e5a10c392f13cd86489e1eb3ac86
Signature · 1 line
2.43.5
PATCH v3 1/2 clk: clk-loongson2: Switch to use devm_clk_hw_register_fixed_rate_parent_data()
Since commit 706ae6446494 ("clk: fixed-rate: add devm_clk_hw_register_fixed_rate_parent_data()"), we can use the devm_clk_hw_register_fixed_rate_parent_data() helper and from then on there is no need to manually unregister the fixed rate hw.
Since clk_hw_unregister_fixed_rate() was not called before, we also fix the memory leak that was present.
--- drivers/clk/clk-loongson2.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/clk/clk-loongson2.c +2 -2
@@ -335,8 +335,8 @@ static int loongson2_clk_probe(struct platform_device *pdev) &clp->clk_lock);break ;case CLK_TYPE_FIXED : - hw =clk_hw_register_fixed_rate_parent_data (dev, p->name, pdata, -0 , p->fixed_rate); + hw =devm_clk_hw_register_fixed_rate_parent_data (dev, p->name, pdata, +0 , p->fixed_rate);break ;default :return dev_err_probe (dev, -EINVAL ,"Invalid clk type\n" );
Signature · 1 line
2.43.5
Re: [PATCH v3 1/2] clk: clk-loongson2: Switch to use devm_clk_hw_register_fixed_rate_parent_data()
Quoting Binbin Zhou (2025-01-14 05:00:28)
Quoted 10 lines
Since commit
706ae6446494("clk: fixed-rate: adddevm_clk_hw_register_fixed_rate_parent_data()"), we can use thedevm_clk_hw_register_fixed_rate_parent_data()helper and from then on there is no need to manually unregister the fixed rate hw.Since
clk_hw_unregister_fixed_rate()was not called before, we also fix the memory leak that was present.Signed-off-by Binbin Zhou <[email protected]>---
Applied to clk-next
PATCH v3 2/2 clk: clk-loongson2: Fix the number count of clk provider
In reply to Binbin ZhouSince commit 02fb4f008433 ("clk: clk-loongson2: Fix potential buffer overflow in flexible-array member access"), the clk provider register is failed.
The count of clks_num is shown below:
for (p = data; p->name; p++) clks_num++;
In fact, clks_num represents the number of SoC clocks and should be expressed as the maximum value of the clock binding id in use (p->id + 1).
Now we fix it to avoid the following error when trying to register a clk provider:
[ 13.409595] of_clk_hw_onecell_get: invalid index 17
--- drivers/clk/clk-loongson2.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/clk/clk-loongson2.c +4 -1
@@ -294,7 +294,7 @@ static int loongson2_clk_probe(struct platform_device *pdev)return -EINVAL ;for (p = data; p->name; p++) - clks_num++; + clks_num =max (clks_num, p->id +1 ); clp =devm_kzalloc (dev,struct_size (clp, clk_data.hws, clks_num),GFP_KERNEL );
@@ -309,6 +309,9 @@ static int loongson2_clk_probe(struct platform_device *pdev) clp->clk_data.num = clks_num; clp->dev = dev; +/* Avoid returning NULL for unused id */ +memset_p ((void **)clp->clk_data.hws,ERR_PTR (-ENOENT ), clks_num); +for (i =0 ; i < clks_num; i++) { p = &data[i];switch (p->type) {
Signature · 1 line
2.43.5
Re: [PATCH v3 2/2] clk: clk-loongson2: Fix the number count of clk provider
Quoting Binbin Zhou (2025-01-14 05:00:29)
Quoted 15 lines
Since commit
02fb4f008433("clk: clk-loongson2: Fix potential buffer overflow in flexible-array member access"), the clk provider register is failed.The count of
clks_numis shown below:for (p = data; p->name; p++) clks_num++;In fact,
clks_numrepresents the number of SoC clocks and should be expressed as the maximum value of the clock binding id in use (p->id+ 1).Now we fix it to avoid the following error when trying to register a clk provider:
Quoted 7 lines
[ 13.409595] of_clk_hw_onecell_get: invalid index 17Cc Gustavo A. R. Silva <[email protected]>Fixes 02fb4f008433 ("clk: clk-loongson2: Fix potential buffer overflow in flexible-array member access")Signed-off-by Binbin Zhou <[email protected]>---
Applied to clk-fixes