clk: Switch to use kmemdup_array()
Subsystems (2)
v2 cover clk: Switch to use kmemdup_array()
Replace open coded kmemdup_array(), which does an additional overflow check.
v2:
- dropped upstreamed changes
- fixed a typo in the commit messages
Andy Shevchenko (2):
clk: mmp: Switch to use kmemdup_array()
clk: visconti: Switch to use kmemdup_array()
drivers/clk/mmp/clk-mix.c | 10 ++++------ drivers/clk/visconti/pll.c | 6 +++--- 2 files changed, 7 insertions(+), 9 deletions(-)
Signature · 1 line
2.43.0.rc1.1336.g36b5255a03ac
PATCH v2 1/2 clk: mmp: Switch to use kmemdup_array()
Let the kmemdup_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
Re: [PATCH v2 1/2] clk: mmp: Switch to use kmemdup_array()
Quoting Andy Shevchenko (2024-08-14 05:54:07)
Quoted 5 lines
Let the
kmemdup_array()take care about multiplication and possible overflows.Signed-off-by Andy Shevchenko <[email protected]>---
Applied to clk-next
PATCH v2 2/2 clk: visconti: Switch to use kmemdup_array()
In reply to Andy ShevchenkoLet the kmemdup_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: [PATCH v2 2/2] clk: visconti: Switch to use kmemdup_array()
Quoting Andy Shevchenko (2024-08-14 05:54:08)
Quoted 5 lines
Let the
kmemdup_array()take care about multiplication and possible overflows.Signed-off-by Andy Shevchenko <[email protected]>---
Applied to clk-next