From 5ab765a7ad42933b4ea51a1f9593c37f7b32e6d7 Mon Sep 17 00:00:00 2001 From: oliviermartin Date: Sun, 14 Apr 2013 09:26:28 +0000 Subject: [PATCH] EmbeddedPkg/MmcDxe: Make the driver more compliant with the UEFI specification Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Olivier Martin git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@14264 6f19259b-4bc3-4df7-8a09-765794883524 --- EmbeddedPkg/Universal/MmcDxe/MmcBlockIo.c | 26 ++++++++++++++++------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/EmbeddedPkg/Universal/MmcDxe/MmcBlockIo.c b/EmbeddedPkg/Universal/MmcDxe/MmcBlockIo.c index fa0eccd40d..33f2c561f1 100644 --- a/EmbeddedPkg/Universal/MmcDxe/MmcBlockIo.c +++ b/EmbeddedPkg/Universal/MmcDxe/MmcBlockIo.c @@ -515,6 +515,10 @@ MmcIoBlocks ( MmcHost = MmcHostInstance->MmcHost; ASSERT (MmcHost); + if (This->Media->MediaId != MediaId) { + return EFI_MEDIA_CHANGED; + } + if ((MmcHost == 0)|| (Buffer == NULL)) { return EFI_INVALID_PARAMETER; } @@ -529,17 +533,23 @@ MmcIoBlocks ( return EFI_INVALID_PARAMETER; } - // The buffer size must not be zero and it must be an exact multiple of the block size - if ((BufferSize == 0) || ((BufferSize % This->Media->BlockSize) != 0)) { + if((Transfer == MMC_IOBLOCKS_WRITE) && (This->Media->ReadOnly == TRUE)) { + return EFI_WRITE_PROTECTED; + } + + // Reading 0 Byte is valid + if (BufferSize == 0) { + return EFI_SUCCESS; + } + + // The buffer size must be an exact multiple of the block size + if ((BufferSize % This->Media->BlockSize) != 0) { return EFI_BAD_BUFFER_SIZE; } - if (This->Media->MediaId != MediaId) { - return EFI_MEDIA_CHANGED; - } - - if((Transfer == MMC_IOBLOCKS_WRITE) && (This->Media->ReadOnly == TRUE)) { - return EFI_WRITE_PROTECTED; + // Check the alignment + if ((This->Media->IoAlign > 2) && (((UINTN)Buffer & (This->Media->IoAlign - 1)) != 0)) { + return EFI_INVALID_PARAMETER; } BytesRemainingToBeTransfered = BufferSize;