diff mbox

[3/3] device-assignment: Byte-wise ROM read

Message ID 20100730194025.10110.47519.stgit@localhost6.localdomain6 (mailing list archive)
State New, archived
Headers show

Commit Message

Alex Williamson July 30, 2010, 7:40 p.m. UTC
None
diff mbox

Patch

diff --git a/hw/device-assignment.c b/hw/device-assignment.c
index 0e82a16..3bb7f0b 100644
--- a/hw/device-assignment.c
+++ b/hw/device-assignment.c
@@ -1680,19 +1680,20 @@  static void assigned_dev_load_option_rom(AssignedDevice *dev)
         return;
     }
 
-    ret = fread(buf, size, 1, fp);
-    if (!feof(fp) || ferror(fp) || ret != 1) {
+    if (!(ret = fread(buf, 1, size, fp))) {
         free(buf);
         fclose(fp);
         return;
     }
     fclose(fp);
 
+    /* The number of bytes read is often much smaller than the BAR size */
+    size = ret;
+
     /* Copy ROM contents into the space backing the ROM BAR */
     if (dev->v_addrs[PCI_ROM_SLOT].r_size >= size &&
         dev->v_addrs[PCI_ROM_SLOT].u.r_virtbase) {
-        memcpy(dev->v_addrs[PCI_ROM_SLOT].u.r_virtbase,
-               buf, size);
+        memcpy(dev->v_addrs[PCI_ROM_SLOT].u.r_virtbase, buf, size);
     }
 
     free(buf);