From patchwork Thu Nov 12 12:08:05 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: 38244 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 57BB8B7B63 for ; Thu, 12 Nov 2009 23:15:45 +1100 (EST) Received: from localhost ([127.0.0.1]:41998 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1N8YaT-0000oG-J2 for incoming@patchwork.ozlabs.org; Thu, 12 Nov 2009 07:15:41 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1N8YVg-0006Fl-2J for qemu-devel@nongnu.org; Thu, 12 Nov 2009 07:10:44 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1N8YVb-00066U-Di for qemu-devel@nongnu.org; Thu, 12 Nov 2009 07:10:43 -0500 Received: from [199.232.76.173] (port=54977 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1N8YVa-000666-TN for qemu-devel@nongnu.org; Thu, 12 Nov 2009 07:10:38 -0500 Received: from mx1.redhat.com ([209.132.183.28]:56089) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1N8YVa-0001YN-FH for qemu-devel@nongnu.org; Thu, 12 Nov 2009 07:10:38 -0500 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 nACCAb7b005501 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 12 Nov 2009 07:10:37 -0500 Received: from redhat.com (vpn1-7-66.ams2.redhat.com [10.36.7.66]) by int-mx03.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with SMTP id nACCAY4s008186; Thu, 12 Nov 2009 07:10:35 -0500 Date: Thu, 12 Nov 2009 14:08:05 +0200 From: "Michael S. Tsirkin" To: Isaku Yamahata Message-ID: <20091112120805.GC11106@redhat.com> References: <1258005528-25383-1-git-send-email-yamahata@valinux.co.jp> <1258005528-25383-21-git-send-email-yamahata@valinux.co.jp> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <1258005528-25383-21-git-send-email-yamahata@valinux.co.jp> User-Agent: Mutt/1.5.19 (2009-01-05) X-Scanned-By: MIMEDefang 2.67 on 10.5.11.16 X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized. Cc: qemu-devel@nongnu.org Subject: [Qemu-devel] Re: [PATCH 20/20] pci: remove goto in pci_bridge_filter(). 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 On Thu, Nov 12, 2009 at 02:58:48PM +0900, Isaku Yamahata wrote: > This patch removes ugly goto in pci_bridge_filter() by > introducing subfunction, pci_bridge_filter_nomap(). > > Signed-off-by: Isaku Yamahata goto on error is actually cleaner IMO. just *not into scope*. > --- > hw/pci.c | 16 +++++++++++----- > 1 files changed, 11 insertions(+), 5 deletions(-) > > diff --git a/hw/pci.c b/hw/pci.c > index add919b..90bdf5e 100644 > --- a/hw/pci.c > +++ b/hw/pci.c > @@ -691,6 +691,12 @@ static pcibus_t pci_bridge_get_limit(PCIDevice *bridge, uint8_t type) > return limit; > } > > +static void pci_bridge_filter_nomap(pcibus_t *addr, pcibus_t *size) > +{ > + *addr = PCI_BAR_UNMAPPED; > + *size = 0; > +} > + > static void pci_bridge_filter(PCIDevice *d, pcibus_t *addr, pcibus_t *size, > uint8_t type) > { > @@ -703,11 +709,13 @@ static void pci_bridge_filter(PCIDevice *d, pcibus_t *addr, pcibus_t *size, > > if (type & PCI_BASE_ADDRESS_SPACE_IO) { > if (!(cmd & PCI_COMMAND_IO)) { > - goto no_map; > + pci_bridge_filter_nomap(addr, size); > + return; > } > } else { > if (!(cmd & PCI_COMMAND_MEMORY)) { > - goto no_map; > + pci_bridge_filter_nomap(addr, size); > + return; > } > } > > @@ -716,9 +724,7 @@ static void pci_bridge_filter(PCIDevice *d, pcibus_t *addr, pcibus_t *size, > } > > if (base > limit) { > - no_map: > - *addr = PCI_BAR_UNMAPPED; > - *size = 0; > + pci_bridge_filter_nomap(addr, size); > } else { > *addr = base; > *size = limit - base + 1; Here's what I came up with: ---> From: Michael S. Tsirkin Subject: pci: convert goto into scope in bridge_filter goto into scope is evil. rearrange pci_bridge_filter so that we always go to end of function on error. Signed-off-by: Michael S. Tsirkin Acked-by: Isaku Yamahata diff --git a/hw/pci.c b/hw/pci.c index 14de2d1..6e5d57b 100644 --- a/hw/pci.c +++ b/hw/pci.c @@ -716,13 +716,14 @@ static void pci_bridge_filter(PCIDevice *d, pcibus_t *addr, pcibus_t *size, } if (base > limit) { - no_map: - *addr = PCI_BAR_UNMAPPED; - *size = 0; - } else { - *addr = base; - *size = limit - base + 1; + goto no_map; } + *addr = base; + *size = limit - base + 1; + return; +no_map: + *addr = PCI_BAR_UNMAPPED; + *size = 0; } static pcibus_t pci_bar_address(PCIDevice *d,