]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Bus/Usb/UsbBusDxe/UsbEnumer.c
1) remove wrong global variable usage because it will bring data corrupt if there...
[mirror_edk2.git] / MdeModulePkg / Bus / Usb / UsbBusDxe / UsbEnumer.c
index aacc67fef1896d57d06d2f4c038ada04a1642687..b7141a0ab334a55663c95806a918cdf378c463bd 100644 (file)
@@ -548,7 +548,7 @@ UsbRemoveDevice (
   // Remove all the devices on its downstream ports. Search from devices[1].\r
   // Devices[0] is the root hub.\r
   //\r
-  for (Index = 1; Index < mMaxUsbDeviceNum; Index++) {\r
+  for (Index = 1; Index < Bus->MaxDevices; Index++) {\r
     Child = Bus->Devices[Index];\r
 \r
     if ((Child == NULL) || (Child->ParentAddr != Device->Address)) {\r
@@ -567,7 +567,7 @@ UsbRemoveDevice (
 \r
   DEBUG (( EFI_D_INFO, "UsbRemoveDevice: device %d removed\n", Device->Address));\r
 \r
-  ASSERT (Device->Address < mMaxUsbDeviceNum);\r
+  ASSERT (Device->Address < Bus->MaxDevices);\r
   Bus->Devices[Device->Address] = NULL;\r
   UsbFreeDevice (Device);\r
 \r
@@ -599,7 +599,7 @@ UsbFindChild (
   //\r
   // Start checking from device 1, device 0 is the root hub\r
   //\r
-  for (Index = 1; Index < mMaxUsbDeviceNum; Index++) {\r
+  for (Index = 1; Index < Bus->MaxDevices; Index++) {\r
     Device = Bus->Devices[Index];\r
 \r
     if ((Device != NULL) && (Device->ParentAddr == HubIf->Device->Address) &&\r
@@ -639,11 +639,11 @@ UsbEnumerateNewDev (
   UINT8                   Config;\r
   EFI_STATUS              Status;\r
 \r
-  Address = mMaxUsbDeviceNum;\r
   Parent  = HubIf->Device;\r
   Bus     = Parent->Bus;\r
-  HubApi  = HubIf->HubApi;\r
-  \r
+  HubApi  = HubIf->HubApi;  \r
+  Address = Bus->MaxDevices;\r
+\r
   gBS->Stall (USB_WAIT_PORT_STABLE_STALL);\r
   \r
   //\r
@@ -731,13 +731,14 @@ UsbEnumerateNewDev (
   // status stage with default address, then switches to new address.\r
   // ADDRESS state. Address zero is reserved for root hub.\r
   //\r
-  for (Address = 1; Address < mMaxUsbDeviceNum; Address++) {\r
+  ASSERT (Bus->MaxDevices <= 256);\r
+  for (Address = 1; Address < Bus->MaxDevices; Address++) {\r
     if (Bus->Devices[Address] == NULL) {\r
       break;\r
     }\r
   }\r
 \r
-  if (Address == mMaxUsbDeviceNum) {\r
+  if (Address >= Bus->MaxDevices) {\r
     DEBUG ((EFI_D_ERROR, "UsbEnumerateNewDev: address pool is full for port %d\n", Port));\r
 \r
     Status = EFI_ACCESS_DENIED;\r
@@ -808,7 +809,7 @@ UsbEnumerateNewDev (
   return EFI_SUCCESS;\r
 \r
 ON_ERROR:\r
-  if (Address != mMaxUsbDeviceNum) {\r
+  if (Address != Bus->MaxDevices) {\r
     Bus->Devices[Address] = NULL;\r
   }\r
 \r