]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
crypto: hisilicon - use kcalloc() instead of kzalloc()
authorQianfeng Rong <rongqianfeng@vivo.com>
Thu, 21 Aug 2025 14:27:31 +0000 (22:27 +0800)
committerHerbert Xu <herbert@gondor.apana.org.au>
Sat, 30 Aug 2025 07:43:26 +0000 (15:43 +0800)
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
Signed-off-by: Qianfeng Rong <rongqianfeng@vivo.com>
Reviewed-by: Longfang Liu <liulongfang@huawei.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
drivers/crypto/hisilicon/hpre/hpre_main.c
drivers/crypto/hisilicon/sec2/sec_main.c
drivers/crypto/hisilicon/zip/zip_main.c

index 7b60e89015bdf176198400a03be464bab18f4f17..f437f361a2c9741fd52814578279cf241437db0a 100644 (file)
@@ -1213,7 +1213,7 @@ static int hpre_pre_store_cap_reg(struct hisi_qm *qm)
        size_t i, size;
 
        size = ARRAY_SIZE(hpre_cap_query_info);
-       hpre_cap = devm_kzalloc(dev, sizeof(*hpre_cap) * size, GFP_KERNEL);
+       hpre_cap = devm_kcalloc(dev, size, sizeof(*hpre_cap), GFP_KERNEL);
        if (!hpre_cap)
                return -ENOMEM;
 
index 348f1f52956dcb83ce9027f84dab6cdcd3163cde..bdb2d52ee1b61ed519a9333380f5224a88703834 100644 (file)
@@ -1215,7 +1215,7 @@ static int sec_pre_store_cap_reg(struct hisi_qm *qm)
        size_t i, size;
 
        size = ARRAY_SIZE(sec_cap_query_info);
-       sec_cap = devm_kzalloc(&pdev->dev, sizeof(*sec_cap) * size, GFP_KERNEL);
+       sec_cap = devm_kcalloc(&pdev->dev, size, sizeof(*sec_cap), GFP_KERNEL);
        if (!sec_cap)
                return -ENOMEM;
 
index 8c64f145173f524375172f8175a982b89039ae1d..fcb72d5cf5927e23937997697dcbbac633ee5230 100644 (file)
@@ -1331,7 +1331,7 @@ static int zip_pre_store_cap_reg(struct hisi_qm *qm)
        size_t i, size;
 
        size = ARRAY_SIZE(zip_cap_query_info);
-       zip_cap = devm_kzalloc(&pdev->dev, sizeof(*zip_cap) * size, GFP_KERNEL);
+       zip_cap = devm_kcalloc(&pdev->dev, size, sizeof(*zip_cap), GFP_KERNEL);
        if (!zip_cap)
                return -ENOMEM;