From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=134.134.136.65; helo=mga03.intel.com; envelope-from=hao.a.wu@intel.com; receiver=edk2-devel@lists.01.org Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 47CA1222630D6 for ; Fri, 23 Feb 2018 16:42:04 -0800 (PST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga103.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 23 Feb 2018 16:48:06 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.47,385,1515484800"; d="scan'208";a="19994444" Received: from shwdeopenpsi014.ccr.corp.intel.com ([10.239.9.10]) by fmsmga008.fm.intel.com with ESMTP; 23 Feb 2018 16:48:05 -0800 From: Hao Wu To: edk2-devel@lists.01.org Cc: Hao Wu , Ruiyu Ni , Star Zeng , Eric Dong Date: Sat, 24 Feb 2018 08:48:03 +0800 Message-Id: <20180224004803.12436-1-hao.a.wu@intel.com> X-Mailer: git-send-email 2.12.0.windows.1 Subject: [PATCH] MdeModulePkg/RamDiskDxe: Perform MediaId check first in BlkIo services X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 24 Feb 2018 00:42:05 -0000 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: Ruiyu Ni Cc: Star Zeng Cc: Eric Dong Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Hao Wu --- .../Universal/Disk/RamDiskDxe/RamDiskBlockIo.c | 30 +++++++++++----------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/MdeModulePkg/Universal/Disk/RamDiskDxe/RamDiskBlockIo.c b/MdeModulePkg/Universal/Disk/RamDiskDxe/RamDiskBlockIo.c index f36e1c8ff2..4f74b5ef15 100644 --- a/MdeModulePkg/Universal/Disk/RamDiskDxe/RamDiskBlockIo.c +++ b/MdeModulePkg/Universal/Disk/RamDiskDxe/RamDiskBlockIo.c @@ -1,7 +1,7 @@ /** @file Produce EFI_BLOCK_IO_PROTOCOL on a RAM disk device. - Copyright (c) 2016, Intel Corporation. All rights reserved.
+ Copyright (c) 2016 - 2018, Intel Corporation. All rights reserved.
This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License which accompanies this distribution. The full text of the license may be found at @@ -137,6 +137,12 @@ RamDiskBlkIoReadBlocks ( RAM_DISK_PRIVATE_DATA *PrivateData; UINTN NumberOfBlocks; + PrivateData = RAM_DISK_PRIVATE_FROM_BLKIO (This); + + if (MediaId != PrivateData->Media.MediaId) { + return EFI_MEDIA_CHANGED; + } + if (Buffer == NULL) { return EFI_INVALID_PARAMETER; } @@ -145,12 +151,6 @@ RamDiskBlkIoReadBlocks ( return EFI_SUCCESS; } - PrivateData = RAM_DISK_PRIVATE_FROM_BLKIO (This); - - if (MediaId != PrivateData->Media.MediaId) { - return EFI_MEDIA_CHANGED; - } - if ((BufferSize % PrivateData->Media.BlockSize) != 0) { return EFI_BAD_BUFFER_SIZE; } @@ -212,14 +212,6 @@ RamDiskBlkIoWriteBlocks ( RAM_DISK_PRIVATE_DATA *PrivateData; UINTN NumberOfBlocks; - if (Buffer == NULL) { - return EFI_INVALID_PARAMETER; - } - - if (BufferSize == 0) { - return EFI_SUCCESS; - } - PrivateData = RAM_DISK_PRIVATE_FROM_BLKIO (This); if (MediaId != PrivateData->Media.MediaId) { @@ -230,6 +222,14 @@ RamDiskBlkIoWriteBlocks ( return EFI_WRITE_PROTECTED; } + if (Buffer == NULL) { + return EFI_INVALID_PARAMETER; + } + + if (BufferSize == 0) { + return EFI_SUCCESS; + } + if ((BufferSize % PrivateData->Media.BlockSize) != 0) { return EFI_BAD_BUFFER_SIZE; } -- 2.12.0.windows.1