From patchwork Sun Apr 26 11:46:38 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 20006 Received: from vger.kernel.org (vger.kernel.org [209.132.176.167]) by demeter.kernel.org (8.14.2/8.14.2) with ESMTP id n3QBlxSY012148 for ; Sun, 26 Apr 2009 11:47:59 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752654AbZDZLrj (ORCPT ); Sun, 26 Apr 2009 07:47:39 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1752675AbZDZLrj (ORCPT ); Sun, 26 Apr 2009 07:47:39 -0400 Received: from mx2.redhat.com ([66.187.237.31]:49336 "EHLO mx2.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752305AbZDZLrj (ORCPT ); Sun, 26 Apr 2009 07:47:39 -0400 Received: from int-mx2.corp.redhat.com (int-mx2.corp.redhat.com [172.16.27.26]) by mx2.redhat.com (8.13.8/8.13.8) with ESMTP id n3QBldVa027183 for ; Sun, 26 Apr 2009 07:47:39 -0400 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx2.corp.redhat.com (8.13.1/8.13.1) with ESMTP id n3QBlcUc002547; Sun, 26 Apr 2009 07:47:38 -0400 Received: from redhat.com (vpn-10-33.str.redhat.com [10.32.10.33]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id n3QBla2m010155; Sun, 26 Apr 2009 07:47:36 -0400 Date: Sun, 26 Apr 2009 14:46:38 +0300 From: "Michael S. Tsirkin" To: kvm@vger.kernel.org Cc: avi@redhat.com Subject: [PATCH] thinko fix: move memset to after mmap failure check Message-ID: <20090426114638.GA27129@redhat.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.18 (2008-05-17) X-Scanned-By: MIMEDefang 2.58 on 172.16.27.26 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org By the time we've done a memset, it's too late to check the pointer for MAP_FAILED value. Let's compare to MAP_FAILED first. Signed-off-by: Michael S. Tsikirn --- Noticed this when reading the code. Makes sense, does it not? hw/device-assignment.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/hw/device-assignment.c b/hw/device-assignment.c index 1f0a1a7..0a5f850 100644 --- a/hw/device-assignment.c +++ b/hw/device-assignment.c @@ -1087,12 +1087,12 @@ static int assigned_dev_register_msix_mmio(AssignedDevice *dev) dev->msix_table_page = mmap(NULL, 0x1000, PROT_READ|PROT_WRITE, MAP_ANONYMOUS|MAP_PRIVATE, 0, 0); - memset(dev->msix_table_page, 0, 0x1000); if (dev->msix_table_page == MAP_FAILED) { fprintf(stderr, "fail allocate msix_table_page! %s\n", strerror(errno)); return -EFAULT; } + memset(dev->msix_table_page, 0, 0x1000); dev->mmio_index = cpu_register_io_memory(0, msix_mmio_read, msix_mmio_write, dev); return 0;