From 72b65f922b7b925ed67847017dcd0539e49d925f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Date: Mon, 6 Jun 2016 18:45:04 +0200 Subject: vhost-net: do not crash if backend is not present MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Do not crash when backend is not present while enabling the ring. A following patch will save the enabled state so it can be restored once the backend is started. Signed-off-by: Marc-André Lureau Tested-by: Yuanhan Liu Reviewed-by: Yuanhan Liu Reviewed-by: Victor Kaplansky Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- hw/net/vhost_net.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'hw/net/vhost_net.c') diff --git a/hw/net/vhost_net.c b/hw/net/vhost_net.c index 6e1032fc18..805a0df7d1 100644 --- a/hw/net/vhost_net.c +++ b/hw/net/vhost_net.c @@ -401,8 +401,13 @@ VHostNetState *get_vhost_net(NetClientState *nc) int vhost_set_vring_enable(NetClientState *nc, int enable) { VHostNetState *net = get_vhost_net(nc); - const VhostOps *vhost_ops = net->dev.vhost_ops; + const VhostOps *vhost_ops; + + if (!net) { + return 0; + } + vhost_ops = net->dev.vhost_ops; if (vhost_ops->vhost_set_vring_enable) { return vhost_ops->vhost_set_vring_enable(&net->dev, enable); } -- cgit v1.2.3