]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Library/UefiBootManagerLib/BmDriverHealth.c
MdeModulePkg/UefiBootManagerLib: Fix small LoadOptionToVariable leak
[mirror_edk2.git] / MdeModulePkg / Library / UefiBootManagerLib / BmDriverHealth.c
index b3f57f56fab2ce310503ff84f91266372f674657..ecd01bbb81e356512a024722abffd0d0926fe19a 100644 (file)
@@ -1,7 +1,9 @@
 /** @file\r
   Library functions which relates with driver health.\r
 \r
-Copyright (c) 2011 - 2015, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2011 - 2018, Intel Corporation. All rights reserved.<BR>\r
+(C) Copyright 2015 Hewlett-Packard Development Company, L.P.<BR>\r
+(C) Copyright 2016 Hewlett Packard Enterprise Development LP<BR>\r
 This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
@@ -90,7 +92,7 @@ BmGetControllerName (
 \r
     Status = ComponentName->GetControllerName (\r
                               ComponentName,\r
-                              ControllerHandle, \r
+                              ControllerHandle,\r
                               ChildHandle,\r
                               BestLanguage,\r
                               &ControllerName\r
@@ -129,7 +131,7 @@ BmDisplayMessages (
 \r
   ControllerName = BmGetControllerName (\r
                      DriverHealthInfo->DriverHealthHandle,\r
-                     DriverHealthInfo->ControllerHandle, \r
+                     DriverHealthInfo->ControllerHandle,\r
                      DriverHealthInfo->ChildHandle\r
                      );\r
 \r
@@ -179,7 +181,7 @@ BmRepairNotify (
 \r
 /**\r
   Collect the Driver Health status of a single controller.\r
-  \r
+\r
   @param DriverHealthInfo        A pointer to the array containing all of the platform driver health information.\r
   @param Count                   Return the updated array count.\r
   @param DriverHealthHandle      The handle on which the Driver Health protocol instance is retrieved.\r
@@ -216,7 +218,7 @@ BmGetSingleControllerHealthStatus (
                   (VOID **) &DriverHealth\r
                   );\r
   ASSERT_EFI_ERROR (Status);\r
-  \r
+\r
 \r
   if (ControllerHandle == NULL) {\r
     //\r
@@ -295,7 +297,6 @@ EfiBootManagerGetDriverHealthInfo (
   EFI_STATUS                 Status;\r
   UINTN                      NumHandles;\r
   EFI_HANDLE                 *DriverHealthHandles;\r
-  EFI_DRIVER_HEALTH_STATUS   HealthStatus;\r
   UINTN                      DriverHealthIndex;\r
   EFI_HANDLE                 *Handles;\r
   UINTN                      HandleCount;\r
@@ -313,8 +314,6 @@ EfiBootManagerGetDriverHealthInfo (
   NumHandles              = 0;\r
   HandleCount             = 0;\r
 \r
-  HealthStatus = EfiDriverHealthStatusHealthy;\r
-\r
   Status = gBS->LocateHandleBuffer (\r
                   ByProtocol,\r
                   &gEfiDriverHealthProtocolGuid,\r
@@ -424,10 +423,13 @@ EfiBootManagerFreeDriverHealthInfo (
 \r
 /**\r
   Repair all the controllers according to the Driver Health status queried.\r
+\r
+  @param ReconnectRepairCount     To record the number of recursive call of\r
+                                  this function itself.\r
 **/\r
 VOID\r
 BmRepairAllControllers (\r
-  VOID\r
+  UINTN       ReconnectRepairCount\r
   )\r
 {\r
   EFI_STATUS                          Status;\r
@@ -441,17 +443,22 @@ BmRepairAllControllers (
   BOOLEAN                             RebootRequired;\r
   EFI_HII_HANDLE                      *HiiHandles;\r
   EFI_FORM_BROWSER2_PROTOCOL          *FormBrowser2;\r
+  UINT32                              MaxRepairCount;\r
+  UINT32                              RepairCount;\r
 \r
   //\r
   // Configure PcdDriverHealthConfigureForm to ZeroGuid to disable driver health check.\r
   //\r
-  if (CompareGuid (PcdGetPtr (PcdDriverHealthConfigureForm), &gZeroGuid)) {\r
+  if (IsZeroGuid (PcdGetPtr (PcdDriverHealthConfigureForm))) {\r
     return;\r
   }\r
 \r
   Status = gBS->LocateProtocol (&gEfiFormBrowser2ProtocolGuid, NULL, (VOID **) &FormBrowser2);\r
   ASSERT_EFI_ERROR (Status);\r
 \r
+  MaxRepairCount = PcdGet32 (PcdMaxRepairCount);\r
+  RepairCount = 0;\r
+\r
   do {\r
     RepairRequired        = FALSE;\r
     ConfigurationRequired = FALSE;\r
@@ -464,7 +471,7 @@ BmRepairAllControllers (
       if (DriverHealthInfo[Index].HealthStatus == EfiDriverHealthStatusConfigurationRequired) {\r
         ConfigurationRequired = TRUE;\r
       }\r
-      \r
+\r
       if (DriverHealthInfo[Index].HealthStatus == EfiDriverHealthStatusRepairRequired) {\r
         RepairRequired        = TRUE;\r
 \r
@@ -512,9 +519,10 @@ BmRepairAllControllers (
         FreePool (HiiHandles);\r
       }\r
     }\r
-  \r
+\r
     EfiBootManagerFreeDriverHealthInfo (DriverHealthInfo, Count);\r
-  } while (RepairRequired || ConfigurationRequired);\r
+    RepairCount++;\r
+  } while ((RepairRequired || ConfigurationRequired) && ((MaxRepairCount == 0) || (RepairCount < MaxRepairCount)));\r
 \r
   RebootRequired    = FALSE;\r
   ReconnectRequired = FALSE;\r
@@ -543,10 +551,6 @@ BmRepairAllControllers (
   EfiBootManagerFreeDriverHealthInfo (DriverHealthInfo, Count);\r
 \r
 \r
-  if (ReconnectRequired) {\r
-    BmRepairAllControllers ();\r
-  }\r
-\r
   DEBUG_CODE (\r
     CHAR16 *ControllerName;\r
 \r
@@ -571,6 +575,15 @@ BmRepairAllControllers (
     EfiBootManagerFreeDriverHealthInfo (DriverHealthInfo, Count);\r
     );\r
 \r
+  if (ReconnectRequired) {\r
+    if (ReconnectRepairCount < MAX_RECONNECT_REPAIR) {\r
+      BmRepairAllControllers (ReconnectRepairCount + 1);\r
+    } else {\r
+      DEBUG ((DEBUG_ERROR, "[%a:%d] Repair failed after %d retries.\n",\r
+        __FUNCTION__, __LINE__, ReconnectRepairCount));\r
+    }\r
+  }\r
+\r
   if (RebootRequired) {\r
     DEBUG ((EFI_D_INFO, "[BDS] One of the Driver Health instances requires rebooting.\n"));\r
     gRT->ResetSystem (EfiResetWarm, EFI_SUCCESS, 0, NULL);\r