Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

clk: mmp: Switch to use kmemdup_array()

Let the kmemdup_array() take care about multiplication and possible
overflows.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Link: https://lore.kernel.org/r/20240814125513.2637955-2-andriy.shevchenko@linux.intel.com
Signed-off-by: Stephen Boyd <sboyd@kernel.org>

authored by

Andy Shevchenko and committed by
Stephen Boyd
0da7faca de7aeb5d

+4 -6
+4 -6
drivers/clk/mmp/clk-mix.c
··· 447 447 struct mmp_clk_mix *mix; 448 448 struct clk *clk; 449 449 struct clk_init_data init; 450 - size_t table_bytes; 451 450 452 451 mix = kzalloc(sizeof(*mix), GFP_KERNEL); 453 452 if (!mix) ··· 460 461 461 462 memcpy(&mix->reg_info, &config->reg_info, sizeof(config->reg_info)); 462 463 if (config->table) { 463 - table_bytes = sizeof(*config->table) * config->table_size; 464 - mix->table = kmemdup(config->table, table_bytes, GFP_KERNEL); 464 + mix->table = kmemdup_array(config->table, config->table_size, 465 + sizeof(*mix->table), GFP_KERNEL); 465 466 if (!mix->table) 466 467 goto free_mix; 467 468 ··· 469 470 } 470 471 471 472 if (config->mux_table) { 472 - table_bytes = sizeof(u32) * num_parents; 473 - mix->mux_table = kmemdup(config->mux_table, table_bytes, 474 - GFP_KERNEL); 473 + mix->mux_table = kmemdup_array(config->mux_table, num_parents, 474 + sizeof(*mix->mux_table), GFP_KERNEL); 475 475 if (!mix->mux_table) { 476 476 kfree(mix->table); 477 477 goto free_mix;