* [PATCH v3 0/2] clk: clk-loongson2: Fix two small issues
@ 2025-01-14 13:00 Binbin Zhou
2025-01-14 13:00 ` [PATCH v3 1/2] clk: clk-loongson2: Switch to use devm_clk_hw_register_fixed_rate_parent_data() Binbin Zhou
2025-01-14 13:00 ` [PATCH v3 2/2] clk: clk-loongson2: Fix the number count of clk provider Binbin Zhou
0 siblings, 2 replies; 5+ messages in thread
From: Binbin Zhou @ 2025-01-14 13:00 UTC (permalink / raw)
To: Binbin Zhou, Huacai Chen, Michael Turquette, Stephen Boyd,
Yinbo Zhu
Cc: Huacai Chen, linux-clk, Xuerui Wang, loongarch, Binbin Zhou
V3:
patch(2/2):
- Correct the array of pointers address;
- Collect both patches together.
Link to V2:
https://lore.kernel.org/all/20250109113004.2473331-1-zhoubinbin@loongson.cn
https://lore.kernel.org/all/20241225060600.3094154-2-zhoubinbin@loongson.cn
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/20241225060600.3094154-1-zhoubinbin@loongson.cn/
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
--
2.43.5
^ permalink raw reply [flat|nested] 5+ messages in thread* [PATCH v3 1/2] clk: clk-loongson2: Switch to use devm_clk_hw_register_fixed_rate_parent_data() 2025-01-14 13:00 [PATCH v3 0/2] clk: clk-loongson2: Fix two small issues Binbin Zhou @ 2025-01-14 13:00 ` Binbin Zhou 2025-01-14 19:14 ` Stephen Boyd 2025-01-14 13:00 ` [PATCH v3 2/2] clk: clk-loongson2: Fix the number count of clk provider Binbin Zhou 1 sibling, 1 reply; 5+ messages in thread From: Binbin Zhou @ 2025-01-14 13:00 UTC (permalink / raw) To: Binbin Zhou, Huacai Chen, Michael Turquette, Stephen Boyd, Yinbo Zhu Cc: Huacai Chen, linux-clk, Xuerui Wang, loongarch, Binbin Zhou 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. Signed-off-by: Binbin Zhou <zhoubinbin@loongson.cn> --- drivers/clk/clk-loongson2.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/clk/clk-loongson2.c b/drivers/clk/clk-loongson2.c index 7082b4309c6f..6bf51d5a49a1 100644 --- a/drivers/clk/clk-loongson2.c +++ b/drivers/clk/clk-loongson2.c @@ -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"); -- 2.43.5 ^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH v3 1/2] clk: clk-loongson2: Switch to use devm_clk_hw_register_fixed_rate_parent_data() 2025-01-14 13:00 ` [PATCH v3 1/2] clk: clk-loongson2: Switch to use devm_clk_hw_register_fixed_rate_parent_data() Binbin Zhou @ 2025-01-14 19:14 ` Stephen Boyd 0 siblings, 0 replies; 5+ messages in thread From: Stephen Boyd @ 2025-01-14 19:14 UTC (permalink / raw) To: Binbin Zhou, Binbin Zhou, Huacai Chen, Michael Turquette, Yinbo Zhu Cc: Huacai Chen, linux-clk, Xuerui Wang, loongarch, Binbin Zhou Quoting Binbin Zhou (2025-01-14 05:00:28) > 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. > > Signed-off-by: Binbin Zhou <zhoubinbin@loongson.cn> > --- Applied to clk-next ^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v3 2/2] clk: clk-loongson2: Fix the number count of clk provider 2025-01-14 13:00 [PATCH v3 0/2] clk: clk-loongson2: Fix two small issues Binbin Zhou 2025-01-14 13:00 ` [PATCH v3 1/2] clk: clk-loongson2: Switch to use devm_clk_hw_register_fixed_rate_parent_data() Binbin Zhou @ 2025-01-14 13:00 ` Binbin Zhou 2025-01-14 19:14 ` Stephen Boyd 1 sibling, 1 reply; 5+ messages in thread From: Binbin Zhou @ 2025-01-14 13:00 UTC (permalink / raw) To: Binbin Zhou, Huacai Chen, Michael Turquette, Stephen Boyd, Yinbo Zhu Cc: Huacai Chen, linux-clk, Xuerui Wang, loongarch, Binbin Zhou, stable, Gustavo A . R . Silva 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_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 Cc: stable@vger.kernel.org Cc: Gustavo A. R. Silva <gustavoars@kernel.org> Fixes: 02fb4f008433 ("clk: clk-loongson2: Fix potential buffer overflow in flexible-array member access") Signed-off-by: Binbin Zhou <zhoubinbin@loongson.cn> --- drivers/clk/clk-loongson2.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/clk/clk-loongson2.c b/drivers/clk/clk-loongson2.c index 6bf51d5a49a1..27e632edd484 100644 --- a/drivers/clk/clk-loongson2.c +++ b/drivers/clk/clk-loongson2.c @@ -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) { -- 2.43.5 ^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH v3 2/2] clk: clk-loongson2: Fix the number count of clk provider 2025-01-14 13:00 ` [PATCH v3 2/2] clk: clk-loongson2: Fix the number count of clk provider Binbin Zhou @ 2025-01-14 19:14 ` Stephen Boyd 0 siblings, 0 replies; 5+ messages in thread From: Stephen Boyd @ 2025-01-14 19:14 UTC (permalink / raw) To: Binbin Zhou, Binbin Zhou, Huacai Chen, Michael Turquette, Yinbo Zhu Cc: Huacai Chen, linux-clk, Xuerui Wang, loongarch, Binbin Zhou, stable, Gustavo A . R . Silva Quoting Binbin Zhou (2025-01-14 05:00:29) > 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_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 > > Cc: stable@vger.kernel.org > Cc: Gustavo A. R. Silva <gustavoars@kernel.org> > Fixes: 02fb4f008433 ("clk: clk-loongson2: Fix potential buffer overflow in flexible-array member access") > Signed-off-by: Binbin Zhou <zhoubinbin@loongson.cn> > --- Applied to clk-fixes ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2025-01-14 19:14 UTC | newest] Thread overview: 5+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2025-01-14 13:00 [PATCH v3 0/2] clk: clk-loongson2: Fix two small issues Binbin Zhou 2025-01-14 13:00 ` [PATCH v3 1/2] clk: clk-loongson2: Switch to use devm_clk_hw_register_fixed_rate_parent_data() Binbin Zhou 2025-01-14 19:14 ` Stephen Boyd 2025-01-14 13:00 ` [PATCH v3 2/2] clk: clk-loongson2: Fix the number count of clk provider Binbin Zhou 2025-01-14 19:14 ` Stephen Boyd
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).