From c8c2e4d61339592056931dff5c209b7d06fb466c Mon Sep 17 00:00:00 2001 From: jljusten Date: Thu, 18 Oct 2012 17:07:24 +0000 Subject: [PATCH] OvmfPkg: VirtioBlkDriverBindingStop: fix incorrect use of UEFI driver model Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Laszlo Ersek Reviewed-by: Jordan Justen git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@13866 6f19259b-4bc3-4df7-8a09-765794883524 --- OvmfPkg/VirtioBlkDxe/VirtioBlk.c | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/OvmfPkg/VirtioBlkDxe/VirtioBlk.c b/OvmfPkg/VirtioBlkDxe/VirtioBlk.c index 199b9dd0ae..b2bfcdf7b7 100644 --- a/OvmfPkg/VirtioBlkDxe/VirtioBlk.c +++ b/OvmfPkg/VirtioBlkDxe/VirtioBlk.c @@ -944,18 +944,32 @@ VirtioBlkDriverBindingStop ( IN EFI_HANDLE *ChildHandleBuffer ) { - VBLK_DEV *Dev; - EFI_STATUS Status; + EFI_STATUS Status; + EFI_BLOCK_IO_PROTOCOL *BlockIo; + VBLK_DEV *Dev; - Dev = VIRTIO_BLK_FROM_BLOCK_IO (This); + Status = gBS->OpenProtocol ( + DeviceHandle, // candidate device + &gEfiBlockIoProtocolGuid, // retrieve the BlockIo iface + (VOID **)&BlockIo, // target pointer + This->DriverBindingHandle, // requestor driver identity + DeviceHandle, // requesting lookup for dev. + EFI_OPEN_PROTOCOL_GET_PROTOCOL // lookup only, no ref. added + ); + if (EFI_ERROR (Status)) { + return Status; + } + + Dev = VIRTIO_BLK_FROM_BLOCK_IO (BlockIo); // - // If DriverBindingStop() is called with the driver instance still in use, - // or any of the parameters are invalid, we've caught a bug. + // Handle Stop() requests for in-use driver instances gracefully. // Status = gBS->UninstallProtocolInterface (DeviceHandle, &gEfiBlockIoProtocolGuid, &Dev->BlockIo); - ASSERT (Status == EFI_SUCCESS); + if (EFI_ERROR (Status)) { + return Status; + } VirtioBlkUninit (Dev); -- 2.39.2