clk: hisilicon: Use devm_kcalloc() instead of devm_kzalloc()
PATCH 1/1 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.
--- drivers/clk/hisilicon/clk-hi3559a.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/clk/hisilicon/clk-hi3559a.c +1 -2
@@ -461,8 +461,7 @@ static void hisi_clk_register_pll(struct hi3559av100_pll_clock *clks,struct clk_init_data init;int i; - p_clk =devm_kzalloc (dev,sizeof (*p_clk) * nums,GFP_KERNEL ); - + p_clk =devm_kcalloc (dev, nums,sizeof (*p_clk),GFP_KERNEL );if (!p_clk)return ;
--
2.25.1
Quoted 23 lines · Erick Archer
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 thedevm_kzalloc()function.Signed-off-by Erick Archer <[email protected]>--- drivers/clk/hisilicon/clk-hi3559a.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)drivers/clk/hisilicon/clk-hi3559a.c +0
-0
drivers/clk/hisilicon/clk-hi3559a.c static void hisi_clk_register_pll(struct hi3559av100_pll_clock *clks, · line 466
Quoted 8 lines
drivers/clk/hisilicon/clk-hi3559a.c +1
-2@@ -461,8 +461,7 @@ static void hisi_clk_register_pll(struct hi3559av100_pll_clock *clks,struct clk_init_data init;int i; - p_clk =devm_kzalloc (dev,sizeof (*p_clk) * nums,GFP_KERNEL ); - + p_clk =devm_kcalloc (dev, nums,sizeof (*p_clk),GFP_KERNEL );if (!p_clk)return ;
Looks good,
My first impulse was to ask why hisi_clk_register_pll doesn't return an error if the allocation fails, but I guess that happens so early that no sensible error handling is possible?
Best regards
Uwe
Signature · 2 lines
Pengutronix e.K. | Uwe Kleine-König | Industrial Linux Solutions | https://www.pengutronix.de/ |
Quoted 8 lines · Erick Archer
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.
Quoted 6 lines
So, use the purpose specific
devm_kcalloc()function instead of the argument size * count in thedevm_kzalloc()function.
Thanks!
Signature · 1 line
Gustavo
Quoted 22 lines
--- drivers/clk/hisilicon/clk-hi3559a.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)drivers/clk/hisilicon/clk-hi3559a.c +1
-3@@ -461,8 +461,7 @@ static void hisi_clk_register_pll(struct hi3559av100_pll_clock *clks,struct clk_init_data init;int i; - p_clk =devm_kzalloc (dev,sizeof (*p_clk) * nums,GFP_KERNEL ); - + p_clk =devm_kcalloc (dev, nums,sizeof (*p_clk),GFP_KERNEL );if (!p_clk)return ; --2.25.1
Quoting Erick Archer (2024-01-21 06:29:46)
Quoted 8 lines
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.
Quoted 7 lines
So, use the purpose specific
devm_kcalloc()function instead of the argument size * count in thedevm_kzalloc()function.Signed-off-by Erick Archer <[email protected]>---
Applied to clk-next