PCI: complain about devices that seem to be broken

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Linux Kernel Mailing List
Date: Friday, March 26, 2010 - 4:59 pm

Gitweb:     http://git.kernel.org/linus/c519a5a7dab2d8e9a114f003e2d369bcf8e913f3
Commit:     c519a5a7dab2d8e9a114f003e2d369bcf8e913f3
Parent:     e1944c6b0fba80a7837c1cbc47dfbf46e1274a4b
Author:     Bjorn Helgaas <bjorn.helgaas@hp.com>
AuthorDate: Fri Mar 19 14:56:27 2010 -0600
Committer:  Jesse Barnes <jbarnes@virtuousgeek.org>
CommitDate: Wed Mar 24 13:21:36 2010 -0700

    PCI: complain about devices that seem to be broken
    
    If we can tell that a device isn't working correctly, we should tell
    the user to make debugging easier.  Otherwise, it can take a lot of
    work to determine whether the problem is in the driver, PCMCIA, PCI,
    hardware, etc., as in http://bugzilla.kernel.org/show_bug.cgi?id=12006
    
    Signed-off-by: Bjorn Helgaas <bjorn.helgaas@hp.com>
    Signed-off-by: Jesse Barnes <jbarnes@virtuousgeek.org>
---
 drivers/pci/probe.c |   23 ++++++++++++++++-------
 1 files changed, 16 insertions(+), 7 deletions(-)

diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
index c82548a..882bd8d 100644
--- a/drivers/pci/probe.c
+++ b/drivers/pci/probe.c
@@ -174,14 +174,19 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
 	pci_read_config_dword(dev, pos, &sz);
 	pci_write_config_dword(dev, pos, l);
 
+	if (!sz)
+		goto fail;	/* BAR not implemented */
+
 	/*
 	 * All bits set in sz means the device isn't working properly.
-	 * If the BAR isn't implemented, all bits must be 0.  If it's a
-	 * memory BAR or a ROM, bit 0 must be clear; if it's an io BAR, bit
-	 * 1 must be clear.
+	 * If it's a memory BAR or a ROM, bit 0 must be clear; if it's
+	 * an io BAR, bit 1 must be clear.
 	 */
-	if (!sz || sz == 0xffffffff)
+	if (sz == 0xffffffff) {
+		dev_err(&dev->dev, "reg %x: invalid size %#x; broken device?\n",
+			pos, sz);
 		goto fail;
+	}
 
 	/*
 	 * I don't know how l can have all bits set.  Copied from old code.
@@ -244,13 +249,17 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
 				   pos, res);
 		}
 	} else {
-		sz = pci_size(l, sz, mask);
+		u32 size = pci_size(l, sz, mask);
 
-		if (!sz)
+		if (!size) {
+			dev_err(&dev->dev, "reg %x: invalid size "
+			        "(l %#x sz %#x mask %#x); broken device?",
+				pos, l, sz, mask);
 			goto fail;
+		}
 
 		res->start = l;
-		res->end = l + sz;
+		res->end = l + size;
 
 		dev_printk(KERN_DEBUG, &dev->dev, "reg %x: %pR\n", pos, res);
 	}
--
To unsubscribe from this list: send the line "unsubscribe git-commits-head" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
PCI: complain about devices that seem to be broken, Linux Kernel Mailing ..., (Fri Mar 26, 4:59 pm)