From 73f8ef8c086a60391647259dfcd853ab30b7b995 Mon Sep 17 00:00:00 2001 From: eric_tian Date: Wed, 19 Aug 2009 02:32:56 +0000 Subject: add error handler in return places. git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@9119 6f19259b-4bc3-4df7-8a09-765794883524 --- .../Bus/Usb/UsbMassStorageDxe/UsbMassImpl.c | 67 ++++++++++++++++------ 1 file changed, 51 insertions(+), 16 deletions(-) (limited to 'MdeModulePkg/Bus/Usb') diff --git a/MdeModulePkg/Bus/Usb/UsbMassStorageDxe/UsbMassImpl.c b/MdeModulePkg/Bus/Usb/UsbMassStorageDxe/UsbMassImpl.c index f80895bda4..2db5f11c63 100644 --- a/MdeModulePkg/Bus/Usb/UsbMassStorageDxe/UsbMassImpl.c +++ b/MdeModulePkg/Bus/Usb/UsbMassStorageDxe/UsbMassImpl.c @@ -712,12 +712,14 @@ ON_ERROR: if (UsbMass != NULL) { FreePool (UsbMass); } - gBS->CloseProtocol ( - Controller, - &gEfiUsbIoProtocolGuid, - This->DriverBindingHandle, - Controller - ); + if (UsbIo != NULL) { + gBS->CloseProtocol ( + Controller, + &gEfiUsbIoProtocolGuid, + This->DriverBindingHandle, + Controller + ); + } return Status; } @@ -830,6 +832,7 @@ USBMassDriverBindingStart ( VOID *Context; UINT8 MaxLun; EFI_STATUS Status; + EFI_USB_IO_PROTOCOL *UsbIo; Transport = NULL; Context = NULL; @@ -867,18 +870,44 @@ USBMassDriverBindingStart ( return Status; } + Status = gBS->OpenProtocol ( + Controller, + &gEfiUsbIoProtocolGuid, + (VOID **) &UsbIo, + This->DriverBindingHandle, + Controller, + EFI_OPEN_PROTOCOL_BY_DRIVER + ); + + if (EFI_ERROR (Status)) { + DEBUG ((EFI_D_ERROR, "USBMassDriverBindingStart: OpenUsbIoProtocol By Driver (%r)\n", Status)); + gBS->CloseProtocol ( + Controller, + &gEfiDevicePathProtocolGuid, + This->DriverBindingHandle, + Controller + ); + return Status; + } + // // Initialize data for device that supports multiple LUNSs. // EFI_SUCCESS is returned if at least 1 LUN is initialized successfully. // Status = UsbMassInitMultiLun (This, Controller, Transport, Context, DevicePath, MaxLun); if (EFI_ERROR (Status)) { - gBS->CloseProtocol ( - Controller, - &gEfiDevicePathProtocolGuid, - This->DriverBindingHandle, - Controller - ); + gBS->CloseProtocol ( + Controller, + &gEfiDevicePathProtocolGuid, + This->DriverBindingHandle, + Controller + ); + gBS->CloseProtocol ( + Controller, + &gEfiUsbIoProtocolGuid, + This->DriverBindingHandle, + Controller + ); DEBUG ((EFI_D_ERROR, "USBMassDriverBindingStart: UsbMassInitMultiLun (%r) with Maxlun=%d\n", Status, MaxLun)); } } @@ -919,9 +948,9 @@ USBMassDriverBindingStop ( // // This is a bus driver stop function since multi-lun is supported. // There are three kinds of device handles that might be passed: - // 1st is a handle with Device Path & USB I/O & Block I/O installed (non-multi-lun) + // 1st is a handle with USB I/O & Block I/O installed (non-multi-lun) // 2nd is a handle with Device Path & USB I/O installed (multi-lun root) - // 3rd is a handle with Device Path & Block I/O installed (multi-lun). + // 3rd is a handle with Device Path & USB I/O & Block I/O installed (multi-lun). // if (NumberOfChildren == 0) { // @@ -938,8 +967,8 @@ USBMassDriverBindingStop ( if (EFI_ERROR(Status)) { // - // This is a 2nd type handle(multi-lun root), which only needs to close - // Device Path Protocol. + // This is a 2nd type handle(multi-lun root), it needs to close devicepath + // and usbio protocol. // gBS->CloseProtocol ( Controller, @@ -947,6 +976,12 @@ USBMassDriverBindingStop ( This->DriverBindingHandle, Controller ); + gBS->CloseProtocol ( + Controller, + &gEfiUsbIoProtocolGuid, + This->DriverBindingHandle, + Controller + ); DEBUG ((EFI_D_INFO, "Success to stop multi-lun root handle\n")); return EFI_SUCCESS; } -- cgit v1.2.3