From: rsun3 Date: Thu, 23 Jul 2009 01:30:16 +0000 (+0000) Subject: Fixed a bug that the system hangs with an assert in DiskIo.c that is division overflo... X-Git-Tag: edk2-stable201903~17334 X-Git-Url: https://git.proxmox.com/?a=commitdiff_plain;h=88e349f1feaa7a9963cc044e8e815db4eed198bf;p=mirror_edk2.git Fixed a bug that the system hangs with an assert in DiskIo.c that is division overflow due to block size == 0 when no flppy media is present in a specific type of USB floppy drive (NEC PC-VP-BU04)at power on. Root cause is that Read Capacity command returns media not present error, then UsbMassStorage driver issues Sense Request command to get the sense data. However, the USB floppy drive still returns the previous error for the Sense Request command. UsbBootRequestSense() does not handle this case correctly and returns EFI_SUCCESS so that the block size of the Block IO protocol instance is set to be 0. Solution is to fix the logic to handle the case and add protective logic to avoid setting block size to be 0. git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@8979 6f19259b-4bc3-4df7-8a09-765794883524 --- diff --git a/MdeModulePkg/Bus/Usb/UsbMassStorageDxe/UsbMassBoot.c b/MdeModulePkg/Bus/Usb/UsbMassStorageDxe/UsbMassBoot.c index 71deef051e..013b7e2cc3 100644 --- a/MdeModulePkg/Bus/Usb/UsbMassStorageDxe/UsbMassBoot.c +++ b/MdeModulePkg/Bus/Usb/UsbMassStorageDxe/UsbMassBoot.c @@ -65,6 +65,9 @@ UsbBootRequestSense ( ); if (EFI_ERROR (Status) || CmdResult != USB_MASS_CMD_SUCCESS) { DEBUG ((EFI_D_ERROR, "UsbBootRequestSense: (%r) CmdResult=0x%x\n", Status, CmdResult)); + if (!EFI_ERROR (Status)) { + Status = EFI_DEVICE_ERROR; + } return Status; } @@ -375,6 +378,7 @@ UsbBootReadCapacity ( USB_BOOT_READ_CAPACITY_DATA CapacityData; EFI_BLOCK_IO_MEDIA *Media; EFI_STATUS Status; + UINT32 BlockSize; Media = &UsbMass->BlockIoMedia; @@ -403,10 +407,12 @@ UsbBootReadCapacity ( // Media->MediaPresent = TRUE; Media->LastBlock = SwapBytes32 (ReadUnaligned32 ((CONST UINT32 *) CapacityData.LastLba)); - Media->BlockSize = SwapBytes32 (ReadUnaligned32 ((CONST UINT32 *) CapacityData.BlockLen)); - if (Media->BlockSize == 0) { + BlockSize = SwapBytes32 (ReadUnaligned32 ((CONST UINT32 *) CapacityData.BlockLen)); + if (BlockSize == 0) { return EFI_NOT_READY; + } else { + Media->BlockSize = BlockSize; } DEBUG ((EFI_D_INFO, "UsbBootReadCapacity Success LBA=%ld BlockSize=%d\n",