Revision: 18527
          http://sourceforge.net/p/edk2/code/18527
Author:   lersek
Date:     2015-09-22 11:18:22 +0000 (Tue, 22 Sep 2015)
Log Message:
-----------
OvmfPkg: SataControllerDxe: add cascading error handling to Start()

In the next patch we'll add another PCI operation to
SataControllerStart(), which, on error, has to be rolled back similarly to
other actions already being done in SataControllerStart(). Since that PCI
operation won't provide a non-NULL pointer on success, its rollback isn't
really suitable for the current error handling in SataControllerStart().

Employ the traditional cascading labels instead.

Cc: Alexander Graf <[email protected]>
Cc: Reza Jelveh <[email protected]>
Cc: Jordan Justen <[email protected]>
Cc: Hannes Reinecke <[email protected]>
Cc: Gabriel L. Somlo <[email protected]>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Laszlo Ersek <[email protected]>
Tested-by: Gabriel Somlo <[email protected]>
Reviewed-by: Jordan Justen <[email protected]>

Modified Paths:
--------------
    trunk/edk2/OvmfPkg/SataControllerDxe/SataController.c

Modified: trunk/edk2/OvmfPkg/SataControllerDxe/SataController.c
===================================================================
--- trunk/edk2/OvmfPkg/SataControllerDxe/SataController.c       2015-09-22 
11:18:18 UTC (rev 18526)
+++ trunk/edk2/OvmfPkg/SataControllerDxe/SataController.c       2015-09-22 
11:18:22 UTC (rev 18527)
@@ -411,8 +411,7 @@
                   EFI_OPEN_PROTOCOL_BY_DRIVER
                   );
   if (EFI_ERROR (Status)) {
-    DEBUG ((EFI_D_ERROR, "SataControllerStart error return status = %r\n", 
Status));
-    return Status;
+    goto Bail;
   }
 
   //
@@ -421,7 +420,7 @@
   SataPrivateData = AllocateZeroPool (sizeof 
(EFI_SATA_CONTROLLER_PRIVATE_DATA));
   if (SataPrivateData == NULL) {
     Status = EFI_OUT_OF_RESOURCES;
-    goto Done;
+    goto ClosePciIo;
   }
 
   //
@@ -444,7 +443,9 @@
                         sizeof (PciData.Hdr.ClassCode),
                         PciData.Hdr.ClassCode
                         );
-  ASSERT_EFI_ERROR (Status);
+  if (EFI_ERROR (Status)) {
+    goto FreeSataPrivateData;
+  }
 
   if (IS_PCI_IDE (&PciData)) {
     SataPrivateData->IdeInit.ChannelCount = IDE_MAX_CHANNEL;
@@ -467,19 +468,19 @@
   SataPrivateData->DisqualifiedModes = AllocateZeroPool ((sizeof 
(EFI_ATA_COLLECTIVE_MODE)) * ChannelDeviceCount);
   if (SataPrivateData->DisqualifiedModes == NULL) {
     Status = EFI_OUT_OF_RESOURCES;
-    goto Done;
+    goto FreeSataPrivateData;
   }
 
   SataPrivateData->IdentifyData = AllocateZeroPool ((sizeof 
(EFI_IDENTIFY_DATA)) * ChannelDeviceCount);
   if (SataPrivateData->IdentifyData == NULL) {
     Status = EFI_OUT_OF_RESOURCES;
-    goto Done;
+    goto FreeDisqualifiedModes;
   }
 
   SataPrivateData->IdentifyValid = AllocateZeroPool ((sizeof (BOOLEAN)) * 
ChannelDeviceCount);
   if (SataPrivateData->IdentifyValid == NULL) {
     Status = EFI_OUT_OF_RESOURCES;
-    goto Done;
+    goto FreeIdentifyData;
   }
 
   //
@@ -492,31 +493,35 @@
                   NULL
                   );
 
-Done:
   if (EFI_ERROR (Status)) {
-
-    gBS->CloseProtocol (
-          Controller,
-          &gEfiPciIoProtocolGuid,
-          This->DriverBindingHandle,
-          Controller
-          );
-    if (SataPrivateData != NULL) {
-      if (SataPrivateData->DisqualifiedModes != NULL) {
-        FreePool (SataPrivateData->DisqualifiedModes);
-      }
-      if (SataPrivateData->IdentifyData != NULL) {
-        FreePool (SataPrivateData->IdentifyData);
-      }
-      if (SataPrivateData->IdentifyValid != NULL) {
-        FreePool (SataPrivateData->IdentifyValid);
-      }
-      FreePool (SataPrivateData);
-    }
+    goto FreeIdentifyValid;
   }
 
   DEBUG ((EFI_D_INFO, "SataControllerStart END status = %r\n", Status));
+  return Status;
 
+FreeIdentifyValid:
+  FreePool (SataPrivateData->IdentifyValid);
+
+FreeIdentifyData:
+  FreePool (SataPrivateData->IdentifyData);
+
+FreeDisqualifiedModes:
+  FreePool (SataPrivateData->DisqualifiedModes);
+
+FreeSataPrivateData:
+  FreePool (SataPrivateData);
+
+ClosePciIo:
+  gBS->CloseProtocol (
+         Controller,
+         &gEfiPciIoProtocolGuid,
+         This->DriverBindingHandle,
+         Controller
+         );
+
+Bail:
+  DEBUG ((EFI_D_ERROR, "SataControllerStart error return status = %r\n", 
Status));
   return Status;
 }
 


------------------------------------------------------------------------------
_______________________________________________
edk2-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/edk2-commits

Reply via email to