[PATCH] relay: use kvcalloc to alloc page array in relay_alloc_page_array

From: wuchi
Date: Fri Sep 09 2022 - 06:10:52 EST


The kvcalloc is safer because it will check the integer overflows,
and using it will simple the logic of allocation size.

Signed-off-by: wuchi <wuchi.zero@xxxxxxxxx>
---
kernel/relay.c | 5 +----
1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/kernel/relay.c b/kernel/relay.c
index 6a611e779e95..d7edc934c56d 100644
--- a/kernel/relay.c
+++ b/kernel/relay.c
@@ -60,10 +60,7 @@ static const struct vm_operations_struct relay_file_mmap_ops = {
*/
static struct page **relay_alloc_page_array(unsigned int n_pages)
{
- const size_t pa_size = n_pages * sizeof(struct page *);
- if (pa_size > PAGE_SIZE)
- return vzalloc(pa_size);
- return kzalloc(pa_size, GFP_KERNEL);
+ return kvcalloc(n_pages, sizeof(struct page *), GFP_KERNEL);
}

/*
--
2.20.1