Skip to contentSkip to conversation

arm64: early_alloc: Fix check for allocation failure

PATCH New Suzuki K. Poulose 3 participants 3 messages Nov 20, 2015 – Nov 25, 2015 arm64

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 arm64: early_alloc: Fix check for allocation failure

In early_alloc we check if the memblock_alloc failed by checking the virtual address of the result, which will never fail. This patch fixes it to check the actual result for failure.

Cc Catalin Marinas <[email protected]>
Cc Will Deacon <[email protected]>
---
 arch/arm64/mm/mmu.c |    8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
arch/arm64/mm/mmu.c +6 -2
index e3f563c..e94c32b 100644
@@ -64,8 +64,12 @@ EXPORT_SYMBOL(phys_mem_access_prot);
 
 static void __init *early_alloc(unsigned long sz)
 {
-	void *ptr = __va(memblock_alloc(sz, sz));
-	BUG_ON(!ptr);
+	phys_addr_t phys;
+	void *ptr;
+
+	phys = memblock_alloc(sz, sz);
+	BUG_ON(!phys);
+	ptr = __va(phys);
 	memset(ptr, 0, sz);
 	return ptr;
 }
Signature · 1 line
1.7.9.5
#1 lore raw

PATCH 1/1 arm64: early_alloc: Fix check for allocation failure

Quoted 19 lines · Suzuki K. Poulose

In early_alloc we check if the memblock_alloc failed by checking the virtual address of the result, which will never fail. This patch fixes it to check the actual result for failure.

Cc Catalin Marinas <[email protected]>
Cc Will Deacon <[email protected]>
---
 arch/arm64/mm/mmu.c |    8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
arch/arm64/mm/mmu.c +0 -0
index e3f563c..e94c32b 100644
@@ -64,8 +64,12 @@ EXPORT_SYMBOL(phys_mem_access_prot);
 
 static void __init *early_alloc(unsigned long sz)
 {

arch/arm64/mm/mmu.c EXPORT_SYMBOL(phys_mem_access_prot); · line 74

Quoted 10 lines
arch/arm64/mm/mmu.c +6 -2
-	void *ptr = __va(memblock_alloc(sz, sz));
-	BUG_ON(!ptr);
+	phys_addr_t phys;
+	void *ptr;
+
+	phys = memblock_alloc(sz, sz);
+	BUG_ON(!phys);
+	ptr = __va(phys);
 	memset(ptr, 0, sz);
 	return ptr;

Haha, oops! I guess we don't tend to see failures that early on, but the fix is correct:

Will

maintainer Applied
#2 lore raw

PATCH 1/1 arm64: early_alloc: Fix check for allocation failure

In reply to Suzuki K. Poulose
Quoted 7 lines · Suzuki K. Poulose

In early_alloc we check if the memblock_alloc failed by checking the virtual address of the result, which will never fail. This patch fixes it to check the actual result for failure.

Cc Catalin Marinas <[email protected]>
Cc Will Deacon <[email protected]>

Applied. Thanks.

Signature · 1 line
Catalin