SignedCapsulePkg SystemFirmwareUpdateDxe: Fix failure caused by d69d922
authorStar Zeng <star.zeng@intel.com>
Fri, 13 Apr 2018 09:55:14 +0000 (17:55 +0800)
committerStar Zeng <star.zeng@intel.com>
Mon, 16 Apr 2018 05:55:00 +0000 (13:55 +0800)
d69d9227d046211265de1fab5580c50a65944614 caused system firmware update
failure. It is because FindMatchingFmpHandles() is expected to return
handles matched, but the function returns all handles found.

This patch is to fix the issue.
This patch also assigns mSystemFmpPrivate->Handle for "case 1:" path
in case the Handle is needed by other place in future.

Cc: Michael D Kinney <michael.d.kinney@intel.com>
Cc: Jiewen Yao <jiewen.yao@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Star Zeng <star.zeng@intel.com>
Reviewed-by: Jiewen Yao <jiewen.yao@intel.com>
Reviewed-by: Michael D Kinney <michael.d.kinney@intel.com>
SignedCapsulePkg/Universal/SystemFirmwareUpdate/SystemFirmwareUpdateDxe.c

index d0b1c99..fa0c5f0 100644 (file)
@@ -602,6 +602,7 @@ FindMatchingFmpHandles (
   )\r
 {\r
   EFI_STATUS                     Status;\r
+  UINTN                          TempHandleCount;\r
   EFI_HANDLE                     *HandleBuffer;\r
   UINTN                          Index;\r
   UINTN                          Index2;\r
@@ -613,20 +614,20 @@ FindMatchingFmpHandles (
   BOOLEAN                        MatchFound;\r
 \r
   *HandleCount  = 0;\r
+  TempHandleCount = 0;\r
   HandleBuffer = NULL;\r
   Status = gBS->LocateHandleBuffer (\r
                    ByProtocol,\r
                    ProtocolGuid,\r
                    NULL,\r
-                   HandleCount,\r
+                   &TempHandleCount,\r
                    &HandleBuffer\r
                    );\r
   if (EFI_ERROR (Status)) {\r
-    *HandleCount  = 0;\r
     return NULL;\r
   }\r
 \r
-  for (Index = 0; Index < *HandleCount; Index++) {\r
+  for (Index = 0; Index < TempHandleCount; Index++) {\r
     OriginalFmpImageInfoBuf = GetFmpImageDescriptors (\r
                                 HandleBuffer[Index],\r
                                 ProtocolGuid,\r
@@ -657,12 +658,21 @@ FindMatchingFmpHandles (
       //\r
       FmpImageInfoBuf = (EFI_FIRMWARE_IMAGE_DESCRIPTOR *)(((UINT8 *)FmpImageInfoBuf) + DescriptorSize);\r
     }\r
-    if (!MatchFound) {\r
-      HandleBuffer[Index] = NULL;\r
+    if (MatchFound) {\r
+      HandleBuffer[*HandleCount] = HandleBuffer[Index];\r
+      (*HandleCount)++;\r
     }\r
 \r
     FreePool (OriginalFmpImageInfoBuf);\r
   }\r
+\r
+  if ((*HandleCount) == 0) {\r
+    //\r
+    // No any matching handle.\r
+    //\r
+    FreePool (HandleBuffer);\r
+    return NULL;\r
+  }\r
   return HandleBuffer;\r
 }\r
 \r
@@ -801,6 +811,7 @@ SystemFirmwareUpdateMainDxe (
     // Install System FMP protocol onto handle with matching FMP Protocol\r
     //\r
     DEBUG ((DEBUG_INFO, "SystemFirmwareUpdateDxe: Install System FMP onto matching FMP handle\n"));\r
+    mSystemFmpPrivate->Handle = HandleBuffer[0];\r
     Status = gBS->InstallMultipleProtocolInterfaces (\r
                     &HandleBuffer[0],\r
                     &gSystemFmpProtocolGuid,\r