IN EFI_HANDLE *ChildHandleBuffer\r
)\r
{\r
- VBLK_DEV *Dev;\r
- EFI_STATUS Status;\r
+ EFI_STATUS Status;\r
+ EFI_BLOCK_IO_PROTOCOL *BlockIo;\r
+ VBLK_DEV *Dev;\r
\r
- Dev = VIRTIO_BLK_FROM_BLOCK_IO (This);\r
+ Status = gBS->OpenProtocol (\r
+ DeviceHandle, // candidate device\r
+ &gEfiBlockIoProtocolGuid, // retrieve the BlockIo iface\r
+ (VOID **)&BlockIo, // target pointer\r
+ This->DriverBindingHandle, // requestor driver identity\r
+ DeviceHandle, // requesting lookup for dev.\r
+ EFI_OPEN_PROTOCOL_GET_PROTOCOL // lookup only, no ref. added\r
+ );\r
+ if (EFI_ERROR (Status)) {\r
+ return Status;\r
+ }\r
+\r
+ Dev = VIRTIO_BLK_FROM_BLOCK_IO (BlockIo);\r
\r
//\r
- // If DriverBindingStop() is called with the driver instance still in use,\r
- // or any of the parameters are invalid, we've caught a bug.\r
+ // Handle Stop() requests for in-use driver instances gracefully.\r
//\r
Status = gBS->UninstallProtocolInterface (DeviceHandle,\r
&gEfiBlockIoProtocolGuid, &Dev->BlockIo);\r
- ASSERT (Status == EFI_SUCCESS);\r
+ if (EFI_ERROR (Status)) {\r
+ return Status;\r
+ }\r
\r
VirtioBlkUninit (Dev);\r
\r