48e123e
From 0ce1af6e7d4b1e2ffa4dedf6d415c4d86a1af490 Mon Sep 17 00:00:00 2001
48e123e
From: Markus Armbruster <armbru@redhat.com>
48e123e
Date: Fri, 25 Sep 2009 03:53:50 +0200
48e123e
Subject: [PATCH] Make it obvious that pci_nic_init() can't fail
48e123e
48e123e
Before this patch, pci_nic_init() returns NULL when it can't find the
48e123e
model in pci_nic_models[].  Except this can't happen, because
48e123e
qemu_check_nic_model_list() just searched for model in
48e123e
pci_nic_models[], and terminated the program on failure.
48e123e
48e123e
Repeating the search here is pointless.  Instead, change
48e123e
qemu_check_nic_model_list() to return the model's array index.
48e123e
48e123e
Signed-off-by: Markus Armbruster <armbru@redhat.com>
48e123e
Signed-off-by: Mark McLoughlin 
48e123e
Fedora-patch: qemu-do-not-exit-on-pci-hotplug-invalid-nic1.patch
48e123e
---
48e123e
 hw/pci.c |   25 +++++++++----------------
48e123e
 net.c    |    6 +++---
48e123e
 net.h    |    4 ++--
48e123e
 3 files changed, 14 insertions(+), 21 deletions(-)
48e123e
48e123e
diff --git a/hw/pci.c b/hw/pci.c
48e123e
index a575d4a..eb990f9 100644
48e123e
--- a/hw/pci.c
48e123e
+++ b/hw/pci.c
48e123e
@@ -937,22 +937,15 @@ PCIDevice *pci_nic_init(NICInfo *nd, const char *default_model,
48e123e
     DeviceState *dev;
48e123e
     int i;
48e123e
 
48e123e
-    qemu_check_nic_model_list(nd, pci_nic_models, default_model);
48e123e
-
48e123e
-    for (i = 0; pci_nic_models[i]; i++) {
48e123e
-        if (strcmp(nd->model, pci_nic_models[i]) == 0) {
48e123e
-            pci_dev = pci_create(pci_nic_names[i], devaddr);
48e123e
-            dev = &pci_dev->qdev;
48e123e
-            if (nd->id)
48e123e
-                dev->id = qemu_strdup(nd->id);
48e123e
-            dev->nd = nd;
48e123e
-            qdev_init(dev);
48e123e
-            nd->private = dev;
48e123e
-            return pci_dev;
48e123e
-        }
48e123e
-    }
48e123e
-
48e123e
-    return NULL;
48e123e
+    i = qemu_check_nic_model_list(nd, pci_nic_models, default_model);
48e123e
+    pci_dev = pci_create(pci_nic_names[i], devaddr);
48e123e
+    dev = &pci_dev->qdev;
48e123e
+    if (nd->id)
48e123e
+        dev->id = qemu_strdup(nd->id);
48e123e
+    dev->nd = nd;
48e123e
+    qdev_init(dev);
48e123e
+    nd->private = dev;
48e123e
+    return pci_dev;
48e123e
 }
48e123e
 
48e123e
 typedef struct {
48e123e
diff --git a/net.c b/net.c
48e123e
index da2f428..047e72e 100644
48e123e
--- a/net.c
48e123e
+++ b/net.c
48e123e
@@ -2553,8 +2553,8 @@ void qemu_check_nic_model(NICInfo *nd, const char *model)
48e123e
     qemu_check_nic_model_list(nd, models, model);
48e123e
 }
48e123e
 
48e123e
-void qemu_check_nic_model_list(NICInfo *nd, const char * const *models,
48e123e
-                               const char *default_model)
48e123e
+int qemu_check_nic_model_list(NICInfo *nd, const char * const *models,
48e123e
+                              const char *default_model)
48e123e
 {
48e123e
     int i, exit_status = 0;
48e123e
 
48e123e
@@ -2564,7 +2564,7 @@ void qemu_check_nic_model_list(NICInfo *nd, const char * const *models,
48e123e
     if (strcmp(nd->model, "?") != 0) {
48e123e
         for (i = 0 ; models[i]; i++)
48e123e
             if (strcmp(nd->model, models[i]) == 0)
48e123e
-                return;
48e123e
+                return i;
48e123e
 
48e123e
         fprintf(stderr, "qemu: Unsupported NIC model: %s\n", nd->model);
48e123e
         exit_status = 1;
48e123e
diff --git a/net.h b/net.h
48e123e
index 94db0d7..9662988 100644
48e123e
--- a/net.h
48e123e
+++ b/net.h
48e123e
@@ -80,8 +80,8 @@ void qemu_purge_queued_packets(VLANClientState *vc);
48e123e
 void qemu_flush_queued_packets(VLANClientState *vc);
48e123e
 void qemu_format_nic_info_str(VLANClientState *vc, uint8_t macaddr[6]);
48e123e
 void qemu_check_nic_model(NICInfo *nd, const char *model);
48e123e
-void qemu_check_nic_model_list(NICInfo *nd, const char * const *models,
48e123e
-                               const char *default_model);
48e123e
+int qemu_check_nic_model_list(NICInfo *nd, const char * const *models,
48e123e
+                              const char *default_model);
48e123e
 void qemu_handler_true(void *opaque);
48e123e
 
48e123e
 void do_info_network(Monitor *mon);
48e123e
-- 
48e123e
1.6.2.5
48e123e