Skip to content

Commit 0da7fac

Browse files
andy-shevbebarino
authored andcommitted
clk: mmp: Switch to use kmemdup_array()
Let the kmemdup_array() take care about multiplication and possible overflows. Signed-off-by: Andy Shevchenko <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Stephen Boyd <[email protected]>
1 parent de7aeb5 commit 0da7fac

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

drivers/clk/mmp/clk-mix.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,6 @@ struct clk *mmp_clk_register_mix(struct device *dev,
447447
struct mmp_clk_mix *mix;
448448
struct clk *clk;
449449
struct clk_init_data init;
450-
size_t table_bytes;
451450

452451
mix = kzalloc(sizeof(*mix), GFP_KERNEL);
453452
if (!mix)
@@ -461,18 +460,17 @@ struct clk *mmp_clk_register_mix(struct device *dev,
461460

462461
memcpy(&mix->reg_info, &config->reg_info, sizeof(config->reg_info));
463462
if (config->table) {
464-
table_bytes = sizeof(*config->table) * config->table_size;
465-
mix->table = kmemdup(config->table, table_bytes, GFP_KERNEL);
463+
mix->table = kmemdup_array(config->table, config->table_size,
464+
sizeof(*mix->table), GFP_KERNEL);
466465
if (!mix->table)
467466
goto free_mix;
468467

469468
mix->table_size = config->table_size;
470469
}
471470

472471
if (config->mux_table) {
473-
table_bytes = sizeof(u32) * num_parents;
474-
mix->mux_table = kmemdup(config->mux_table, table_bytes,
475-
GFP_KERNEL);
472+
mix->mux_table = kmemdup_array(config->mux_table, num_parents,
473+
sizeof(*mix->mux_table), GFP_KERNEL);
476474
if (!mix->mux_table) {
477475
kfree(mix->table);
478476
goto free_mix;

0 commit comments

Comments
 (0)