]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
net: hns3: use kcalloc() instead of kzalloc()
authorQianfeng Rong <rongqianfeng@vivo.com>
Mon, 25 Aug 2025 14:27:52 +0000 (22:27 +0800)
committerJakub Kicinski <kuba@kernel.org>
Wed, 27 Aug 2025 00:12:35 +0000 (17:12 -0700)
As noted in the kernel documentation, 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.

Signed-off-by: Qianfeng Rong <rongqianfeng@vivo.com>
Reviewed-by: Jijie Shao <shaojijie@huawei.com>
Link: https://patch.msgid.link/20250825142753.534509-1-rongqianfeng@vivo.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
drivers/net/ethernet/hisilicon/hns3/hns3_debugfs.c

index 0255c8acb74444ba60d23a54843565cf517c18ab..4cce4f4ba6b018c74191c14cfaa6d7ca3202c67f 100644 (file)
@@ -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;