From 52fbd7024284fcb52ac6d9e8634d23a25badc2d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Date: Fri, 17 Jun 2016 13:45:40 +0200 Subject: [PATCH 07/25] 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 RH-Author: Marc-André Lureau Message-id: <1466171144-10377-7-git-send-email-marcandre.lureau@redhat.com> Patchwork-id: 70652 O-Subject: [RHEV-7.3 qemu-kvm-rhev PATCH 06/10] vhost-net: do not crash if backend is not present Bugzilla: 1322087 RH-Acked-by: Marcel Apfelbaum RH-Acked-by: Victor Kaplansky RH-Acked-by: Michael S. Tsirkin From: Marc-André Lureau 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 (cherry picked from commit 72b65f922b7b925ed67847017dcd0539e49d925f) Signed-off-by: Marc-André Lureau Signed-off-by: Miroslav Rezanina --- hw/net/vhost_net.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/hw/net/vhost_net.c b/hw/net/vhost_net.c index 6e1032f..805a0df 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); } -- 1.8.3.1