]> git.proxmox.com Git - mirror_edk2.git/commitdiff
ArmPkg/Library/ArmDmaLib: Deallocate Map buffer in case of error
authorDaniil Egranov <daniil.egranov@arm.com>
Tue, 15 Nov 2016 13:24:40 +0000 (13:24 +0000)
committerArd Biesheuvel <ard.biesheuvel@linaro.org>
Tue, 15 Nov 2016 13:24:40 +0000 (13:24 +0000)
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>
ArmPkg/Library/ArmDmaLib/ArmDmaLib.c

index d48d6ff6dbbb82993d6232858e11739bc10a8fb9..4476e8b461e39b1e7d051e3b89489c9c0fb25c9b 100644 (file)
@@ -90,15 +90,13 @@ DmaMap (
     return  EFI_OUT_OF_RESOURCES;\r
   }\r
 \r
-  *Mapping = Map;\r
-\r
   if ((((UINTN)HostAddress & (gCacheAlignment - 1)) != 0) ||\r
       ((*NumberOfBytes & (gCacheAlignment - 1)) != 0)) {\r
 \r
     // Get the cacheability of the region\r
     Status = gDS->GetMemorySpaceDescriptor (*DeviceAddress, &GcdDescriptor);\r
     if (EFI_ERROR(Status)) {\r
-      return Status;\r
+      goto FreeMapInfo;\r
     }\r
 \r
     // If the mapped buffer is not an uncached buffer\r
@@ -112,7 +110,8 @@ DmaMap (
           "%a: Operation type 'MapOperationBusMasterCommonBuffer' is only supported\n"\r
           "on memory regions that were allocated using DmaAllocateBuffer ()\n",\r
           __FUNCTION__));\r
-        return EFI_UNSUPPORTED;\r
+        Status = EFI_UNSUPPORTED;\r
+        goto FreeMapInfo;\r
       }\r
 \r
       //\r
@@ -122,7 +121,7 @@ DmaMap (
       Map->DoubleBuffer  = TRUE;\r
       Status = DmaAllocateBuffer (EfiBootServicesData, EFI_SIZE_TO_PAGES (*NumberOfBytes), &Buffer);\r
       if (EFI_ERROR (Status)) {\r
-        return Status;\r
+        goto FreeMapInfo;\r
       }\r
 \r
       if (Operation == MapOperationBusMasterRead) {\r
@@ -162,7 +161,14 @@ DmaMap (
   Map->NumberOfBytes = *NumberOfBytes;\r
   Map->Operation     = Operation;\r
 \r
+  *Mapping = Map;\r
+\r
   return EFI_SUCCESS;\r
+\r
+FreeMapInfo:\r
+  FreePool (Map);\r
+\r
+  return Status;\r
 }\r
 \r
 \r