diff mbox

[edk2,1/3] OvmfPkg: VirtioBlkDxe: Fix SCT test errors

Message ID 1433160495-10385-2-git-send-email-heyi.guo@linaro.org
State New
Headers show

Commit Message

gary guo June 1, 2015, 12:08 p.m. UTC
Fix SCT test errors for VirtioBlkDxe with ReadBlocks interface:

1. Media present and media ID should be checked first according to
   UEFI spec: "The function must return EFI_NO_MEDIA or
   EFI_MEDIA_CHANGED even if LBA, BufferSize, or Buffer are invalid
   so the caller can probe for changes in media state".

2. Check Buffer to be not NULL, or we will get below error from QEMU
   and the emulation will exit abnormally:
   qemu-system-aarch64: virtio: error trying to map MMIO memory

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Heyi Guo <heyi.guo@linaro.org>
---
 OvmfPkg/VirtioBlkDxe/VirtioBlk.c | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)
diff mbox

Patch

diff --git a/OvmfPkg/VirtioBlkDxe/VirtioBlk.c b/OvmfPkg/VirtioBlkDxe/VirtioBlk.c
index 862957c..36f0fa5 100644
--- a/OvmfPkg/VirtioBlkDxe/VirtioBlk.c
+++ b/OvmfPkg/VirtioBlkDxe/VirtioBlk.c
@@ -363,10 +363,31 @@  VirtioBlkReadBlocks (
 {
   VBLK_DEV   *Dev;
   EFI_STATUS Status;
+  EFI_BLOCK_IO_MEDIA  *Media;
+
+  if (This == NULL) {
+    return EFI_INVALID_PARAMETER;
+  }
+
+  Media = This->Media;
+
+  // Check media first according to UEFI spec
+  if (!Media) {
+    return EFI_INVALID_PARAMETER;
+  }
+  if (!Media->MediaPresent) {
+    return EFI_NO_MEDIA;
+  }
+  if (Media->MediaId != MediaId) {
+    return EFI_MEDIA_CHANGED;
+  }
 
   if (BufferSize == 0) {
     return EFI_SUCCESS;
   }
+  if (Buffer == NULL) {
+    return EFI_INVALID_PARAMETER;
+  }
 
   Dev = VIRTIO_BLK_FROM_BLOCK_IO (This);
   Status = VerifyReadWriteRequest (