Pci nic: pci_register_device can fail
authorChris Wright <chrisw@sous-sol.org>
Mon, 21 Apr 2008 23:02:48 +0000 (16:02 -0700)
committerAnthony Liguori <aliguori@us.ibm.com>
Fri, 1 May 2009 14:47:14 +0000 (09:47 -0500)
The pci_register_device() call in PCI nic initialization routines can
fail.  Handle this failure and propagate a meaningful error message to
the user instead of generating a SEGV.

Cc: Marcelo Tosatti <mtosatti@redhat.com>
Signed-off-by: Chris Wright <chrisw@sous-sol.org>
Signed-off-by: Avi Kivity <avi@qumranet.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
hw/e1000.c
hw/eepro100.c
hw/ne2000.c
hw/pcnet.c
hw/rtl8139.c

index 1729db28e1ea690e54eb6d9f7678ce30b3ca5e0f..b0fe917342bd3c2023650202d537f86e9ff0bb84 100644 (file)
@@ -1063,6 +1063,9 @@ pci_e1000_init(PCIBus *bus, NICInfo *nd, int devfn)
     d = (E1000State *)pci_register_device(bus, "e1000",
                 sizeof(E1000State), devfn, NULL, NULL);
 
+    if (!d)
+       return NULL;
+
     pci_conf = d->dev.config;
     memset(pci_conf, 0, 256);
 
index 18d81153bf872fcacabb5eea4c6db51eb0f18df3..235e598725c35aa5e9b12651a97db9bbabb4d933 100644 (file)
@@ -1739,6 +1739,9 @@ static PCIDevice *nic_init(PCIBus * bus, NICInfo * nd, uint32_t device)
     d = (PCIEEPRO100State *) pci_register_device(bus, nd->model,
                                                  sizeof(PCIEEPRO100State), -1,
                                                  NULL, NULL);
+    if (!d)
+        return NULL;
+
     d->dev.unregister = pci_nic_uninit;
 
     s = &d->eepro100;
index 99612e25899aa5c93c204aa7b1f00a9b0015ee5c..613ac411f89b15c20e8a5e925762fb04f450012d 100644 (file)
@@ -810,6 +810,9 @@ PCIDevice *pci_ne2000_init(PCIBus *bus, NICInfo *nd, int devfn)
                                               "NE2000", sizeof(PCINE2000State),
                                               devfn,
                                               NULL, NULL);
+    if (!d)
+       return NULL;
+
     pci_conf = d->dev.config;
     pci_config_set_vendor_id(pci_conf, PCI_VENDOR_ID_REALTEK);
     pci_config_set_device_id(pci_conf, PCI_DEVICE_ID_REALTEK_8029);
index acbaee6cdd63c62815192d1ad3203e8a60d7fe78..654340b68fe2aa035ca8a402766c24bc8e4ede1b 100644 (file)
@@ -2023,7 +2023,11 @@ PCIDevice *pci_pcnet_init(PCIBus *bus, NICInfo *nd, int devfn)
 
     d = (PCNetState *)pci_register_device(bus, "PCNet", sizeof(PCNetState),
                                           devfn, NULL, NULL);
+    if (!d)
+       return NULL;
+
     d->dev.unregister = pci_pcnet_uninit;
+
     pci_conf = d->dev.config;
 
     pci_config_set_vendor_id(pci_conf, PCI_VENDOR_ID_AMD);
index 0093ff4a930d3344f6ac264a1a8c969a72c81c2e..19c7623c58ac14bf758369ea8a962c9129d4231c 100644 (file)
@@ -3451,7 +3451,11 @@ PCIDevice *pci_rtl8139_init(PCIBus *bus, NICInfo *nd, int devfn)
                                               "RTL8139", sizeof(PCIRTL8139State),
                                               devfn,
                                               NULL, NULL);
+    if (!d)
+       return NULL;
+
     d->dev.unregister = pci_rtl8139_uninit;
+
     pci_conf = d->dev.config;
     pci_config_set_vendor_id(pci_conf, PCI_VENDOR_ID_REALTEK);
     pci_config_set_device_id(pci_conf, PCI_DEVICE_ID_REALTEK_8139);