diff --git a/MdeModulePkg/Bus/Spi/SpiNorFlashJedecSfdp/SpiNorFlash.c b/MdeModulePkg/Bus/Spi/SpiNorFlashJedecSfdp/SpiNorFlash.c index 3ac5420fbf..58f7704a2d 100644 --- a/MdeModulePkg/Bus/Spi/SpiNorFlashJedecSfdp/SpiNorFlash.c +++ b/MdeModulePkg/Bus/Spi/SpiNorFlashJedecSfdp/SpiNorFlash.c @@ -48,7 +48,17 @@ FillWriteBuffer ( UINT32 Index; UINT8 SfdpAddressBytes; - SfdpAddressBytes = (UINT8)Instance->SfdpBasicFlash->AddressBytes; + if ((Instance == NULL) || (WriteBuffer == NULL)) { + ASSERT (Instance != NULL); + ASSERT (WriteBuffer != NULL); + return 0; + } + + if (Instance->SfdpBasicFlash == NULL) { + SfdpAddressBytes = 0; + } else { + SfdpAddressBytes = (UINT8)Instance->SfdpBasicFlash->AddressBytes; + } // Copy Opcode into Write Buffer Instance->SpiTransactionWriteBuffer[0] = Opcode;