@@ -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 (
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(+)