]> git.proxmox.com Git - mirror_edk2.git/commitdiff
ArmPkg/ArmDmaLib: deal with NULL return value of UncachedAllocatePages ()
authorArd Biesheuvel <ard.biesheuvel@linaro.org>
Tue, 19 Apr 2016 14:12:10 +0000 (16:12 +0200)
committerArd Biesheuvel <ard.biesheuvel@linaro.org>
Tue, 10 May 2016 12:38:59 +0000 (14:38 +0200)
The allocation function UncachedAllocatePages () may return NULL, in
which case our implementation of DmaAllocateBuffer () should return
EFI_OUT_OF_RESOURCES rather than silently ignoring the NULL value and
returning EFI_SUCCESS.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Reviewed-by: Leif Lindholm <leif.lindholm@linaro.org>
ArmPkg/Library/ArmDmaLib/ArmDmaLib.c

index 54a49a18d3029134d21b139895e2b24b45acccb2..1e6b288b10b91ab9a1d35fe1b2271996365e1ab9 100644 (file)
@@ -216,6 +216,8 @@ DmaAllocateBuffer (
   OUT VOID                         **HostAddress\r
   )\r
 {\r
+  VOID    *Allocation;\r
+\r
   if (HostAddress == NULL) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
@@ -226,13 +228,19 @@ DmaAllocateBuffer (
   // We used uncached memory to keep coherency\r
   //\r
   if (MemoryType == EfiBootServicesData) {\r
-    *HostAddress = UncachedAllocatePages (Pages);\r
+    Allocation = UncachedAllocatePages (Pages);\r
   } else if (MemoryType == EfiRuntimeServicesData) {\r
-    *HostAddress = UncachedAllocateRuntimePages (Pages);\r
+    Allocation = UncachedAllocateRuntimePages (Pages);\r
   } else {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
+  if (Allocation == NULL) {\r
+    return EFI_OUT_OF_RESOURCES;\r
+  }\r
+\r
+  *HostAddress = Allocation;\r
+\r
   return EFI_SUCCESS;\r
 }\r
 \r