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
This commit is contained in:
vanjeff 2007-11-28 03:55:36 +00:00
parent ac4f8b5abe
commit 6a6d955c5f
5 changed files with 291 additions and 266 deletions

View File

@ -1496,6 +1496,7 @@ EhcDriverBindingStart (
EFI_PCI_IO_PROTOCOL *PciIo; EFI_PCI_IO_PROTOCOL *PciIo;
UINT64 Supports; UINT64 Supports;
UINT64 OriginalPciAttributes; UINT64 OriginalPciAttributes;
BOOLEAN PciAttributesSaved;
// //
// Open the PciIo Protocol, then enable the USB host controller // Open the PciIo Protocol, then enable the USB host controller
@ -1514,6 +1515,7 @@ EhcDriverBindingStart (
return EFI_DEVICE_ERROR; return EFI_DEVICE_ERROR;
} }
PciAttributesSaved = FALSE;
// //
// Save original PCI attributes // Save original PCI attributes
// //
@ -1525,8 +1527,9 @@ EhcDriverBindingStart (
); );
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
return Status; goto CLOSE_PCIIO;
} }
PciAttributesSaved = TRUE;
Status = PciIo->Attributes ( Status = PciIo->Attributes (
PciIo, PciIo,
@ -1634,15 +1637,17 @@ FREE_POOL:
gBS->FreePool (Ehc); gBS->FreePool (Ehc);
CLOSE_PCIIO: CLOSE_PCIIO:
// if (PciAttributesSaved == TRUE) {
// Restore original PCI attributes //
// // Restore original PCI attributes
PciIo->Attributes ( //
PciIo, PciIo->Attributes (
EfiPciIoAttributeOperationSet, PciIo,
OriginalPciAttributes, EfiPciIoAttributeOperationSet,
NULL OriginalPciAttributes,
); NULL
);
}
gBS->CloseProtocol ( gBS->CloseProtocol (
Controller, Controller,

View File

@ -2133,6 +2133,7 @@ UhciDriverBindingStart (
USB_HC_DEV *Uhc; USB_HC_DEV *Uhc;
UINT64 Supports; UINT64 Supports;
UINT64 OriginalPciAttributes; UINT64 OriginalPciAttributes;
BOOLEAN PciAttributesSaved;
// //
// Open PCIIO, then enable the EHC device and turn off emulation // Open PCIIO, then enable the EHC device and turn off emulation
@ -2151,6 +2152,7 @@ UhciDriverBindingStart (
return Status; return Status;
} }
PciAttributesSaved = FALSE;
// //
// Save original PCI attributes // Save original PCI attributes
// //
@ -2162,8 +2164,9 @@ UhciDriverBindingStart (
); );
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
return Status; goto CLOSE_PCIIO;
} }
PciAttributesSaved = TRUE;
UhciTurnOffUsbEmulation (PciIo); UhciTurnOffUsbEmulation (PciIo);
@ -2262,15 +2265,17 @@ FREE_UHC:
UhciFreeDev (Uhc); UhciFreeDev (Uhc);
CLOSE_PCIIO: CLOSE_PCIIO:
// if (PciAttributesSaved == TRUE) {
// Restore original PCI attributes //
// // Restore original PCI attributes
PciIo->Attributes ( //
PciIo, PciIo->Attributes (
EfiPciIoAttributeOperationSet, PciIo,
OriginalPciAttributes, EfiPciIoAttributeOperationSet,
NULL OriginalPciAttributes,
); NULL
);
}
gBS->CloseProtocol ( gBS->CloseProtocol (
Controller, Controller,

View File

@ -287,6 +287,7 @@ Returns:
EFI_PCI_IO_PROTOCOL *PciIoFncs; EFI_PCI_IO_PROTOCOL *PciIoFncs;
UINTN Len; UINTN Len;
UINT64 Supports; UINT64 Supports;
BOOLEAN PciAttributesSaved;
Status = gBS->OpenProtocol ( Status = gBS->OpenProtocol (
Controller, Controller,
@ -321,6 +322,8 @@ Returns:
return Status; return Status;
} }
PciAttributesSaved = FALSE;
Status = gBS->AllocatePool ( Status = gBS->AllocatePool (
EfiRuntimeServicesData, EfiRuntimeServicesData,
sizeof (UNDI32_DEV), sizeof (UNDI32_DEV),
@ -344,8 +347,9 @@ Returns:
); );
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
return Status; goto UndiErrorDeleteDevice;
} }
PciAttributesSaved = TRUE;
// //
// allocate and initialize both (old and new) the !pxe structures here, // allocate and initialize both (old and new) the !pxe structures here,
@ -550,15 +554,17 @@ UndiErrorDeletePxe:
} }
UndiErrorDeleteDevice: UndiErrorDeleteDevice:
// if (PciAttributesSaved == TRUE) {
// Restore original PCI attributes //
// // Restore original PCI attributes
PciIoFncs->Attributes ( //
PciIoFncs, PciIoFncs->Attributes (
EfiPciIoAttributeOperationSet, PciIoFncs,
UNDI32Device->NicInfo.OriginalPciAttributes, EfiPciIoAttributeOperationSet,
NULL UNDI32Device->NicInfo.OriginalPciAttributes,
); NULL
);
}
gBS->FreePool (UNDI32Device); gBS->FreePool (UNDI32Device);

