]> git.proxmox.com Git - mirror_edk2.git/blobdiff - Nt32Pkg/WinNtBusDriverDxe/WinNtBusDriver.c
Nt32Pkg/WinNtBusDriverDxe: Fix memory allocation size
[mirror_edk2.git] / Nt32Pkg / WinNtBusDriverDxe / WinNtBusDriver.c
index 86d7929671cf343339582e1c9375ce5a8a69e891..cfce4a0af34575050c6e4f589758eaa5688cb6d1 100644 (file)
@@ -1,7 +1,8 @@
 /**@file\r
 \r
-Copyright (c) 2006 - 2007, Intel Corporation\r
-All rights reserved. This program and the accompanying materials\r
+Copyright (c) 2006 - 2009, Intel Corporation. All rights reserved.<BR>\r
+(C) Copyright 2018 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
 http://opensource.org/licenses/bsd-license.php\r
@@ -239,20 +240,30 @@ Returns:
   // it is a legal Device Path Node for this bus driver's children.\r
   //\r
   if (RemainingDevicePath != NULL) {\r
-    if (RemainingDevicePath->Type != HARDWARE_DEVICE_PATH ||\r
-        RemainingDevicePath->SubType != HW_VENDOR_DP ||\r
-        DevicePathNodeLength(RemainingDevicePath) != sizeof(WIN_NT_VENDOR_DEVICE_PATH_NODE)) {\r
-      return EFI_UNSUPPORTED;\r
-    }\r
-\r
-    for (Index = 0; Index < NT_PCD_ARRAY_SIZE; Index++) {\r
-      if (CompareGuid (&((VENDOR_DEVICE_PATH *) RemainingDevicePath)->Guid, mPcdEnvironment[Index].DevicePathGuid)) {\r
-        break;\r
+    //\r
+    // Check if RemainingDevicePath is the End of Device Path Node, \r
+    // if yes, go on checking other conditions\r
+    //\r
+    if (!IsDevicePathEnd (RemainingDevicePath)) {\r
+      //\r
+      // If RemainingDevicePath isn't the End of Device Path Node,\r
+      // check its validation\r
+      //\r
+      if (RemainingDevicePath->Type != HARDWARE_DEVICE_PATH ||\r
+          RemainingDevicePath->SubType != HW_VENDOR_DP ||\r
+          DevicePathNodeLength(RemainingDevicePath) != sizeof(WIN_NT_VENDOR_DEVICE_PATH_NODE)) {\r
+        return EFI_UNSUPPORTED;\r
+      }\r
+  \r
+      for (Index = 0; Index < NT_PCD_ARRAY_SIZE; Index++) {\r
+        if (CompareGuid (&((VENDOR_DEVICE_PATH *) RemainingDevicePath)->Guid, mPcdEnvironment[Index].DevicePathGuid)) {\r
+          break;\r
+        }\r
+      }\r
+  \r
+      if (Index >= NT_PCD_ARRAY_SIZE) {\r
+        return EFI_UNSUPPORTED;\r
       }\r
-    }\r
-\r
-    if (Index >= NT_PCD_ARRAY_SIZE) {\r
-      return EFI_UNSUPPORTED;\r
     }\r
   }\r
 \r
@@ -261,8 +272,8 @@ Returns:
   //\r
   Status = gBS->OpenProtocol (\r
                   ControllerHandle,\r
-                  &gEfiDevicePathProtocolGuid,\r
-                  (VOID **) &ParentDevicePath,\r
+                  &gEfiWinNtThunkProtocolGuid,\r
+                  (VOID **) &WinNtThunk,\r
                   This->DriverBindingHandle,\r
                   ControllerHandle,\r
                   EFI_OPEN_PROTOCOL_BY_DRIVER\r
@@ -275,17 +286,23 @@ Returns:
     return Status;\r
   }\r
 \r
+  //\r
+  // Close the I/O Abstraction(s) used to perform the supported test\r
+  //\r
   gBS->CloseProtocol (\r
         ControllerHandle,\r
-        &gEfiDevicePathProtocolGuid,\r
+        &gEfiWinNtThunkProtocolGuid,\r
         This->DriverBindingHandle,\r
         ControllerHandle\r
         );\r
 \r
+  //\r
+  // Open the EFI Device Path protocol needed to perform the supported test\r
+  //\r
   Status = gBS->OpenProtocol (\r
                   ControllerHandle,\r
-                  &gEfiWinNtThunkProtocolGuid,\r
-                  (VOID **) &WinNtThunk,\r
+                  &gEfiDevicePathProtocolGuid,\r
+                  (VOID **) &ParentDevicePath,\r
                   This->DriverBindingHandle,\r
                   ControllerHandle,\r
                   EFI_OPEN_PROTOCOL_BY_DRIVER\r
@@ -307,11 +324,11 @@ Returns:
   }\r
 \r
   //\r
-  // Close the I/O Abstraction(s) used to perform the supported test\r
+  // Close protocol, don't use device path protocol in the Support() function\r
   //\r
   gBS->CloseProtocol (\r
         ControllerHandle,\r
-        &gEfiWinNtThunkProtocolGuid,\r
+        &gEfiDevicePathProtocolGuid,\r
         This->DriverBindingHandle,\r
         ControllerHandle\r
         );\r
@@ -437,7 +454,7 @@ Returns:
     ASSERT (PcdTempStr != NULL);\r
 \r
     TempStrSize = StrLen (PcdTempStr);\r
-    TempStr = AllocateMemory ((TempStrSize * sizeof (CHAR16)) + 1);\r
+    TempStr = AllocateMemory (((TempStrSize + 1) * sizeof (CHAR16)));\r
     StrCpy (TempStr, PcdTempStr);\r
 \r
     StartString = TempStr;\r
@@ -470,15 +487,25 @@ Returns:
       CreateDevice = TRUE;\r
       if (RemainingDevicePath != NULL) {\r
         CreateDevice  = FALSE;\r
-        Node          = (WIN_NT_VENDOR_DEVICE_PATH_NODE *) RemainingDevicePath;\r
-        if (Node->VendorDevicePath.Header.Type == HARDWARE_DEVICE_PATH &&\r
-            Node->VendorDevicePath.Header.SubType == HW_VENDOR_DP &&\r
-            DevicePathNodeLength (&Node->VendorDevicePath.Header) == sizeof (WIN_NT_VENDOR_DEVICE_PATH_NODE)\r
-            ) {\r
-          if (CompareGuid (&Node->VendorDevicePath.Guid, mPcdEnvironment[Index].DevicePathGuid) &&\r
-              Node->Instance == Count\r
+        //\r
+        // Check if RemainingDevicePath is the End of Device Path Node, \r
+        // if yes, don't create any child device \r
+        //\r
+        if (!IsDevicePathEnd (RemainingDevicePath)) {\r
+          //\r
+          // If RemainingDevicePath isn't the End of Device Path Node,\r
+          // check its validation\r
+          //\r
+          Node          = (WIN_NT_VENDOR_DEVICE_PATH_NODE *) RemainingDevicePath;\r
+          if (Node->VendorDevicePath.Header.Type == HARDWARE_DEVICE_PATH &&\r
+              Node->VendorDevicePath.Header.SubType == HW_VENDOR_DP &&\r
+              DevicePathNodeLength (&Node->VendorDevicePath.Header) == sizeof (WIN_NT_VENDOR_DEVICE_PATH_NODE)\r
               ) {\r
-            CreateDevice = TRUE;\r
+            if (CompareGuid (&Node->VendorDevicePath.Guid, mPcdEnvironment[Index].DevicePathGuid) &&\r
+                Node->Instance == Count\r
+                ) {\r
+              CreateDevice = TRUE;\r
+            }\r
           }\r
         }\r
       }\r