OSDN Git Service

Bug #13988: Fix reads from "0"-sized ROMs.
authorStuart Bennett <sb476@cam.ac.uk>
Fri, 14 Mar 2008 15:58:33 +0000 (11:58 -0400)
committerAdam Jackson <ajax@redhat.com>
Fri, 14 Mar 2008 15:58:33 +0000 (11:58 -0400)
src/linux_devmem.c
src/linux_sysfs.c

index a68ea11..21b45ef 100644 (file)
@@ -124,7 +124,7 @@ pci_device_linux_devmem_read_rom(struct pci_device *dev, void *buffer)
     else {
        size_t bytes;
 
-       for (bytes = 0; bytes < priv->base.rom_size; /* empty */) {
+       for (bytes = 0; bytes < rom_size; /* empty */) {
            const ssize_t got = pread(fd, buffer, rom_size - bytes, 
                                      rom_base + bytes);
            if (got == -1) {
index 84cdb84..873dc02 100644 (file)
@@ -307,6 +307,7 @@ pci_device_linux_sysfs_read_rom( struct pci_device * dev, void * buffer )
     int fd;
     struct stat  st;
     int err = 0;
+    size_t rom_size;
     size_t total_bytes;
 
 
@@ -331,6 +332,9 @@ pci_device_linux_sysfs_read_rom( struct pci_device * dev, void * buffer )
        return errno;
     }
 
+    rom_size = st.st_size;
+    if ( rom_size == 0 )
+       rom_size = 0x10000;
 
     /* This is a quirky thing on Linux.  Even though the ROM and the file
      * for the ROM in sysfs are read-only, the string "1" must be written to
@@ -340,9 +344,9 @@ pci_device_linux_sysfs_read_rom( struct pci_device * dev, void * buffer )
     write( fd, "1", 1 );
     lseek( fd, 0, SEEK_SET );
 
-    for ( total_bytes = 0 ; total_bytes < st.st_size ; /* empty */ ) {
+    for ( total_bytes = 0 ; total_bytes < rom_size ; /* empty */ ) {
        const int bytes = read( fd, (char *) buffer + total_bytes,
-                               st.st_size - total_bytes );
+                               rom_size - total_bytes );
        if ( bytes == -1 ) {
            err = errno;
            break;