]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Bus/Usb/UsbBusDxe/UsbEnumer.c
add assert logic to avoid Klocwork fake report
[mirror_edk2.git] / MdeModulePkg / Bus / Usb / UsbBusDxe / UsbEnumer.c
index 0b96394f2a1dd38ee50d805f4c6452b7501dcef6..eba9017e4c78d27862521223c9d5810bc6ad7e1c 100644 (file)
@@ -32,9 +32,12 @@ UsbGetEndpointDesc (
   )\r
 {\r
   USB_ENDPOINT_DESC       *EpDesc;\r
-  UINTN                   Index;\r
-\r
-  for (Index = 0; Index < UsbIf->IfSetting->Desc.NumEndpoints; Index++) {\r
+  UINT8                   Index;\r
+  UINT8                   NumEndpoints;\r
+  \r
+  NumEndpoints = UsbIf->IfSetting->Desc.NumEndpoints;\r
+  \r
+  for (Index = 0; Index < NumEndpoints; Index++) {\r
     EpDesc = UsbIf->IfSetting->Endpoints[Index];\r
 \r
     if (EpDesc->Desc.EndpointAddress == EpAddr) {\r
@@ -51,8 +54,6 @@ UsbGetEndpointDesc (
 \r
   @param  UsbIf                 The USB interface to free.\r
 \r
-  @return None.\r
-\r
 **/\r
 VOID\r
 UsbFreeInterface (\r
@@ -71,10 +72,10 @@ UsbFreeInterface (
          );\r
 \r
   if (UsbIf->DevicePath != NULL) {\r
-    gBS->FreePool (UsbIf->DevicePath);\r
+    FreePool (UsbIf->DevicePath);\r
   }\r
 \r
-  gBS->FreePool (UsbIf);\r
+  FreePool (UsbIf);\r
 }\r
 \r
 \r
@@ -108,6 +109,7 @@ UsbCreateInterface (
   UsbIf->Signature  = USB_INTERFACE_SIGNATURE;\r
   UsbIf->Device     = Device;\r
   UsbIf->IfDesc     = IfDesc;\r
+  ASSERT (IfDesc->ActiveIndex < USB_MAX_INTERFACE_SETTING);\r
   UsbIf->IfSetting  = IfDesc->Settings[IfDesc->ActiveIndex];\r
 \r
   CopyMem (\r
@@ -175,10 +177,10 @@ UsbCreateInterface (
 \r
 ON_ERROR:\r
   if (UsbIf->DevicePath != NULL) {\r
-    gBS->FreePool (UsbIf->DevicePath);\r
+    FreePool (UsbIf->DevicePath);\r
   }\r
 \r
-  gBS->FreePool (UsbIf);\r
+  FreePool (UsbIf);\r
   return NULL;\r
 }\r
 \r
@@ -188,8 +190,6 @@ ON_ERROR:
 \r
   @param  Device                The USB device to free.\r
 \r
-  @return None.\r
-\r
 **/\r
 VOID\r
 UsbFreeDevice (\r
@@ -240,7 +240,7 @@ UsbCreateDevice (
 \r
 /**\r
   Connect the USB interface with its driver. EFI USB bus will\r
-  create a USB interface for each seperate interface descriptor.\r
+  create a USB interface for each separate interface descriptor.\r
 \r
   @param  UsbIf             The interface to connect driver to.\r
 \r
@@ -280,7 +280,7 @@ UsbConnectDriver (
     //\r
     if (UsbBusIsWantedUsbIO (UsbIf->Device->Bus, UsbIf)) {\r
       OldTpl            = UsbGetCurrentTpl ();\r
-      DEBUG ((EFI_D_INFO, "UsbConnectDriver: TPL before connect is %d\n", (UINT32)OldTpl));\r
+      DEBUG ((EFI_D_INFO, "UsbConnectDriver: TPL before connect is %d, %p\n", (UINT32)OldTpl, UsbIf->Handle));\r
 \r
       gBS->RestoreTPL (TPL_CALLBACK);\r
 \r
@@ -326,6 +326,7 @@ UsbSelectSetting (
   Setting = NULL;\r
 \r
   for (Index = 0; Index < IfDesc->NumOfSetting; Index++) {\r
+    ASSERT (Index < USB_MAX_INTERFACE_SETTING);\r
     Setting = IfDesc->Settings[Index];\r
 \r
     if (Setting->Desc.AlternateSetting == Alternate) {\r
@@ -339,6 +340,7 @@ UsbSelectSetting (
 \r
   IfDesc->ActiveIndex = Index;\r
 \r
+  ASSERT (Setting != NULL);\r
   DEBUG ((EFI_D_INFO, "UsbSelectSetting: setting %d selected for interface %d\n",\r
               Alternate, Setting->Desc.InterfaceNumber));\r
 \r
@@ -421,6 +423,7 @@ UsbSelectConfig (
       return EFI_OUT_OF_RESOURCES;\r
     }\r
 \r
+    ASSERT (Index < USB_MAX_INTERFACE);\r
     Device->Interfaces[Index] = UsbIf;\r
 \r
     //\r
@@ -446,8 +449,6 @@ UsbSelectConfig (
 \r
   @param  UsbIf                 The interface to disconnect driver from.\r
 \r
-  @return None.\r
-\r
 **/\r
 VOID\r
 UsbDisconnectDriver (\r
@@ -455,6 +456,7 @@ UsbDisconnectDriver (
   )\r
 {\r
   EFI_TPL                 OldTpl;\r
+  EFI_STATUS              Status;\r
 \r
   //\r
   // Release the hub if it's a hub controller, otherwise\r
@@ -472,14 +474,14 @@ UsbDisconnectDriver (
     // or disconnect at CALLBACK.\r
     //\r
     OldTpl           = UsbGetCurrentTpl ();\r
-    DEBUG ((EFI_D_INFO, "UsbDisconnectDriver: old TPL is %d\n", (UINT32)OldTpl));\r
+    DEBUG ((EFI_D_INFO, "UsbDisconnectDriver: old TPL is %d, %p\n", (UINT32)OldTpl, UsbIf->Handle));\r
 \r
     gBS->RestoreTPL (TPL_CALLBACK);\r
 \r
-    gBS->DisconnectController (UsbIf->Handle, NULL, NULL);\r
+    Status = gBS->DisconnectController (UsbIf->Handle, NULL, NULL);\r
     UsbIf->IsManaged = FALSE;\r
 \r
-    DEBUG (( EFI_D_INFO, "UsbDisconnectDriver: TPL after disconnect is %d\n", (UINT32)UsbGetCurrentTpl()));\r
+    DEBUG (( EFI_D_INFO, "UsbDisconnectDriver: TPL after disconnect is %d, %d\n", (UINT32)UsbGetCurrentTpl(), Status));\r
     ASSERT (UsbGetCurrentTpl () == TPL_CALLBACK);\r
 \r
     gBS->RaiseTPL (OldTpl);\r
@@ -492,8 +494,6 @@ UsbDisconnectDriver (
 \r
   @param  Device                The USB device to remove configuration from.\r
 \r
-  @return None.\r
-\r
 **/\r
 VOID\r
 UsbRemoveConfig (\r
@@ -506,7 +506,8 @@ UsbRemoveConfig (
   //\r
   // Remove each interface of the device\r
   //\r
-  for (Index = 0; Index < Device->NumOfInterface; Index++) {\r
+  for (Index = 0; Index < Device->NumOfInterface; Index++) {    \r
+    ASSERT (Index < USB_MAX_INTERFACE);\r
     UsbIf = Device->Interfaces[Index];\r
 \r
     if (UsbIf == NULL) {\r
@@ -566,6 +567,7 @@ UsbRemoveDevice (
 \r
   DEBUG (( EFI_D_INFO, "UsbRemoveDevice: device %d removed\n", Device->Address));\r
 \r
+  ASSERT (Device->Address < USB_MAX_DEVICES);\r
   Bus->Devices[Device->Address] = NULL;\r
   UsbFreeDevice (Device);\r
 \r
@@ -905,7 +907,7 @@ UsbEnumeratePort (
   Child = UsbFindChild (HubIf, Port);\r
   \r
   if (Child != NULL) {\r
-    DEBUG (( EFI_D_INFO, "UsbEnumeratePort: device at port %d removed from system\n", Port));\r
+    DEBUG (( EFI_D_INFO, "UsbEnumeratePort: device at port %d removed from root hub %p\n", Port, HubIf));\r
     UsbRemoveDevice (Child);\r
   }\r
   \r
@@ -931,8 +933,6 @@ UsbEnumeratePort (
   @param  Event                 The event that is triggered.\r
   @param  Context               The context to the event.\r
 \r
-  @return None.\r
-\r
 **/\r
 VOID\r
 EFIAPI\r
@@ -946,7 +946,7 @@ UsbHubEnumeration (
   UINT8                   Bit;\r
   UINT8                   Index;\r
 \r
-  ASSERT (Context);\r
+  ASSERT (Context != NULL);\r
 \r
   HubIf = (USB_INTERFACE *) Context;\r
 \r
@@ -982,8 +982,6 @@ UsbHubEnumeration (
   @param  Event                 The event that is triggered.\r
   @param  Context               The context to the event.\r
 \r
-  @return None.\r
-\r
 **/\r
 VOID\r
 EFIAPI\r