virtio: move allocation before initialization
authorStephen Hemminger <stephen@networkplumber.org>
Mon, 9 Feb 2015 01:14:01 +0000 (09:14 +0800)
committerThomas Monjalon <thomas.monjalon@6wind.com>
Fri, 20 Feb 2015 18:18:57 +0000 (19:18 +0100)
If allocation fails, don't want to leave virtio device stuck
in middle of initialization sequence.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
Signed-off-by: Changchun Ouyang <changchun.ouyang@intel.com>
Acked-by: Huawei Xie <huawei.xie@intel.com>
lib/librte_pmd_virtio/virtio_ethdev.c

index cb8764d..d5951db 100644 (file)
@@ -885,6 +885,15 @@ eth_virtio_dev_init(__rte_unused struct eth_driver *eth_drv,
        if (rte_eal_process_type() == RTE_PROC_SECONDARY)
                return 0;
 
+       /* Allocate memory for storing MAC addresses */
+       eth_dev->data->mac_addrs = rte_zmalloc("virtio", ETHER_ADDR_LEN, 0);
+       if (eth_dev->data->mac_addrs == NULL) {
+               PMD_INIT_LOG(ERR,
+                       "Failed to allocate %d bytes needed to store MAC addresses",
+                       ETHER_ADDR_LEN);
+               return -ENOMEM;
+       }
+
        pci_dev = eth_dev->pci_dev;
        if (virtio_resource_init(pci_dev) < 0)
                return -1;
@@ -911,15 +920,6 @@ eth_virtio_dev_init(__rte_unused struct eth_driver *eth_drv,
                hw->vtnet_hdr_size = sizeof(struct virtio_net_hdr);
        }
 
-       /* Allocate memory for storing MAC addresses */
-       eth_dev->data->mac_addrs = rte_zmalloc("virtio", ETHER_ADDR_LEN, 0);
-       if (eth_dev->data->mac_addrs == NULL) {
-               PMD_INIT_LOG(ERR,
-                       "Failed to allocate %d bytes needed to store MAC addresses",
-                       ETHER_ADDR_LEN);
-               return -ENOMEM;
-       }
-
        /* Copy the permanent MAC address to: virtio_hw */
        virtio_get_hwaddr(hw);
        ether_addr_copy((struct ether_addr *) hw->mac_addr,