From cc8b330e5729312a0632fd0e9f28e8f136a76182 Mon Sep 17 00:00:00 2001 From: Costin Lupu Date: Tue, 15 Dec 2020 16:50:12 +0000 Subject: [PATCH] mini-os: netfront: Handle init failure when no vifs are provided These changes deal with the case when no vifs are created. This can happen when no vif is provided in the config file for mini-os images with netfront support. Signed-off-by: Costin Lupu Reviewed-by: Samuel Thibault --- lwip-net.c | 4 ++++ netfront.c | 9 +++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/lwip-net.c b/lwip-net.c index 7e0d871..16950d3 100644 --- a/lwip-net.c +++ b/lwip-net.c @@ -348,6 +348,10 @@ void start_networking(void) tprintk("Waiting for network.\n"); dev = init_netfront(NULL, NULL, rawmac, &ip); + if (!dev) { + tprintk("Error initializing netfront.\n"); + return; + } netmask_str = netfront_get_netmask(dev); gw_str = netfront_get_gateway(dev); diff --git a/netfront.c b/netfront.c index 2075410..f927e99 100644 --- a/netfront.c +++ b/netfront.c @@ -383,6 +383,7 @@ char *netfront_get_gateway(struct netfront_dev *dev) static struct netfront_dev *_init_netfront(struct netfront_dev *dev) { + int domid; xenbus_transaction_t xbt; char* err = NULL; char* message=NULL; @@ -393,6 +394,12 @@ static struct netfront_dev *_init_netfront(struct netfront_dev *dev) int i; char path[256]; + snprintf(path, sizeof(path), "%s/backend-id", dev->nodename); + domid = xenbus_read_integer(path); + if (domid < 0) + return NULL; + dev->dom = domid; + printk("net TX ring size %lu\n", (unsigned long) NET_TX_RING_SIZE); printk("net RX ring size %lu\n", (unsigned long) NET_RX_RING_SIZE); init_SEMAPHORE(&dev->tx_sem, NET_TX_RING_SIZE); @@ -407,8 +414,6 @@ static struct netfront_dev *_init_netfront(struct netfront_dev *dev) BUG_ON(dev->rx_buffers[i].page == NULL); } - snprintf(path, sizeof(path), "%s/backend-id", dev->nodename); - dev->dom = xenbus_read_integer(path); #ifdef HAVE_LIBC if (dev->netif_rx == NETIF_SELECT_RX) evtchn_alloc_unbound(dev->dom, netfront_select_handler, dev, &dev->evtchn); -- 2.39.5