According to the UEFI Specification, data values in EFI_BLOCK_IO_MEDIA are read-only. This patch introduces a local variable to avoid overwriting IoAlign and reduces unnecessary overallocation.

Cc: Jaben Carsey <jaben.car...@intel.com>
Cc: Ruiyu Ni <ruiyu...@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Kornel Pal <kornel...@gmail.com>
---
 ShellPkg/Library/UefiShellDebug1CommandsLib/Dblk.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/Dblk.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/Dblk.c
index 3632ca8a7a..b2cbae84f3 100644
--- a/ShellPkg/Library/UefiShellDebug1CommandsLib/Dblk.c
+++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/Dblk.c
@@ -39,6 +39,7 @@ DisplayTheBlocks(
   UINT8                     *Buffer;
   UINT8                     *OriginalBuffer;
   UINTN                     BufferSize;
+  UINT32                    IoAlign;

   ShellStatus = SHELL_SUCCESS;

@@ -53,13 +54,14 @@ DisplayTheBlocks(
   }

   BufferSize = BlockIo->Media->BlockSize * BlockCount;
-  if(BlockIo->Media->IoAlign == 0) {
-    BlockIo->Media->IoAlign = 1;
+  IoAlign    = BlockIo->Media->IoAlign;
+  if (IoAlign == 0) {
+    IoAlign = 1;
   }

   if (BufferSize > 0) {
-    OriginalBuffer = AllocateZeroPool(BufferSize + BlockIo->Media->IoAlign); -    Buffer         = ALIGN_POINTER (OriginalBuffer,BlockIo->Media->IoAlign);
+    OriginalBuffer = AllocateZeroPool(BufferSize + IoAlign - 1);
+    Buffer         = ALIGN_POINTER (OriginalBuffer, IoAlign);
   } else {
     ShellPrintEx(-1,-1,L"  BlockSize: 0x%08x, BlockCount: 0x%08x\r\n", BlockIo->Media->BlockSize, BlockCount);
     OriginalBuffer = NULL;
--
2.15.1.windows.2

_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel

Reply via email to