Fixed potential issues to release resources when error occurs.
[mirror_edk2.git] / OptionRomPkg / CirrusLogic5430Dxe / CirrusLogic5430.c
index eb5ce3b..424e19d 100644 (file)
@@ -211,7 +211,9 @@ CirrusLogic5430ControllerDriverStart (
 {\r
   EFI_STATUS                      Status;\r
   CIRRUS_LOGIC_5430_PRIVATE_DATA  *Private;\r
+  BOOLEAN                         PciAttributesSaved;\r
 \r
+  PciAttributesSaved = FALSE;\r
   //\r
   // Allocate Private context data for UGA Draw inteface.\r
   //\r
@@ -255,6 +257,7 @@ CirrusLogic5430ControllerDriverStart (
   if (EFI_ERROR (Status)) {\r
     goto Error;\r
   }\r
+  PciAttributesSaved = TRUE;\r
 \r
   Status = Private->PciIo->Attributes (\r
                             Private->PciIo,\r
@@ -319,16 +322,17 @@ Error:
   if (EFI_ERROR (Status)) {\r
     if (Private) {\r
       if (Private->PciIo) {\r
-        //\r
-        // Restore original PCI attributes\r
-        //\r
-        Private->PciIo->Attributes (\r
-                        Private->PciIo,\r
-                        EfiPciIoAttributeOperationSet,\r
-                        Private->OriginalPciAttributes,\r
-                        NULL\r
-                        );\r
-\r
+        if (PciAttributesSaved == TRUE) {\r
+          //\r
+          // Restore original PCI attributes\r
+          //\r
+          Private->PciIo->Attributes (\r
+                          Private->PciIo,\r
+                          EfiPciIoAttributeOperationSet,\r
+                          Private->OriginalPciAttributes,\r
+                          NULL\r
+                          );\r
+        }\r
         //\r
         // Close the PCI I/O Protocol\r
         //\r