[2/2] PCI: Add check code for last image indicator not set

Message ID 1528163206-4136-2-git-send-email-Rex.Zhu@amd.com
State New
Delegated to: Bjorn Helgaas
Headers show
Series
  • [1/2] PCI: Avoid access memory outside the resource window
Related show

Commit Message

Rex Zhu June 5, 2018, 1:46 a.m.
if last image indicator was not set in the PCI data struct,
print out "No more image in the PCI ROM" instand of
loop back and print "Invalid PCI ROM header signature" info.

Signed-off-by: Rex Zhu <Rex.Zhu@amd.com>
---
 drivers/pci/rom.c | 6 ++++++
 1 file changed, 6 insertions(+)

Patch

diff --git a/drivers/pci/rom.c b/drivers/pci/rom.c
index a5c6016..a8b916b 100644
--- a/drivers/pci/rom.c
+++ b/drivers/pci/rom.c
@@ -110,6 +110,12 @@  size_t pci_get_rom_size(struct pci_dev *pdev, void __iomem *rom, size_t size)
 		/* Avoid iterating through memory outside the resource window */
 		if (image >= rom + size)
 			break;
+		if (!last_image) {
+			if (readw(image) != 0xAA55) {
+				pci_info(pdev, "No more image in the PCI ROM\n");
+				break;
+			}
+		}
 	} while (length && !last_image);
 
 	/* never return a size larger than the PCI resource window */