summary refs log tree commit diff stats
path: root/hw/pci.c
diff options
context:
space:
mode:
authorMarkus Armbruster <armbru@redhat.com>2009-09-25 03:53:51 +0200
committerAnthony Liguori <aliguori@us.ibm.com>2009-10-05 09:32:53 -0500
commit07caea315a85ebfe90851f9c2e4ef3fdd24117b5 (patch)
tree153e42950d500a7c6219539941ff7c1f81a6487b /hw/pci.c
parent9ee05825d9eaf7fe3aaed5ed04b83612ede704a0 (diff)
downloadfocaccia-qemu-07caea315a85ebfe90851f9c2e4ef3fdd24117b5.tar.gz
focaccia-qemu-07caea315a85ebfe90851f9c2e4ef3fdd24117b5.zip
Fix pci_add nic not to exit on bad model
Monitor command "pci_add ADDR nic model=MODEL" uses pci_nic_init() to
create the NIC.  When MODEL is unknown or "?", this prints to stderr
and terminates the program.

Change pci_nic_init() not to treat "?" specially, and to return NULL
on failure.  Switch uses during startup to new convenience wrapper
pci_nic_init_nofail(), which behaves just like pci_nic_init() used to
do.

Bonus bug fix: we now check for qdev_init() failing there.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Diffstat (limited to 'hw/pci.c')
-rw-r--r--hw/pci.c33
1 files changed, 30 insertions, 3 deletions
diff --git a/hw/pci.c b/hw/pci.c
index 295e15d07f..dfdae1cad7 100644
--- a/hw/pci.c
+++ b/hw/pci.c
@@ -867,21 +867,48 @@ PCIDevice *pci_nic_init(NICInfo *nd, const char *default_model,
                         const char *default_devaddr)
 {
     const char *devaddr = nd->devaddr ? nd->devaddr : default_devaddr;
+    PCIBus *bus;
+    int devfn;
     PCIDevice *pci_dev;
     DeviceState *dev;
     int i;
 
-    i = qemu_check_nic_model_list(nd, pci_nic_models, default_model);
-    pci_dev = pci_create(pci_nic_names[i], devaddr);
+    i = qemu_find_nic_model(nd, pci_nic_models, default_model);
+    if (i < 0)
+        return NULL;
+
+    bus = pci_get_bus_devfn(&devfn, devaddr);
+    if (!bus) {
+        qemu_error("Invalid PCI device address %s for device %s\n",
+                   devaddr, pci_nic_names[i]);
+        return NULL;
+    }
+
+    pci_dev = pci_create_noinit(bus, devfn, pci_nic_names[i]);
     dev = &pci_dev->qdev;
     if (nd->id)
         dev->id = qemu_strdup(nd->id);
     dev->nd = nd;
-    qdev_init(dev);
+    if (qdev_init(dev) < 0)
+        return NULL;
     nd->private = dev;
     return pci_dev;
 }
 
+PCIDevice *pci_nic_init_nofail(NICInfo *nd, const char *default_model,
+                               const char *default_devaddr)
+{
+    PCIDevice *res;
+
+    if (qemu_show_nic_models(nd->model, pci_nic_models))
+        exit(0);
+
+    res = pci_nic_init(nd, default_model, default_devaddr);
+    if (!res)
+        exit(1);
+    return res;
+}
+
 typedef struct {
     PCIDevice dev;
     PCIBus bus;