From fcf5e49dc912f27b77b50ddea3c6b7a4ba28717c Mon Sep 17 00:00:00 2001 From: niruiyu Date: Mon, 25 Apr 2011 09:31:57 +0000 Subject: Change BlockIo drivers to return EFI_NO_MEDIA or EFI_MEDIA_CHANGED even the Buffer/BufferSize/Lba is invalid so that caller can probe the media status easier. git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@11584 6f19259b-4bc3-4df7-8a09-765794883524 --- .../Bus/Usb/UsbMassStorageDxe/UsbMassImpl.c | 76 ++++++++++++---------- 1 file changed, 41 insertions(+), 35 deletions(-) (limited to 'MdeModulePkg/Bus/Usb') diff --git a/MdeModulePkg/Bus/Usb/UsbMassStorageDxe/UsbMassImpl.c b/MdeModulePkg/Bus/Usb/UsbMassStorageDxe/UsbMassImpl.c index f440e9fd7c..107eb8b4e4 100644 --- a/MdeModulePkg/Bus/Usb/UsbMassStorageDxe/UsbMassImpl.c +++ b/MdeModulePkg/Bus/Usb/UsbMassStorageDxe/UsbMassImpl.c @@ -1,7 +1,7 @@ /** @file USB Mass Storage Driver that manages USB Mass Storage Device and produces Block I/O Protocol. -Copyright (c) 2007 - 2008, Intel Corporation. All rights reserved.
+Copyright (c) 2007 - 2011, 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 @@ -113,13 +113,6 @@ UsbMassReadBlocks ( EFI_TPL OldTpl; UINTN TotalBlock; - // - // First, validate the parameters - // - if ((Buffer == NULL) || (BufferSize == 0)) { - return EFI_INVALID_PARAMETER; - } - // // Raise TPL to TPL_NOTIFY to serialize all its operations // to protect shared data structures. @@ -140,6 +133,26 @@ UsbMassReadBlocks ( } } + if (!(Media->MediaPresent)) { + Status = EFI_NO_MEDIA; + goto ON_EXIT; + } + + if (MediaId != Media->MediaId) { + Status = EFI_MEDIA_CHANGED; + goto ON_EXIT; + } + + if (BufferSize == 0) { + Status = EFI_SUCCESS; + goto ON_EXIT; + } + + if (Buffer == NULL) { + Status = EFI_INVALID_PARAMETER; + goto ON_EXIT; + } + // // BufferSize must be a multiple of the intrinsic block size of the device. // @@ -158,16 +171,6 @@ UsbMassReadBlocks ( goto ON_EXIT; } - if (!(Media->MediaPresent)) { - Status = EFI_NO_MEDIA; - goto ON_EXIT; - } - - if (MediaId != Media->MediaId) { - Status = EFI_MEDIA_CHANGED; - goto ON_EXIT; - } - Status = UsbBootReadBlocks (UsbMass, (UINT32) Lba, TotalBlock, Buffer); if (EFI_ERROR (Status)) { DEBUG ((EFI_D_ERROR, "UsbMassReadBlocks: UsbBootReadBlocks (%r) -> Reset\n", Status)); @@ -221,13 +224,6 @@ UsbMassWriteBlocks ( EFI_TPL OldTpl; UINTN TotalBlock; - // - // First, validate the parameters - // - if ((Buffer == NULL) || (BufferSize == 0)) { - return EFI_INVALID_PARAMETER; - } - // // Raise TPL to TPL_NOTIFY to serialize all its operations // to protect shared data structures. @@ -248,6 +244,26 @@ UsbMassWriteBlocks ( } } + if (!(Media->MediaPresent)) { + Status = EFI_NO_MEDIA; + goto ON_EXIT; + } + + if (MediaId != Media->MediaId) { + Status = EFI_MEDIA_CHANGED; + goto ON_EXIT; + } + + if (BufferSize == 0) { + Status = EFI_SUCCESS; + goto ON_EXIT; + } + + if (Buffer == NULL) { + Status = EFI_INVALID_PARAMETER; + goto ON_EXIT; + } + // // BufferSize must be a multiple of the intrinsic block size of the device. // @@ -266,16 +282,6 @@ UsbMassWriteBlocks ( goto ON_EXIT; } - if (!(Media->MediaPresent)) { - Status = EFI_NO_MEDIA; - goto ON_EXIT; - } - - if (MediaId != Media->MediaId) { - Status = EFI_MEDIA_CHANGED; - goto ON_EXIT; - } - // // Try to write the data even the device is marked as ReadOnly, // and clear the status should the write succeed. -- cgit v1.2.3