* [PATCH] net: hns3: use kcalloc() instead of kzalloc()
@ 2025-08-25 14:27 Qianfeng Rong
2025-08-26 1:09 ` Jijie Shao
2025-08-27 0:20 ` patchwork-bot+netdevbpf
0 siblings, 2 replies; 3+ messages in thread
From: Qianfeng Rong @ 2025-08-25 14:27 UTC (permalink / raw)
To: Jian Shen, Salil Mehta, Jijie Shao, Andrew Lunn, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, netdev, linux-kernel
Cc: Qianfeng Rong
As noted in the kernel documentation [1], open-coded multiplication in
allocator arguments is discouraged because it can lead to integer overflow.
Use devm_kcalloc() to gain built-in overflow protection, making memory
allocation safer when calculating allocation size compared to explicit
multiplication.
Link: https://www.kernel.org/doc/html/next/process/deprecated.html#open-coded-arithmetic-in-allocator-arguments #1
Signed-off-by: Qianfeng Rong <rongqianfeng@vivo.com>
---
drivers/net/ethernet/hisilicon/hns3/hns3_debugfs.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3_debugfs.c b/drivers/net/ethernet/hisilicon/hns3/hns3_debugfs.c
index 0255c8acb744..4cce4f4ba6b0 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3_debugfs.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3_debugfs.c
@@ -843,7 +843,7 @@ static int hns3_dbg_bd_file_init(struct hnae3_handle *handle, u32 cmd)
entry_dir = hns3_dbg_dentry[hns3_dbg_cmd[cmd].dentry].dentry;
max_queue_num = hns3_get_max_available_channels(handle);
- data = devm_kzalloc(&handle->pdev->dev, max_queue_num * sizeof(*data),
+ data = devm_kcalloc(&handle->pdev->dev, max_queue_num, sizeof(*data),
GFP_KERNEL);
if (!data)
return -ENOMEM;
--
2.34.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] net: hns3: use kcalloc() instead of kzalloc()
2025-08-25 14:27 [PATCH] net: hns3: use kcalloc() instead of kzalloc() Qianfeng Rong
@ 2025-08-26 1:09 ` Jijie Shao
2025-08-27 0:20 ` patchwork-bot+netdevbpf
1 sibling, 0 replies; 3+ messages in thread
From: Jijie Shao @ 2025-08-26 1:09 UTC (permalink / raw)
To: Qianfeng Rong, Jian Shen, Salil Mehta, Andrew Lunn,
David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
netdev, linux-kernel
Cc: shaojijie
on 2025/8/25 22:27, Qianfeng Rong wrote:
> As noted in the kernel documentation [1], open-coded multiplication in
> allocator arguments is discouraged because it can lead to integer overflow.
>
> Use devm_kcalloc() to gain built-in overflow protection, making memory
> allocation safer when calculating allocation size compared to explicit
> multiplication.
>
> Link: https://www.kernel.org/doc/html/next/process/deprecated.html#open-coded-arithmetic-in-allocator-arguments #1
> Signed-off-by: Qianfeng Rong <rongqianfeng@vivo.com>
> ---
Thanks,
Reviewed-by: Jijie Shao <shaojijie@huawei.com>
> drivers/net/ethernet/hisilicon/hns3/hns3_debugfs.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3_debugfs.c b/drivers/net/ethernet/hisilicon/hns3/hns3_debugfs.c
> index 0255c8acb744..4cce4f4ba6b0 100644
> --- a/drivers/net/ethernet/hisilicon/hns3/hns3_debugfs.c
> +++ b/drivers/net/ethernet/hisilicon/hns3/hns3_debugfs.c
> @@ -843,7 +843,7 @@ static int hns3_dbg_bd_file_init(struct hnae3_handle *handle, u32 cmd)
>
> entry_dir = hns3_dbg_dentry[hns3_dbg_cmd[cmd].dentry].dentry;
> max_queue_num = hns3_get_max_available_channels(handle);
> - data = devm_kzalloc(&handle->pdev->dev, max_queue_num * sizeof(*data),
> + data = devm_kcalloc(&handle->pdev->dev, max_queue_num, sizeof(*data),
> GFP_KERNEL);
> if (!data)
> return -ENOMEM;
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] net: hns3: use kcalloc() instead of kzalloc()
2025-08-25 14:27 [PATCH] net: hns3: use kcalloc() instead of kzalloc() Qianfeng Rong
2025-08-26 1:09 ` Jijie Shao
@ 2025-08-27 0:20 ` patchwork-bot+netdevbpf
1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+netdevbpf @ 2025-08-27 0:20 UTC (permalink / raw)
To: Qianfeng Rong
Cc: shenjian15, salil.mehta, shaojijie, andrew+netdev, davem,
edumazet, kuba, pabeni, netdev, linux-kernel
Hello:
This patch was applied to netdev/net-next.git (main)
by Jakub Kicinski <kuba@kernel.org>:
On Mon, 25 Aug 2025 22:27:52 +0800 you wrote:
> As noted in the kernel documentation [1], open-coded multiplication in
> allocator arguments is discouraged because it can lead to integer overflow.
>
> Use devm_kcalloc() to gain built-in overflow protection, making memory
> allocation safer when calculating allocation size compared to explicit
> multiplication.
>
> [...]
Here is the summary with links:
- net: hns3: use kcalloc() instead of kzalloc()
https://git.kernel.org/netdev/net-next/c/7e484a97f6d5
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-08-27 0:20 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-25 14:27 [PATCH] net: hns3: use kcalloc() instead of kzalloc() Qianfeng Rong
2025-08-26 1:09 ` Jijie Shao
2025-08-27 0:20 ` patchwork-bot+netdevbpf
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).