ArmPkg/ArmDmaLib: deal with NULL return value of UncachedAllocatePages ()

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>
This commit is contained in:
Ard Biesheuvel 2016-04-19 16:12:10 +02:00
parent 9c0dc0b01a
commit e55f8c73b6
1 changed files with 10 additions and 2 deletions

View File

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