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

clk: rockchip: Switch to use kmemdup_array()

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

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Link: https://lore.kernel.org/r/20240606161028.2986587-3-andriy.shevchenko@linux.intel.com
Signed-off-by: Heiko Stuebner <heiko@sntech.de>

authored by

Andy Shevchenko and committed by
Heiko Stuebner
fc547ab0 5c0e997e

+6 -7
+2 -3
drivers/clk/rockchip/clk-cpu.c
··· 369 369 370 370 if (nrates > 0) { 371 371 cpuclk->rate_count = nrates; 372 - cpuclk->rate_table = kmemdup(rates, 373 - sizeof(*rates) * nrates, 374 - GFP_KERNEL); 372 + cpuclk->rate_table = kmemdup_array(rates, nrates, sizeof(*rates), 373 + GFP_KERNEL); 375 374 if (!cpuclk->rate_table) { 376 375 ret = -ENOMEM; 377 376 goto unregister_notifier;
+4 -4
drivers/clk/rockchip/clk-pll.c
··· 1136 1136 len++; 1137 1137 1138 1138 pll->rate_count = len; 1139 - pll->rate_table = kmemdup(rate_table, 1140 - pll->rate_count * 1141 - sizeof(struct rockchip_pll_rate_table), 1142 - GFP_KERNEL); 1139 + pll->rate_table = kmemdup_array(rate_table, 1140 + pll->rate_count, 1141 + sizeof(*pll->rate_table), 1142 + GFP_KERNEL); 1143 1143 WARN(!pll->rate_table, 1144 1144 "%s: could not allocate rate table for %s\n", 1145 1145 __func__, name);