This patch makes the ROM reading code return an error to user space if
the size of the ROM read is equal to 0.
The patch also emits dmesg-type warnings if the contents of the ROM
are invalid, or if the ROM is read through sysfs without the device being
enabled.
The Acked-by indicates that Alex indicated to Timothy by private
e-mail that his contribution to the patch below is released under the
appropriate license.
Kernel version: 2.6.27
Signed-off-by: Timothy S. Nelson <wayland@xxxxxxxxxxxxx>
Acked-by: Alex Villacis-Lasso <a_villacis@xxxxxxxxxxxxx>
---
This is my first kernel patch. Hopefully it's fine. Many thanks to
those who helped with it (including answering my stupid questions). I'm
hoping that Jesse, as maintainer, will pick it up from this list.
diff -uprN linux-2.6.27/drivers/pci/pci-sysfs.c linux-2.6.27.rom/drivers/pci/pci-sysfs.c
--- linux-2.6.27/drivers/pci/pci-sysfs.c 2008-10-10 09:13:53.000000000 +1100
+++ linux-2.6.27.rom/drivers/pci/pci-sysfs.c 2009-01-28 10:50:14.000000000 +1100
@@ -663,11 +663,20 @@ pci_write_rom(struct kobject *kobj, stru
char *buf, loff_t off, size_t count)
{
struct pci_dev *pdev = to_pci_dev(container_of(kobj, struct device, kobj));
+ u16 command;
if ((off == 0) && (*buf == '0') && (count == 2))
pdev->rom_attr_enabled = 0;
- else
+ else {
pdev->rom_attr_enabled = 1;
+ pci_read_config_word(pdev, PCI_COMMAND, &command);
+ if (!(command & PCI_COMMAND_MEMORY)) {
+ printk(KERN_INFO "Suggest echoing 1 into "
+ "/sys/bus/pci/<deviceID>/enable to enable "
+ "device\n");
+ printk(KERN_INFO "before trying to do rom reading\n");
+ }
+ }
return count;
}
@@ -694,8 +703,8 @@ pci_read_rom(struct kobject *kobj, struc
return -EINVAL;
rom = pci_map_rom(pdev, &size); /* size starts out as PCI window size */
- if (!rom)
- return 0;
+ if (!rom || !size)
+ return -EIO;
if (off >= size)
count = 0;
diff -uprN linux-2.6.27/drivers/pci/rom.c linux-2.6.27.rom/drivers/pci/rom.c
--- linux-2.6.27/drivers/pci/rom.c 2008-10-10 09:13:53.000000000 +1100
+++ linux-2.6.27.rom/drivers/pci/rom.c 2009-01-28 10:53:27.000000000 +1100
@@ -72,8 +72,11 @@ size_t pci_get_rom_size(void __iomem *ro
do {
void __iomem *pds;
/* Standard PCI ROMs start out with these bytes 55 AA */
- if (readb(image) != 0x55)
+ if (readb(image) != 0x55) {
+ printk(KERN_INFO " %s: Invalid ROM contents\n",
+ __func__);
break;
+ }
if (readb(image + 1) != 0xAA)
break;
/* get the PCI data structure and check its signature */
---------------------------------------------------------------------
| Name: Tim Nelson | Because the Creator is, |
| E-mail: wayland@xxxxxxxxxxxxx | I am |
---------------------------------------------------------------------
----BEGIN GEEK CODE BLOCK----
Version 3.12
GCS d+++ s+: a- C++$ U+++$ P+++$ L+++ E- W+ N+ w--- V-
PE(+) Y+>++ PGP->+++ R(+) !tv b++ DI++++ D G+ e++>++++ h! y-
-----END GEEK CODE BLOCK-----
--
To unsubscribe from this list: send the line "unsubscribe linux-pci" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html