From patchwork Fri Oct 9 06:28:42 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Isaku Yamahata X-Patchwork-Id: 35563 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id BEFE4B7B8E for ; Fri, 9 Oct 2009 17:49:47 +1100 (EST) Received: from localhost ([127.0.0.1]:33734 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Mw9IM-00064l-65 for incoming@patchwork.ozlabs.org; Fri, 09 Oct 2009 02:49:42 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Mw90H-00048B-JD for qemu-devel@nongnu.org; Fri, 09 Oct 2009 02:31:01 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1Mw909-0003wz-9c for qemu-devel@nongnu.org; Fri, 09 Oct 2009 02:30:57 -0400 Received: from [199.232.76.173] (port=55764 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Mw907-0003vr-Uk for qemu-devel@nongnu.org; Fri, 09 Oct 2009 02:30:52 -0400 Received: from mail.valinux.co.jp ([210.128.90.3]:36137) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1Mw904-0001QW-Iw for qemu-devel@nongnu.org; Fri, 09 Oct 2009 02:30:50 -0400 Received: from nm.local.valinux.co.jp (vagw.valinux.co.jp [210.128.90.14]) by mail.valinux.co.jp (Postfix) with ESMTP id D8EA149E1E; Fri, 9 Oct 2009 15:30:39 +0900 (JST) Received: from yamahata by nm.local.valinux.co.jp with local (Exim 4.69) (envelope-from ) id 1Mw8yM-00046R-Ku; Fri, 09 Oct 2009 15:29:02 +0900 From: Isaku Yamahata To: qemu-devel@nongnu.org, mst@redhat.com Date: Fri, 9 Oct 2009 15:28:42 +0900 Message-Id: <1255069742-15724-10-git-send-email-yamahata@valinux.co.jp> X-Mailer: git-send-email 1.6.0.2 In-Reply-To: <1255069742-15724-1-git-send-email-yamahata@valinux.co.jp> References: <1255069742-15724-1-git-send-email-yamahata@valinux.co.jp> X-Virus-Scanned: clamav-milter 0.95.2 at va-mail.local.valinux.co.jp X-Virus-Status: Clean X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6 (newer, 3) Cc: yamahata@valinux.co.jp Subject: [Qemu-devel] [PATCH V5 09/29] pci: clean up of pci_default_read_config. X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org This patch cleans up pci_default_read_config() removing ugly length and range check. Suggesed by "Michael S. Tsirkin" Signed-off-by: Isaku Yamahata Acked-by: Michael S. Tsirkin --- hw/pci.c | 26 +++++--------------------- 1 files changed, 5 insertions(+), 21 deletions(-) diff --git a/hw/pci.c b/hw/pci.c index 634899a..755ebad 100644 --- a/hw/pci.c +++ b/hw/pci.c @@ -558,27 +558,11 @@ static void pci_update_mappings(PCIDevice *d) uint32_t pci_default_read_config(PCIDevice *d, uint32_t address, int len) { - uint32_t val; - - switch(len) { - default: - case 4: - if (address <= 0xfc) { - val = pci_get_long(d->config + address); - break; - } - /* fall through */ - case 2: - if (address <= 0xfe) { - val = pci_get_word(d->config + address); - break; - } - /* fall through */ - case 1: - val = pci_get_byte(d->config + address); - break; - } - return val; + uint32_t val = 0; + assert(len == 1 || len == 2 || len == 4); + len = MIN(len, PCI_CONFIG_SPACE_SIZE - address); + memcpy(&val, d->config + address, len); + return le32_to_cpu(val); } void pci_default_write_config(PCIDevice *d, uint32_t addr, uint32_t val, int l)