clk: Switch to use kmemdup_array()
Subsystems (5)
cover clk: Switch to use kmemdup_array()
Replace open coded kmemdup_array(), which does an additional overflow check.
Andy Shevchenko (4):
clk: mmp: Switch to use kmemdup_array()
clk: rockchip: Switch to use kmemdup_array()
clk: samsung: Switch to use kmemdup_array()
clk: visconti: Switch to use kmemdup_array()
drivers/clk/mmp/clk-mix.c | 10 ++++------ drivers/clk/rockchip/clk-cpu.c | 5 ++--- drivers/clk/rockchip/clk-pll.c | 8 ++++---- drivers/clk/samsung/clk-cpu.c | 4 ++-- drivers/clk/samsung/clk-pll.c | 8 ++++---- drivers/clk/visconti/pll.c | 6 +++--- 6 files changed, 19 insertions(+), 22 deletions(-)
Signature · 1 line
2.43.0.rc1.1336.g36b5255a03ac
PATCH 1/4 clk: mmp: Switch to use kmemdup_array()
Let the kememdup_array() take care about multiplication and possible overflows.
--- drivers/clk/mmp/clk-mix.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-)
drivers/clk/mmp/clk-mix.c +4 -6
@@ -447,7 +447,6 @@ struct clk *mmp_clk_register_mix(struct device *dev,struct mmp_clk_mix *mix;struct clk *clk;struct clk_init_data init; -size_t table_bytes; mix =kzalloc (sizeof (*mix),GFP_KERNEL );if (!mix)
@@ -461,8 +460,8 @@ struct clk *mmp_clk_register_mix(struct device *dev,memcpy (&mix->reg_info, &config->reg_info,sizeof (config->reg_info));if (config->table) { - table_bytes =sizeof (*config->table) * config->table_size; - mix->table =kmemdup (config->table, table_bytes,GFP_KERNEL ); + mix->table =kmemdup_array (config->table, config->table_size, +sizeof (*mix->table),GFP_KERNEL );if (!mix->table) goto free_mix;
@@ -470,9 +469,8 @@ struct clk *mmp_clk_register_mix(struct device *dev, }if (config->mux_table) { - table_bytes =sizeof (u32) * num_parents; - mix->mux_table =kmemdup (config->mux_table, table_bytes, -GFP_KERNEL ); + mix->mux_table =kmemdup_array (config->mux_table, num_parents, +sizeof (*mix->mux_table),GFP_KERNEL );if (!mix->mux_table) {kfree (mix->table); goto free_mix;
Signature · 1 line
2.43.0.rc1.1336.g36b5255a03ac
PATCH 2/4 clk: rockchip: Switch to use kmemdup_array()
In reply to Andy ShevchenkoLet the kememdup_array() take care about multiplication and possible overflows.
--- drivers/clk/rockchip/clk-cpu.c | 5 ++--- drivers/clk/rockchip/clk-pll.c | 8 ++++---- 2 files changed, 6 insertions(+), 7 deletions(-)
drivers/clk/rockchip/clk-cpu.c +2 -3
@@ -369,9 +369,8 @@ struct clk *rockchip_clk_register_cpuclk(const char *name,if (nrates >0 ) { cpuclk->rate_count = nrates; - cpuclk->rate_table =kmemdup (rates, -sizeof (*rates) * nrates, -GFP_KERNEL ); + cpuclk->rate_table =kmemdup_array (rates, nrates,sizeof (*rates), +GFP_KERNEL );if (!cpuclk->rate_table) { ret = -ENOMEM ; goto unregister_notifier;
drivers/clk/rockchip/clk-pll.c +4 -4
@@ -1136,10 +1136,10 @@ struct clk *rockchip_clk_register_pll(struct rockchip_clk_provider *ctx, len++; pll->rate_count = len; - pll->rate_table =kmemdup (rate_table, - pll->rate_count * -sizeof (struct rockchip_pll_rate_table ), -GFP_KERNEL ); + pll->rate_table =kmemdup_array (rate_table, + pll->rate_count, +sizeof (*pll->rate_table), +GFP_KERNEL );WARN (!pll->rate_table,"%s: could not allocate rate table for %s\n" , __func__, name);
Signature · 1 line
2.43.0.rc1.1336.g36b5255a03ac
Heiko Stübner
maintainerRe: [PATCH v1 2/4] clk: rockchip: Switch to use kmemdup_array()
Hi Andy,
Am Donnerstag, 6. Juni 2024, 18:09:32 CEST schrieb Andy Shevchenko:
Quoted 14 lines
Let the
kememdup_array()take care about multiplication and possible overflows.Signed-off-by Andy Shevchenko <[email protected]>--- drivers/clk/rockchip/clk-cpu.c | 5 ++--- drivers/clk/rockchip/clk-pll.c | 8 ++++---- 2 files changed, 6 insertions(+), 7 deletions(-)drivers/clk/rockchip/clk-cpu.c +0
-0
drivers/clk/rockchip/clk-cpu.c struct clk *rockchip_clk_register_cpuclk(const char *name, · line 373
Quoted 8 lines
drivers/clk/rockchip/clk-cpu.c +2
-3@@ -369,9 +369,8 @@ struct clk *rockchip_clk_register_cpuclk(const char *name,if (nrates >0 ) { cpuclk->rate_count = nrates; - cpuclk->rate_table =kmemdup (rates, -sizeof (*rates) * nrates, -GFP_KERNEL ); + cpuclk->rate_table =kmemdup_array (rates, nrates,sizeof (*rates), +GFP_KERNEL );
are you sure the param order is correct?
According to [0], it's (src, element_size, count, gfp), while above (and below) element_size and count seems switched in the kmemdup_array calls.
Heiko
[0] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/mm/util.c#n149
Quoted 23 lines
drivers/clk/rockchip/clk-cpu.c +0
-0if (!cpuclk->rate_table) { ret = -ENOMEM ; goto unregister_notifier;drivers/clk/rockchip/clk-pll.c +4
-4@@ -1136,10 +1136,10 @@ struct clk *rockchip_clk_register_pll(struct rockchip_clk_provider *ctx, len++; pll->rate_count = len; - pll->rate_table =kmemdup (rate_table, - pll->rate_count * -sizeof (struct rockchip_pll_rate_table ), -GFP_KERNEL ); + pll->rate_table =kmemdup_array (rate_table, + pll->rate_count, +sizeof (*pll->rate_table), +GFP_KERNEL );WARN (!pll->rate_table,"%s: could not allocate rate table for %s\n" , __func__, name);
Re: [PATCH v1 2/4] clk: rockchip: Switch to use kmemdup_array()
Quoted 1 line · Heiko Stübner
Am Donnerstag, 6. Juni 2024, 18:09:32 CEST schrieb Andy Shevchenko:
...
Quoted 11 lines
drivers/clk/rockchip/clk-cpu.c struct clk *rockchip_clk_register_cpuclk(const char *name, · line 373
Quoted 5 lines
drivers/clk/rockchip/clk-cpu.c +2
-3- cpuclk->rate_table =kmemdup (rates, -sizeof (*rates) * nrates, -GFP_KERNEL ); + cpuclk->rate_table =kmemdup_array (rates, nrates,sizeof (*rates), +GFP_KERNEL );are you sure the param order is correct?
According to [0], it's (src,
element_size, count, gfp), while above (and below)element_sizeand count seems switched in thekmemdup_arraycalls.
I'm glad you asked. The parameter order is going to be fixed [1].
Quoted 1 line
[0] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/mm/util.c#n149
[1]: 0ee14725471c ("mm/util: Swap kmemdup_array() arguments")
Signature · 2 lines
With Best Regards, Andy Shevchenko
Heiko Stuebner
maintainerRe: [PATCH v1 2/4] clk: rockchip: Switch to use kmemdup_array()
Am Dienstag, 11. Juni 2024, 15:20:05 CEST schrieb Andy Shevchenko:
Quoted 17 lines · Heiko Stübner
Quoted 1 line
Am Donnerstag, 6. Juni 2024, 18:09:32 CEST schrieb Andy Shevchenko:
...
Quoted 11 lines
drivers/clk/rockchip/clk-cpu.c struct clk *rockchip_clk_register_cpuclk(const char *name, · line 373
Quoted 5 lines
drivers/clk/rockchip/clk-cpu.c +2
-3- cpuclk->rate_table =kmemdup (rates, -sizeof (*rates) * nrates, -GFP_KERNEL ); + cpuclk->rate_table =kmemdup_array (rates, nrates,sizeof (*rates), +GFP_KERNEL );are you sure the param order is correct?
According to [0], it's (src,
element_size, count, gfp), while above (and below)element_sizeand count seems switched in thekmemdup_arraycalls.
Quoted 5 lines
I'm glad you asked. The parameter order is going to be fixed [1].
Quoted 1 line
[0] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/mm/util.c#n149
[1]:
0ee14725471c("mm/util: Swapkmemdup_array()arguments")
ah that clears it up :-)
Thanks for the pointer
Heiko
PATCH 3/4 clk: samsung: Switch to use kmemdup_array()
In reply to Andy ShevchenkoLet the kememdup_array() take care about multiplication and possible overflows.
--- drivers/clk/samsung/clk-cpu.c | 4 ++-- drivers/clk/samsung/clk-pll.c | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-)
drivers/clk/samsung/clk-cpu.c +2 -2
@@ -689,8 +689,8 @@ static int __init exynos_register_cpu_clock(struct samsung_clk_provider *ctx,for (num_cfgs =0 ; clk_data->cfg[num_cfgs].prate !=0 ; ) num_cfgs++; - cpuclk->cfg =kmemdup (clk_data->cfg,sizeof (*clk_data->cfg) * num_cfgs, -GFP_KERNEL ); + cpuclk->cfg =kmemdup_array (clk_data->cfg, num_cfgs,sizeof (*cpuclk->cfg), +GFP_KERNEL );if (!cpuclk->cfg) { ret = -ENOMEM ; goto unregister_clk_nb;
drivers/clk/samsung/clk-pll.c +4 -4
@@ -1286,10 +1286,10 @@ static void __init _samsung_clk_register_pll(struct samsung_clk_provider *ctx, len++; pll->rate_count = len; - pll->rate_table =kmemdup (pll_clk->rate_table, - pll->rate_count * -sizeof (struct samsung_pll_rate_table ), -GFP_KERNEL ); + pll->rate_table =kmemdup_array (pll_clk->rate_table, + pll->rate_count, +sizeof (*pll->rate_table), +GFP_KERNEL );WARN (!pll->rate_table,"%s: could not allocate rate table for %s\n" , __func__, pll_clk->name);
Signature · 1 line
2.43.0.rc1.1336.g36b5255a03ac
Krzysztof Kozlowski
AppliedRe: (subset) [PATCH v1 3/4] clk: samsung: Switch to use kmemdup_array()
Quoted 4 lines · Andy Shevchenko
Let the
kememdup_array()take care about multiplication and possible overflows.
Applied, thanks!
[3/4] clk: samsung: Switch to use kmemdup_array()
https://git.kernel.org/krzk/linux/c/7666718892f2a8582127f584fdbf5dada59af2d8
Best regards,
Signature · 1 line
Krzysztof Kozlowski <[email protected]>
PATCH 4/4 clk: visconti: Switch to use kmemdup_array()
In reply to Andy ShevchenkoLet the kememdup_array() take care about multiplication and possible overflows.
--- drivers/clk/visconti/pll.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/clk/visconti/pll.c +3 -3
@@ -262,9 +262,9 @@ static struct clk_hw *visconti_register_pll(struct visconti_pll_provider *ctx,for (len =0 ; rate_table[len].rate !=0 ; ) len++; pll->rate_count = len; - pll->rate_table =kmemdup (rate_table, - pll->rate_count *sizeof (struct visconti_pll_rate_table ), -GFP_KERNEL ); + pll->rate_table =kmemdup_array (rate_table, + pll->rate_count,sizeof (*pll->rate_table), +GFP_KERNEL );WARN (!pll->rate_table,"%s: could not allocate rate table for %s\n" , __func__, name); init.ops = &visconti_pll_ops;
Signature · 1 line
2.43.0.rc1.1336.g36b5255a03ac
Re: (subset) [PATCH v1 0/4] clk: Switch to use kmemdup_array()
In reply to Andy ShevchenkoQuoted 10 lines · Andy Shevchenko
Replace open coded
kmemdup_array(), which does an additional overflow check.Andy Shevchenko (4):
clk: mmp: Switch to usekmemdup_array()
clk: rockchip: Switch to usekmemdup_array()
clk: samsung: Switch to usekmemdup_array()
clk: visconti: Switch to usekmemdup_array()[...]
Applied, thanks!
[2/4] clk: rockchip: Switch to use kmemdup_array()
commit: c9ba07b0c02acd89f2e521754357de30e704c254
Best regards,
Signature · 1 line
Heiko Stuebner <[email protected]>
Quoted 2 lines · Andy Shevchenko
Replace open coded
kmemdup_array(), which does an additional overflow check.
...
Quoted 3 lines
clk: mmp: Switch to use
kmemdup_array()clk: visconti: Switch to use
kmemdup_array()
Any news for these two?
Signature · 2 lines
With Best Regards, Andy Shevchenko
Stephen Boyd
maintainerQuoting Andy Shevchenko (2024-08-13 01:37:48)
Quoted 9 lines · Andy Shevchenko
Quoted 2 lines
Replace open coded
kmemdup_array(), which does an additional overflow check....
Quoted 3 lines
clk: mmp: Switch to use
kmemdup_array()clk: visconti: Switch to use
kmemdup_array()
I have them all as "changes requested" so please resend.
Quoted 2 lines · Stephen Boyd
Quoting Andy Shevchenko (2024-08-13 01:37:48)
Quoted 1 line · Andy Shevchenko
...
Quoted 5 lines
Quoted 3 lines
Quoted 3 lines
clk: mmp: Switch to use
kmemdup_array()clk: visconti: Switch to use
kmemdup_array()I have them all as "changes requested" so please resend.
Done (Message-Id: [email protected]).
Signature · 2 lines
With Best Regards, Andy Shevchenko