]> git.proxmox.com Git - mirror_edk2.git/commitdiff
MdeModulePkg/RamDiskDxe: Perform MediaId check first in BlkIo services
authorHao Wu <hao.a.wu@intel.com>
Fri, 9 Feb 2018 02:16:53 +0000 (10:16 +0800)
committerHao Wu <hao.a.wu@intel.com>
Mon, 26 Feb 2018 00:45:57 +0000 (08:45 +0800)
The commit places the check for MediaId at the beginning of Block IO
services:
RamDiskBlkIoReadBlocks and
RamDiskBlkIoWriteBlocks

This aligns with the Block IO protocol implementations for other
devices.

Cc: Star Zeng <star.zeng@intel.com>
Cc: Eric Dong <eric.dong@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Hao Wu <hao.a.wu@intel.com>
Reviewed-by: Ruiyu Ni <ruiyu.ni@intel.com>
MdeModulePkg/Universal/Disk/RamDiskDxe/RamDiskBlockIo.c

index f36e1c8ff27b56e952459f1b4a44ba8f600b57c2..4f74b5ef1531aa80cead18f867e1744dd98ab176 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Produce EFI_BLOCK_IO_PROTOCOL on a RAM disk device.\r
 \r
-  Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2016 - 2018, Intel Corporation. All rights reserved.<BR>\r
   This program and the accompanying materials\r
   are licensed and made available under the terms and conditions of the BSD License\r
   which accompanies this distribution.  The full text of the license may be found at\r
@@ -137,6 +137,12 @@ RamDiskBlkIoReadBlocks (
   RAM_DISK_PRIVATE_DATA           *PrivateData;\r
   UINTN                           NumberOfBlocks;\r
 \r
+  PrivateData = RAM_DISK_PRIVATE_FROM_BLKIO (This);\r
+\r
+  if (MediaId != PrivateData->Media.MediaId) {\r
+    return EFI_MEDIA_CHANGED;\r
+  }\r
+\r
   if (Buffer == NULL) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
@@ -145,12 +151,6 @@ RamDiskBlkIoReadBlocks (
     return EFI_SUCCESS;\r
   }\r
 \r
-  PrivateData = RAM_DISK_PRIVATE_FROM_BLKIO (This);\r
-\r
-  if (MediaId != PrivateData->Media.MediaId) {\r
-    return EFI_MEDIA_CHANGED;\r
-  }\r
-\r
   if ((BufferSize % PrivateData->Media.BlockSize) != 0) {\r
     return EFI_BAD_BUFFER_SIZE;\r
   }\r
@@ -212,14 +212,6 @@ RamDiskBlkIoWriteBlocks (
   RAM_DISK_PRIVATE_DATA           *PrivateData;\r
   UINTN                           NumberOfBlocks;\r
 \r
-  if (Buffer == NULL) {\r
-    return EFI_INVALID_PARAMETER;\r
-  }\r
-\r
-  if (BufferSize == 0) {\r
-    return EFI_SUCCESS;\r
-  }\r
-\r
   PrivateData = RAM_DISK_PRIVATE_FROM_BLKIO (This);\r
 \r
   if (MediaId != PrivateData->Media.MediaId) {\r
@@ -230,6 +222,14 @@ RamDiskBlkIoWriteBlocks (
     return EFI_WRITE_PROTECTED;\r
   }\r
 \r
+  if (Buffer == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  if (BufferSize == 0) {\r
+    return EFI_SUCCESS;\r
+  }\r
+\r
   if ((BufferSize % PrivateData->Media.BlockSize) != 0) {\r
     return EFI_BAD_BUFFER_SIZE;\r
   }\r