Skip to contentSkip to conversation

x86/sgx: Use vmalloc_array() instead of vmalloc()

PATCH Superseded Thorsten Blum 2 participants 2 messages Sep 29, 2024 – Oct 7, 2024

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86/sgx: Use vmalloc_array() instead of vmalloc()

Use vmalloc_array() instead of vmalloc() to calculate the number of bytes to allocate.

---
 arch/x86/kernel/cpu/sgx/main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kernel/cpu/sgx/main.c +1 -1
index 9ace84486499..1a59e5956f4b 100644
@@ -630,7 +630,7 @@ static bool __init sgx_setup_epc_section(u64 phys_addr, u64 size,
 	if (!section->virt_addr)
 		return false;
 
-	section->pages = vmalloc(nr_pages * sizeof(struct sgx_epc_page));
+	section->pages = vmalloc_array(nr_pages, sizeof(struct sgx_epc_page));
 	if (!section->pages) {
 		memunmap(section->virt_addr);
 		return false;
Signature · 1 line
2.46.2
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 21 lines · Thorsten Blum

Use vmalloc_array() instead of vmalloc() to calculate the number of bytes to allocate.

---
 arch/x86/kernel/cpu/sgx/main.c | 2 +-

 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kernel/cpu/sgx/main.c +0 -0
index 9ace84486499..1a59e5956f4b 100644
@@ -630,7 +630,7 @@ static bool __init sgx_setup_epc_section(u64
 phys_addr, u64 size,
  	if (!section->virt_addr)
  		return false;

arch/x86/kernel/cpu/sgx/main.c +0 -1
-	section->pages = vmalloc(nr_pages * sizeof(struct

sgx_epc_page));

arch/x86/kernel/cpu/sgx/main.c +1 -0
+	section->pages = vmalloc_array(nr_pages, sizeof(struct
Quoted 4 lines

sgx_epc_page));
  if (!section->pages) {
  memunmap(section->virt_addr);
  return false;

BR, Jarkko