mirror of
https://github.com/acidanthera/audk.git
synced 2025-07-31 01:24:12 +02:00
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>
This commit is contained in:
parent
c0cb1e1a72
commit
84083b12f2
@ -90,15 +90,13 @@ DmaMap (
|
|||||||
return EFI_OUT_OF_RESOURCES;
|
return EFI_OUT_OF_RESOURCES;
|
||||||
}
|
}
|
||||||
|
|
||||||
*Mapping = Map;
|
|
||||||
|
|
||||||
if ((((UINTN)HostAddress & (gCacheAlignment - 1)) != 0) ||
|
if ((((UINTN)HostAddress & (gCacheAlignment - 1)) != 0) ||
|
||||||
((*NumberOfBytes & (gCacheAlignment - 1)) != 0)) {
|
((*NumberOfBytes & (gCacheAlignment - 1)) != 0)) {
|
||||||
|
|
||||||
// Get the cacheability of the region
|
// Get the cacheability of the region
|
||||||
Status = gDS->GetMemorySpaceDescriptor (*DeviceAddress, &GcdDescriptor);
|
Status = gDS->GetMemorySpaceDescriptor (*DeviceAddress, &GcdDescriptor);
|
||||||
if (EFI_ERROR(Status)) {
|
if (EFI_ERROR(Status)) {
|
||||||
return Status;
|
goto FreeMapInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the mapped buffer is not an uncached buffer
|
// If the mapped buffer is not an uncached buffer
|
||||||
@ -112,7 +110,8 @@ DmaMap (
|
|||||||
"%a: Operation type 'MapOperationBusMasterCommonBuffer' is only supported\n"
|
"%a: Operation type 'MapOperationBusMasterCommonBuffer' is only supported\n"
|
||||||
"on memory regions that were allocated using DmaAllocateBuffer ()\n",
|
"on memory regions that were allocated using DmaAllocateBuffer ()\n",
|
||||||
__FUNCTION__));
|
__FUNCTION__));
|
||||||
return EFI_UNSUPPORTED;
|
Status = EFI_UNSUPPORTED;
|
||||||
|
goto FreeMapInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
@ -122,7 +121,7 @@ DmaMap (
|
|||||||
Map->DoubleBuffer = TRUE;
|
Map->DoubleBuffer = TRUE;
|
||||||
Status = DmaAllocateBuffer (EfiBootServicesData, EFI_SIZE_TO_PAGES (*NumberOfBytes), &Buffer);
|
Status = DmaAllocateBuffer (EfiBootServicesData, EFI_SIZE_TO_PAGES (*NumberOfBytes), &Buffer);
|
||||||
if (EFI_ERROR (Status)) {
|
if (EFI_ERROR (Status)) {
|
||||||
return Status;
|
goto FreeMapInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Operation == MapOperationBusMasterRead) {
|
if (Operation == MapOperationBusMasterRead) {
|
||||||
@ -162,7 +161,14 @@ DmaMap (
|
|||||||
Map->NumberOfBytes = *NumberOfBytes;
|
Map->NumberOfBytes = *NumberOfBytes;
|
||||||
Map->Operation = Operation;
|
Map->Operation = Operation;
|
||||||
|
|
||||||
|
*Mapping = Map;
|
||||||
|
|
||||||
return EFI_SUCCESS;
|
return EFI_SUCCESS;
|
||||||
|
|
||||||
|
FreeMapInfo:
|
||||||
|
FreePool (Map);
|
||||||
|
|
||||||
|
return Status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user