From patchwork Fri Jul 30 19:40:25 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Williamson X-Patchwork-Id: 116107 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter.kernel.org (8.14.4/8.14.3) with ESMTP id o6UJeVoU016506 for ; Fri, 30 Jul 2010 19:40:31 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755168Ab0G3Tk3 (ORCPT ); Fri, 30 Jul 2010 15:40:29 -0400 Received: from mx1.redhat.com ([209.132.183.28]:8074 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754956Ab0G3Tk1 (ORCPT ); Fri, 30 Jul 2010 15:40:27 -0400 Received: from int-mx03.intmail.prod.int.phx2.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o6UJeRHN019756 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Fri, 30 Jul 2010 15:40:27 -0400 Received: from localhost6.localdomain6 (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by int-mx03.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o6UJePYN024110; Fri, 30 Jul 2010 15:40:26 -0400 From: Alex Williamson Subject: [PATCH 3/3] device-assignment: Byte-wise ROM read To: kvm@vger.kernel.org Cc: ddutile@redhat.com, chrisw@redhat.com, gleb@redhat.com, alex.williamson@redhat.com Date: Fri, 30 Jul 2010 13:40:25 -0600 Message-ID: <20100730194025.10110.47519.stgit@localhost6.localdomain6> In-Reply-To: <20100730193941.10110.92913.stgit@localhost6.localdomain6> References: <20100730193941.10110.92913.stgit@localhost6.localdomain6> User-Agent: StGIT/0.14.3 MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.67 on 10.5.11.16 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter.kernel.org [140.211.167.41]); Fri, 30 Jul 2010 19:40:31 +0000 (UTC) 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);