From 6a6d955c5f670141344c614c65dbea332f393b57 Mon Sep 17 00:00:00 2001 From: vanjeff Date: Wed, 28 Nov 2007 03:55:36 +0000 Subject: Fixed potential issues to release resources when error occurs. git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@4341 6f19259b-4bc3-4df7-8a09-765794883524 --- MdeModulePkg/Bus/Pci/EhciDxe/Ehci.c | 25 +++++++++++++++---------- MdeModulePkg/Bus/Pci/UhciDxe/Uhci.c | 25 +++++++++++++++---------- MdeModulePkg/Bus/Pci/UndiRuntimeDxe/Init.c | 26 ++++++++++++++++---------- 3 files changed, 46 insertions(+), 30 deletions(-) (limited to 'MdeModulePkg/Bus/Pci') diff --git a/MdeModulePkg/Bus/Pci/EhciDxe/Ehci.c b/MdeModulePkg/Bus/Pci/EhciDxe/Ehci.c index 32ae6b6cdc..e37cf719d7 100644 --- a/MdeModulePkg/Bus/Pci/EhciDxe/Ehci.c +++ b/MdeModulePkg/Bus/Pci/EhciDxe/Ehci.c @@ -1496,6 +1496,7 @@ EhcDriverBindingStart ( EFI_PCI_IO_PROTOCOL *PciIo; UINT64 Supports; UINT64 OriginalPciAttributes; + BOOLEAN PciAttributesSaved; // // Open the PciIo Protocol, then enable the USB host controller @@ -1514,6 +1515,7 @@ EhcDriverBindingStart ( return EFI_DEVICE_ERROR; } + PciAttributesSaved = FALSE; // // Save original PCI attributes // @@ -1525,8 +1527,9 @@ EhcDriverBindingStart ( ); if (EFI_ERROR (Status)) { - return Status; + goto CLOSE_PCIIO; } + PciAttributesSaved = TRUE; Status = PciIo->Attributes ( PciIo, @@ -1634,15 +1637,17 @@ FREE_POOL: gBS->FreePool (Ehc); CLOSE_PCIIO: - // - // Restore original PCI attributes - // - PciIo->Attributes ( - PciIo, - EfiPciIoAttributeOperationSet, - OriginalPciAttributes, - NULL - ); + if (PciAttributesSaved == TRUE) { + // + // Restore original PCI attributes + // + PciIo->Attributes ( + PciIo, + EfiPciIoAttributeOperationSet, + OriginalPciAttributes, + NULL + ); + } gBS->CloseProtocol ( Controller, diff --git a/MdeModulePkg/Bus/Pci/UhciDxe/Uhci.c b/MdeModulePkg/Bus/Pci/UhciDxe/Uhci.c index 82142b6a85..b52510041f 100644 --- a/MdeModulePkg/Bus/Pci/UhciDxe/Uhci.c +++ b/MdeModulePkg/Bus/Pci/UhciDxe/Uhci.c @@ -2133,6 +2133,7 @@ UhciDriverBindingStart ( USB_HC_DEV *Uhc; UINT64 Supports; UINT64 OriginalPciAttributes; + BOOLEAN PciAttributesSaved; // // Open PCIIO, then enable the EHC device and turn off emulation @@ -2151,6 +2152,7 @@ UhciDriverBindingStart ( return Status; } + PciAttributesSaved = FALSE; // // Save original PCI attributes // @@ -2162,8 +2164,9 @@ UhciDriverBindingStart ( ); if (EFI_ERROR (Status)) { - return Status; + goto CLOSE_PCIIO; } + PciAttributesSaved = TRUE; UhciTurnOffUsbEmulation (PciIo); @@ -2262,15 +2265,17 @@ FREE_UHC: UhciFreeDev (Uhc); CLOSE_PCIIO: - // - // Restore original PCI attributes - // - PciIo->Attributes ( - PciIo, - EfiPciIoAttributeOperationSet, - OriginalPciAttributes, - NULL - ); + if (PciAttributesSaved == TRUE) { + // + // Restore original PCI attributes + // + PciIo->Attributes ( + PciIo, + EfiPciIoAttributeOperationSet, + OriginalPciAttributes, + NULL + ); + } gBS->CloseProtocol ( Controller, diff --git a/MdeModulePkg/Bus/Pci/UndiRuntimeDxe/Init.c b/MdeModulePkg/Bus/Pci/UndiRuntimeDxe/Init.c index b79c5fe7a6..413ef32a7a 100644 --- a/MdeModulePkg/Bus/Pci/UndiRuntimeDxe/Init.c +++ b/MdeModulePkg/Bus/Pci/UndiRuntimeDxe/Init.c @@ -287,6 +287,7 @@ Returns: EFI_PCI_IO_PROTOCOL *PciIoFncs; UINTN Len; UINT64 Supports; + BOOLEAN PciAttributesSaved; Status = gBS->OpenProtocol ( Controller, @@ -321,6 +322,8 @@ Returns: return Status; } + PciAttributesSaved = FALSE; + Status = gBS->AllocatePool ( EfiRuntimeServicesData, sizeof (UNDI32_DEV), @@ -344,8 +347,9 @@ Returns: ); if (EFI_ERROR (Status)) { - return Status; + goto UndiErrorDeleteDevice; } + PciAttributesSaved = TRUE; // // allocate and initialize both (old and new) the !pxe structures here, @@ -550,15 +554,17 @@ UndiErrorDeletePxe: } UndiErrorDeleteDevice: - // - // Restore original PCI attributes - // - PciIoFncs->Attributes ( - PciIoFncs, - EfiPciIoAttributeOperationSet, - UNDI32Device->NicInfo.OriginalPciAttributes, - NULL - ); + if (PciAttributesSaved == TRUE) { + // + // Restore original PCI attributes + // + PciIoFncs->Attributes ( + PciIoFncs, + EfiPciIoAttributeOperationSet, + UNDI32Device->NicInfo.OriginalPciAttributes, + NULL + ); + } gBS->FreePool (UNDI32Device); -- cgit v1.2.3