Skip to content

Commit a6f3296

Browse files
committed
MdeModulePkg: NvmExpressMediaClear - Fix BufferSize value in writeblocks
NvmExpressMediaClear requires that the overwrite buffer be the same size as the block size of the media but then WriteBlocks expects BufferSize in bytes. NvmExpressMediaClear was hardcoded to call using 1. This causes the WriteBlocks to fail. Signed-off-by: Sean Brogan <sebrogan@microsoft.com>
1 parent 11a89ec commit a6f3296

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

MdeModulePkg/Bus/Pci/NvmExpressDxe/NvmExpressMediaSanitize.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -352,14 +352,18 @@ NvmExpressMediaClear (
352352
}
353353

354354
//
355-
// If an invalid buffer or buffer size is sent, the Media Clear operation
356-
// cannot be performed as it requires a native WRITE command. The overwrite
357-
// buffer must have granularity of a namespace block size.
355+
// If an invalid buffer is sent, the Media Clear operation
356+
// cannot be performed as it requires a native WRITE command.
358357
//
359358
if (SectorOwBuffer == NULL) {
360359
return EFI_INVALID_PARAMETER;
361360
}
362361

362+
//
363+
// Since the parameters do not include OwBuffer Size, the size of the overwrite buffer is assumed to be equal
364+
// to the block size of the media.
365+
//
366+
363367
Status = EFI_SUCCESS;
364368

365369
//
@@ -370,9 +374,9 @@ NvmExpressMediaClear (
370374
Status = Device->BlockIo.WriteBlocks (
371375
&Device->BlockIo,
372376
MediaId,
373-
SectorOffset, // Sector/LBA offset (increment each pass)
374-
1, // Write one sector per write
375-
SectorOwBuffer // overwrite buffer
377+
SectorOffset, // Sector/LBA offset (increment each pass)
378+
(UINTN)Device->Media.BlockSize, // Write one block/sector at a time with overwrite buffer
379+
SectorOwBuffer // overwrite buffer
376380
);
377381
}
378382

0 commit comments

Comments
 (0)