From: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Date: Thu, 15 Jan 2015 12:01:06 +0000 (+0000)
Subject: arm64/efi: handle potential failure to remap memory map
X-Git-Tag: firefly_0821_release~176^2~2354^2~28
X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=7fe5d2b1daf6fd82857a8d0ee47547d7852ebe7b;p=firefly-linux-kernel-4.4.55.git

arm64/efi: handle potential failure to remap memory map

When remapping the UEFI memory map using ioremap_cache(), we
have to deal with potential failure. Note that, even if the
common case is for ioremap_cache() to return the existing linear
mapping of the memory map, we cannot rely on that to be always the
case, e.g., in the presence of a mem= kernel parameter.

At the same time, remove a stale comment and move the memmap code
together.

Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Acked-by: Mark Rutland <mark.rutland@arm.com>
Acked-by: Mark Salter <msalter@redhat.com>
Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
---

diff --git a/arch/arm64/kernel/efi.c b/arch/arm64/kernel/efi.c
index a98415b5979c..c9cb0fbe7aa4 100644
--- a/arch/arm64/kernel/efi.c
+++ b/arch/arm64/kernel/efi.c
@@ -229,19 +229,21 @@ static int __init arm64_enable_runtime_services(void)
 		return -1;
 	}
 
-	mapsize = memmap.map_end - memmap.map;
-
 	if (efi_runtime_disabled()) {
 		pr_info("EFI runtime services will be disabled.\n");
 		return -1;
 	}
 
 	pr_info("Remapping and enabling EFI services.\n");
-	/* replace early memmap mapping with permanent mapping */
+
+	mapsize = memmap.map_end - memmap.map;
 	memmap.map = (__force void *)ioremap_cache((phys_addr_t)memmap.phys_map,
 						   mapsize);
+	if (!memmap.map) {
+		pr_err("Failed to remap EFI memory map\n");
+		return -1;
+	}
 	memmap.map_end = memmap.map + mapsize;
-
 	efi.memmap = &memmap;
 
 	efi.systab = (__force void *)ioremap_cache(efi_system_table,