From a1b749d074ef44e758458cf16e460dd74e3df123 Mon Sep 17 00:00:00 2001 From: eric_tian Date: Thu, 12 Feb 2009 06:23:15 +0000 Subject: add assert logic to avoid Klocwork fake report git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@7511 6f19259b-4bc3-4df7-8a09-765794883524 --- MdeModulePkg/Bus/Usb/UsbBusDxe/UsbBus.c | 4 ++++ MdeModulePkg/Bus/Usb/UsbBusDxe/UsbEnumer.c | 18 ++++++++++++------ MdeModulePkg/Bus/Usb/UsbBusDxe/UsbUtility.c | 2 ++ 3 files changed, 18 insertions(+), 6 deletions(-) (limited to 'MdeModulePkg/Bus/Usb/UsbBusDxe') diff --git a/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbBus.c b/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbBus.c index b2a70d1381..d0def777bd 100644 --- a/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbBus.c +++ b/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbBus.c @@ -111,6 +111,7 @@ UsbIoControlTransfer ( // Clear TT buffer when CTRL/BULK split transaction failes // Clear the TRANSLATOR TT buffer, not parent's buffer // + ASSERT (Dev->Translator.TranslatorHubAddress < USB_MAX_DEVICES); if (Dev->Translator.TranslatorHubAddress != 0) { UsbHubCtrlClearTTBuffer ( Dev->Bus->Devices[Dev->Translator.TranslatorHubAddress], @@ -195,6 +196,7 @@ UsbIoControlTransfer ( Status = UsbSelectSetting (UsbIf->IfDesc, (UINT8) Request->Value); if (!EFI_ERROR (Status)) { + ASSERT (UsbIf->IfDesc->ActiveIndex < USB_MAX_INTERFACE_SETTING); UsbIf->IfSetting = UsbIf->IfDesc->Settings[UsbIf->IfDesc->ActiveIndex]; } } @@ -282,6 +284,7 @@ UsbIoBulkTransfer ( // Clear TT buffer when CTRL/BULK split transaction failes. // Clear the TRANSLATOR TT buffer, not parent's buffer // + ASSERT (Dev->Translator.TranslatorHubAddress < USB_MAX_DEVICES); if (Dev->Translator.TranslatorHubAddress != 0) { UsbHubCtrlClearTTBuffer ( Dev->Bus->Devices[Dev->Translator.TranslatorHubAddress], @@ -751,6 +754,7 @@ UsbIoGetStringDescriptor ( Status = EFI_NOT_FOUND; for (Index = 0; Index < Dev->TotalLangId; Index++) { + ASSERT (Index < USB_MAX_LANG_ID); if (Dev->LangId[Index] == LangID) { break; } diff --git a/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbEnumer.c b/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbEnumer.c index 4c2e5ffa65..0577167816 100644 --- a/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbEnumer.c +++ b/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbEnumer.c @@ -109,6 +109,7 @@ UsbCreateInterface ( UsbIf->Signature = USB_INTERFACE_SIGNATURE; UsbIf->Device = Device; UsbIf->IfDesc = IfDesc; + ASSERT (IfDesc->ActiveIndex < USB_MAX_INTERFACE_SETTING); UsbIf->IfSetting = IfDesc->Settings[IfDesc->ActiveIndex]; CopyMem ( @@ -279,7 +280,7 @@ UsbConnectDriver ( // if (UsbBusIsWantedUsbIO (UsbIf->Device->Bus, UsbIf)) { OldTpl = UsbGetCurrentTpl (); - DEBUG ((EFI_D_INFO, "UsbConnectDriver: TPL before connect is %d\n", (UINT32)OldTpl)); + DEBUG ((EFI_D_INFO, "UsbConnectDriver: TPL before connect is %d, %p\n", (UINT32)OldTpl, UsbIf->Handle)); gBS->RestoreTPL (TPL_CALLBACK); @@ -325,6 +326,7 @@ UsbSelectSetting ( Setting = NULL; for (Index = 0; Index < IfDesc->NumOfSetting; Index++) { + ASSERT (Index < USB_MAX_INTERFACE_SETTING); Setting = IfDesc->Settings[Index]; if (Setting->Desc.AlternateSetting == Alternate) { @@ -420,6 +422,7 @@ UsbSelectConfig ( return EFI_OUT_OF_RESOURCES; } + ASSERT (Index < USB_MAX_INTERFACE); Device->Interfaces[Index] = UsbIf; // @@ -452,6 +455,7 @@ UsbDisconnectDriver ( ) { EFI_TPL OldTpl; + EFI_STATUS Status; // // Release the hub if it's a hub controller, otherwise @@ -469,14 +473,14 @@ UsbDisconnectDriver ( // or disconnect at CALLBACK. // OldTpl = UsbGetCurrentTpl (); - DEBUG ((EFI_D_INFO, "UsbDisconnectDriver: old TPL is %d\n", (UINT32)OldTpl)); + DEBUG ((EFI_D_INFO, "UsbDisconnectDriver: old TPL is %d, %p\n", (UINT32)OldTpl, UsbIf->Handle)); gBS->RestoreTPL (TPL_CALLBACK); - gBS->DisconnectController (UsbIf->Handle, NULL, NULL); + Status = gBS->DisconnectController (UsbIf->Handle, NULL, NULL); UsbIf->IsManaged = FALSE; - DEBUG (( EFI_D_INFO, "UsbDisconnectDriver: TPL after disconnect is %d\n", (UINT32)UsbGetCurrentTpl())); + DEBUG (( EFI_D_INFO, "UsbDisconnectDriver: TPL after disconnect is %d, %d\n", (UINT32)UsbGetCurrentTpl(), Status)); ASSERT (UsbGetCurrentTpl () == TPL_CALLBACK); gBS->RaiseTPL (OldTpl); @@ -501,7 +505,8 @@ UsbRemoveConfig ( // // Remove each interface of the device // - for (Index = 0; Index < Device->NumOfInterface; Index++) { + for (Index = 0; Index < Device->NumOfInterface; Index++) { + ASSERT (Index < USB_MAX_INTERFACE); UsbIf = Device->Interfaces[Index]; if (UsbIf == NULL) { @@ -561,6 +566,7 @@ UsbRemoveDevice ( DEBUG (( EFI_D_INFO, "UsbRemoveDevice: device %d removed\n", Device->Address)); + ASSERT (Device->Address < USB_MAX_DEVICES); Bus->Devices[Device->Address] = NULL; UsbFreeDevice (Device); @@ -900,7 +906,7 @@ UsbEnumeratePort ( Child = UsbFindChild (HubIf, Port); if (Child != NULL) { - DEBUG (( EFI_D_INFO, "UsbEnumeratePort: device at port %d removed from system\n", Port)); + DEBUG (( EFI_D_INFO, "UsbEnumeratePort: device at port %d removed from root hub %p\n", Port, HubIf)); UsbRemoveDevice (Child); } diff --git a/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbUtility.c b/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbUtility.c index 2d2bd2a154..c59565fd1e 100644 --- a/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbUtility.c +++ b/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbUtility.c @@ -928,6 +928,7 @@ MatchUsbClass ( } IfDesc = UsbIf->IfDesc; + ASSERT (IfDesc->ActiveIndex < USB_MAX_INTERFACE_SETTING); ActIfDesc = &(IfDesc->Settings[IfDesc->ActiveIndex]->Desc); DevDesc = &(UsbIf->Device->DevDesc->Desc); @@ -1008,6 +1009,7 @@ MatchUsbWwid ( } IfDesc = UsbIf->IfDesc; + ASSERT (IfDesc->ActiveIndex < USB_MAX_INTERFACE_SETTING); ActIfDesc = &(IfDesc->Settings[IfDesc->ActiveIndex]->Desc); DevDesc = &(UsbIf->Device->DevDesc->Desc); StrDesc = UsbGetOneString (UsbIf->Device, DevDesc->StrSerialNumber, USB_US_LAND_ID); -- cgit v1.2.3