From patchwork Fri Sep 25 01:53:50 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Markus Armbruster X-Patchwork-Id: 34250 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 2BD58B7B91 for ; Fri, 25 Sep 2009 12:03:45 +1000 (EST) Received: from localhost ([127.0.0.1]:40458 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Mr09u-0006Pf-Is for incoming@patchwork.ozlabs.org; Thu, 24 Sep 2009 22:03:42 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Mr00c-00042U-4o for qemu-devel@nongnu.org; Thu, 24 Sep 2009 21:54:06 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1Mr00X-00040N-75 for qemu-devel@nongnu.org; Thu, 24 Sep 2009 21:54:05 -0400 Received: from [199.232.76.173] (port=39180 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Mr00X-00040K-1r for qemu-devel@nongnu.org; Thu, 24 Sep 2009 21:54:01 -0400 Received: from oxygen.pond.sub.org ([213.239.205.148]:39231) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1Mr00W-0000ao-E8 for qemu-devel@nongnu.org; Thu, 24 Sep 2009 21:54:00 -0400 Received: from pike.pond.sub.org (pD9E39B51.dip.t-dialin.net [217.227.155.81]) by oxygen.pond.sub.org (Postfix) with ESMTPA id CDC02276D1B for ; Fri, 25 Sep 2009 03:53:58 +0200 (CEST) Received: by pike.pond.sub.org (Postfix, from userid 1000) id 58A59100A0; Fri, 25 Sep 2009 03:53:53 +0200 (CEST) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Fri, 25 Sep 2009 03:53:50 +0200 Message-Id: <77f0efd64b83c1177166dd1c9a11730913857352.1253843233.git.armbru@redhat.com> X-Mailer: git-send-email 1.6.0.6 In-Reply-To: References: X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6 (newer, 3) Subject: [Qemu-devel] [PATCH 3/6] Make it obvious that pci_nic_init() can't fail 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 Before this patch, pci_nic_init() returns NULL when it can't find the model in pci_nic_models[]. Except this can't happen, because qemu_check_nic_model_list() just searched for model in pci_nic_models[], and terminated the program on failure. Repeating the search here is pointless. Instead, change qemu_check_nic_model_list() to return the model's array index. Signed-off-by: Markus Armbruster --- hw/pci.c | 25 +++++++++---------------- net.c | 6 +++--- net.h | 4 ++-- 3 files changed, 14 insertions(+), 21 deletions(-) diff --git a/hw/pci.c b/hw/pci.c index 5be21d7..92262f7 100644 --- a/hw/pci.c +++ b/hw/pci.c @@ -815,22 +815,15 @@ PCIDevice *pci_nic_init(NICInfo *nd, const char *default_model, DeviceState *dev; int i; - qemu_check_nic_model_list(nd, pci_nic_models, default_model); - - for (i = 0; pci_nic_models[i]; i++) { - if (strcmp(nd->model, pci_nic_models[i]) == 0) { - pci_dev = pci_create(pci_nic_names[i], devaddr); - dev = &pci_dev->qdev; - if (nd->id) - dev->id = qemu_strdup(nd->id); - dev->nd = nd; - qdev_init(dev); - nd->private = dev; - return pci_dev; - } - } - - return NULL; + i = qemu_check_nic_model_list(nd, pci_nic_models, default_model); + pci_dev = pci_create(pci_nic_names[i], devaddr); + dev = &pci_dev->qdev; + if (nd->id) + dev->id = qemu_strdup(nd->id); + dev->nd = nd; + qdev_init(dev); + nd->private = dev; + return pci_dev; } typedef struct { diff --git a/net.c b/net.c index 3fdf1e6..0eba08b 100644 --- a/net.c +++ b/net.c @@ -2358,8 +2358,8 @@ void qemu_check_nic_model(NICInfo *nd, const char *model) qemu_check_nic_model_list(nd, models, model); } -void qemu_check_nic_model_list(NICInfo *nd, const char * const *models, - const char *default_model) +int qemu_check_nic_model_list(NICInfo *nd, const char * const *models, + const char *default_model) { int i, exit_status = 0; @@ -2369,7 +2369,7 @@ void qemu_check_nic_model_list(NICInfo *nd, const char * const *models, if (strcmp(nd->model, "?") != 0) { for (i = 0 ; models[i]; i++) if (strcmp(nd->model, models[i]) == 0) - return; + return i; fprintf(stderr, "qemu: Unsupported NIC model: %s\n", nd->model); exit_status = 1; diff --git a/net.h b/net.h index 1479826..c93cc99 100644 --- a/net.h +++ b/net.h @@ -76,8 +76,8 @@ void qemu_purge_queued_packets(VLANClientState *vc); void qemu_flush_queued_packets(VLANClientState *vc); void qemu_format_nic_info_str(VLANClientState *vc, uint8_t macaddr[6]); void qemu_check_nic_model(NICInfo *nd, const char *model); -void qemu_check_nic_model_list(NICInfo *nd, const char * const *models, - const char *default_model); +int qemu_check_nic_model_list(NICInfo *nd, const char * const *models, + const char *default_model); void qemu_handler_true(void *opaque); void do_info_network(Monitor *mon);