]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
RDMA/erdma: Use vcalloc() instead of vzalloc()
authorQianfeng Rong <rongqianfeng@vivo.com>
Thu, 21 Aug 2025 07:22:09 +0000 (15:22 +0800)
committerJason Gunthorpe <jgg@nvidia.com>
Mon, 25 Aug 2025 18:14:54 +0000 (15:14 -0300)
Replace vzalloc() with vcalloc() in vmalloc_to_dma_addrs().  As noted in
the kernel documentation [1], open-coded multiplication in allocator
arguments is discouraged because it can lead to integer overflow.

Use vcalloc() to gain built-in overflow protection, making memory
allocation safer when calculating allocation size compared to explicit
multiplication.

[1]: https://www.kernel.org/doc/html/next/process/deprecated.html#open-coded-arithmetic-in-allocator-arguments

Link: https://patch.msgid.link/r/20250821072209.510348-1-rongqianfeng@vivo.com
Signed-off-by: Qianfeng Rong <rongqianfeng@vivo.com>
Reviewed-by: Cheng Xu <chengyou@linux.alibaba.com>
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
drivers/infiniband/hw/erdma/erdma_verbs.c

index b4dadd30683796b20beddd29a4d28531d17d938b..bb8809ed2f75bcdd743d89f7584b679fcc1acb10 100644 (file)
@@ -671,7 +671,7 @@ static u32 vmalloc_to_dma_addrs(struct erdma_dev *dev, dma_addr_t **dma_addrs,
 
        npages = (PAGE_ALIGN((u64)buf + len) - PAGE_ALIGN_DOWN((u64)buf)) >>
                 PAGE_SHIFT;
-       pg_dma = vzalloc(npages * sizeof(dma_addr_t));
+       pg_dma = vcalloc(npages, sizeof(*pg_dma));
        if (!pg_dma)
                return 0;