linux-pci.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Vladis Dronov <vdronov@redhat.com>
To: Bjorn Helgaas <helgaas@kernel.org>, linux-pci@vger.kernel.org
Cc: Vladis Dronov <vdronov@redhat.com>
Subject: [PATCH v2] PCI: fix missing ROM content warning in pci_get_rom_size()
Date: Fri, 27 Nov 2015 18:20:06 +0100	[thread overview]
Message-ID: <1448644806-6506-1-git-send-email-vdronov@redhat.com> (raw)
In-Reply-To: <20151124170331.GB24819@localhost>

Make pci_get_rom_size() to emit a warning if any byte in a PCI ROM
header or data signature is not following the standard ("PCI Local
Bus Specification" or "PCI Firmware Specification Revision 3.x"),
not only the first one.

Signed-off-by: Vladis Dronov <vdronov@redhat.com>
---
 drivers/pci/rom.c | 20 ++++++++------------
 1 file changed, 8 insertions(+), 12 deletions(-)

diff --git a/drivers/pci/rom.c b/drivers/pci/rom.c
index eb0ad53..48404db 100644
--- a/drivers/pci/rom.c
+++ b/drivers/pci/rom.c
@@ -77,22 +77,18 @@ size_t pci_get_rom_size(struct pci_dev *pdev, void __iomem *rom, size_t size)
 	do {
 		void __iomem *pds;
 		/* Standard PCI ROMs start out with these bytes 55 AA */
-		if (readb(image) != 0x55) {
-			dev_err(&pdev->dev, "Invalid ROM contents\n");
+		if (readw(image) != 0xAA55) {
+			dev_err(&pdev->dev, "Invalid PCI ROM header signature:"
+			    " 0x%4.4x\n", readw(image));
 			break;
 		}
-		if (readb(image + 1) != 0xAA)
-			break;
-		/* get the PCI data structure and check its signature */
+		/* get the PCI data structure and check its "PCIR" signature */
 		pds = image + readw(image + 24);
-		if (readb(pds) != 'P')
-			break;
-		if (readb(pds + 1) != 'C')
-			break;
-		if (readb(pds + 2) != 'I')
-			break;
-		if (readb(pds + 3) != 'R')
+		if (readl(pds) != 0x52494350) {
+			dev_err(&pdev->dev, "Invalid PCI ROM data signature:"
+			    " 0x%8.8x\n", readl(pds));
 			break;
+		}
 		last_image = readb(pds + 21) & 0x80;
 		length = readw(pds + 16);
 		image += length * 512;
-- 
2.4.3


  parent reply	other threads:[~2015-11-27 17:20 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-11-06 12:16 [PATCH] PCI: fix invalid ROM content detection in pci_get_rom_size() Vladis Dronov
2015-11-24 17:03 ` Bjorn Helgaas
2015-11-27 17:05   ` Vladis Dronov
2015-11-27 17:20   ` Vladis Dronov [this message]
2015-12-04 23:44     ` [PATCH v2] PCI: fix missing ROM content warning " Bjorn Helgaas

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1448644806-6506-1-git-send-email-vdronov@redhat.com \
    --to=vdronov@redhat.com \
    --cc=helgaas@kernel.org \
    --cc=linux-pci@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).