Skip to content

Commit 252c31a

Browse files
Erick Archerbebarino
authored andcommitted
clk: hisilicon: Use devm_kcalloc() instead of devm_kzalloc()
As noted in the "Deprecated Interfaces, Language Features, Attributes, and Conventions" documentation [1], size calculations (especially multiplication) should not be performed in memory allocator (or similar) function arguments due to the risk of them overflowing. This could lead to values wrapping around and a smaller allocation being made than the caller was expecting. Using those allocations could lead to linear overflows of heap memory and other misbehaviors. So, use the purpose specific devm_kcalloc() function instead of the argument size * count in the devm_kzalloc() function. Link: https://www.kernel.org/doc/html/next/process/deprecated.html#open-coded-arithmetic-in-allocator-arguments [1] Link: KSPP#162 Signed-off-by: Erick Archer <[email protected]> Link: https://lore.kernel.org/r/[email protected] Reviewed-by: Uwe Kleine-König <[email protected]> Reviewed-by: Gustavo A. R. Silva <[email protected]> Signed-off-by: Stephen Boyd <[email protected]>
1 parent 64c6a38 commit 252c31a

File tree

1 file changed

+1
-2
lines changed

1 file changed

+1
-2
lines changed

drivers/clk/hisilicon/clk-hi3559a.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -461,8 +461,7 @@ static void hisi_clk_register_pll(struct hi3559av100_pll_clock *clks,
461461
struct clk_init_data init;
462462
int i;
463463

464-
p_clk = devm_kzalloc(dev, sizeof(*p_clk) * nums, GFP_KERNEL);
465-
464+
p_clk = devm_kcalloc(dev, nums, sizeof(*p_clk), GFP_KERNEL);
466465
if (!p_clk)
467466
return;
468467

0 commit comments

Comments
 (0)