diff options
author | Daniil Egranov <daniil.egranov@arm.com> | 2016-11-15 13:24:40 +0000 |
---|---|---|
committer | Ard Biesheuvel <ard.biesheuvel@linaro.org> | 2016-11-15 13:24:40 +0000 |
commit | 84083b12f234b62fb133d8c47ee4ab95f3b0eef9 (patch) | |
tree | 0216c1c04363896ff6ef63ca308089137fd065bc | |
parent | c0cb1e1a72bccb5c83d7a36a8e52a38002b18671 (diff) | |
download | edk2-84083b12f234b62fb133d8c47ee4ab95f3b0eef9.tar.gz edk2-84083b12f234b62fb133d8c47ee4ab95f3b0eef9.tar.bz2 edk2-84083b12f234b62fb133d8c47ee4ab95f3b0eef9.zip |
ArmPkg/Library/ArmDmaLib: Deallocate Map buffer in case of error
The patch is fixing memory leak in case of errors.
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Daniil Egranov <daniil.egranov@arm.com>
Tested-by; Ryan Harkin <ryan.harkin@linaro.org>
Style fixes: use goto for error handling, whitespace fixes
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
-rw-r--r-- | ArmPkg/Library/ArmDmaLib/ArmDmaLib.c | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/ArmPkg/Library/ArmDmaLib/ArmDmaLib.c b/ArmPkg/Library/ArmDmaLib/ArmDmaLib.c index d48d6ff6db..4476e8b461 100644 --- a/ArmPkg/Library/ArmDmaLib/ArmDmaLib.c +++ b/ArmPkg/Library/ArmDmaLib/ArmDmaLib.c @@ -90,15 +90,13 @@ DmaMap ( return EFI_OUT_OF_RESOURCES;
}
- *Mapping = Map;
-
if ((((UINTN)HostAddress & (gCacheAlignment - 1)) != 0) ||
((*NumberOfBytes & (gCacheAlignment - 1)) != 0)) {
// Get the cacheability of the region
Status = gDS->GetMemorySpaceDescriptor (*DeviceAddress, &GcdDescriptor);
if (EFI_ERROR(Status)) {
- return Status;
+ goto FreeMapInfo;
}
// If the mapped buffer is not an uncached buffer
@@ -112,7 +110,8 @@ DmaMap ( "%a: Operation type 'MapOperationBusMasterCommonBuffer' is only supported\n"
"on memory regions that were allocated using DmaAllocateBuffer ()\n",
__FUNCTION__));
- return EFI_UNSUPPORTED;
+ Status = EFI_UNSUPPORTED;
+ goto FreeMapInfo;
}
//
@@ -122,7 +121,7 @@ DmaMap ( Map->DoubleBuffer = TRUE;
Status = DmaAllocateBuffer (EfiBootServicesData, EFI_SIZE_TO_PAGES (*NumberOfBytes), &Buffer);
if (EFI_ERROR (Status)) {
- return Status;
+ goto FreeMapInfo;
}
if (Operation == MapOperationBusMasterRead) {
@@ -162,7 +161,14 @@ DmaMap ( Map->NumberOfBytes = *NumberOfBytes;
Map->Operation = Operation;
+ *Mapping = Map;
+
return EFI_SUCCESS;
+
+FreeMapInfo:
+ FreePool (Map);
+
+ return Status;
}
|