View File

@ -206,6 +206,7 @@ Returns:
EFI_PCI_IO_PROTOCOL *PciIo; EFI_PCI_IO_PROTOCOL *PciIo;
UINT64 Supports; UINT64 Supports;
UINT64 OriginalPciAttributes; UINT64 OriginalPciAttributes;
BOOLEAN PciAttributesSaved;
PciIo = NULL; PciIo = NULL;
Status = gBS->OpenProtocol ( Status = gBS->OpenProtocol (
@ -220,6 +221,7 @@ Returns:
return Status; return Status;
} }
PciAttributesSaved = FALSE;
// //
// Save original PCI attributes // Save original PCI attributes
// //
@ -231,8 +233,9 @@ Returns:
); );
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
return Status; goto Done;
} }
PciAttributesSaved = TRUE;
Status = PciIo->Attributes ( Status = PciIo->Attributes (
PciIo, PciIo,
@ -262,15 +265,17 @@ Returns:
Done: Done:
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
// if (PciAttributesSaved == TRUE) {
// Restore original PCI attributes //
// // Restore original PCI attributes
PciIo->Attributes ( //
PciIo, PciIo->Attributes (
EfiPciIoAttributeOperationSet, PciIo,
OriginalPciAttributes, EfiPciIoAttributeOperationSet,
NULL OriginalPciAttributes,
); NULL
);
}
gBS->CloseProtocol ( gBS->CloseProtocol (
Controller, Controller,

View File

@ -211,7 +211,9 @@ CirrusLogic5430ControllerDriverStart (
{ {
EFI_STATUS Status; EFI_STATUS Status;
CIRRUS_LOGIC_5430_PRIVATE_DATA *Private; CIRRUS_LOGIC_5430_PRIVATE_DATA *Private;
BOOLEAN PciAttributesSaved;
PciAttributesSaved = FALSE;
// //
// Allocate Private context data for UGA Draw inteface. // Allocate Private context data for UGA Draw inteface.
// //
@ -255,6 +257,7 @@ CirrusLogic5430ControllerDriverStart (
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
goto Error; goto Error;
} }
PciAttributesSaved = TRUE;
Status = Private->PciIo->Attributes ( Status = Private->PciIo->Attributes (
Private->PciIo, Private->PciIo,
@ -319,16 +322,17 @@ Error:
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
if (Private) { if (Private) {
if (Private->PciIo) { if (Private->PciIo) {
// if (PciAttributesSaved == TRUE) {
// Restore original PCI attributes //
// // Restore original PCI attributes
Private->PciIo->Attributes ( //
Private->PciIo, Private->PciIo->Attributes (
EfiPciIoAttributeOperationSet, Private->PciIo,
Private->OriginalPciAttributes, EfiPciIoAttributeOperationSet,
NULL Private->OriginalPciAttributes,
); NULL
);
}
// //
// Close the PCI I/O Protocol // Close the PCI I/O Protocol
// //