From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Mw9TO-00052X-7Z for qemu-devel@nongnu.org; Fri, 09 Oct 2009 03:01:06 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1Mw9TJ-0004yh-AD for qemu-devel@nongnu.org; Fri, 09 Oct 2009 03:01:05 -0400 Received: from [199.232.76.173] (port=53343 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Mw9TJ-0004yX-2R for qemu-devel@nongnu.org; Fri, 09 Oct 2009 03:01:01 -0400 Received: from mx20.gnu.org ([199.232.41.8]:7931) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1Mw9TI-0004oO-5T for qemu-devel@nongnu.org; Fri, 09 Oct 2009 03:01:00 -0400 Received: from mx1.redhat.com ([209.132.183.28]) by mx20.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1Mw9TH-0008So-BR for qemu-devel@nongnu.org; Fri, 09 Oct 2009 03:00:59 -0400 Date: Fri, 9 Oct 2009 08:58:53 +0200 From: "Michael S. Tsirkin" Message-ID: <20091009065853.GG9942@redhat.com> References: <1255069742-15724-1-git-send-email-yamahata@valinux.co.jp> <1255069742-15724-10-git-send-email-yamahata@valinux.co.jp> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1255069742-15724-10-git-send-email-yamahata@valinux.co.jp> Subject: [Qemu-devel] Re: [PATCH V5 09/29] pci: clean up of pci_default_read_config. List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Isaku Yamahata Cc: qemu-devel@nongnu.org On Fri, Oct 09, 2009 at 03:28:42PM +0900, Isaku Yamahata wrote: > 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) > -- > 1.6.0.2