[RFC PATCH 07/15] virtio-net: Handle virtio_device_ready() failure

From: Xie Yongji
Date: Mon May 17 2021 - 05:37:03 EST


Now virtio_device_ready() will return error if we get
invalid status. Let's handle this case in both probe
and resume paths.

Signed-off-by: Xie Yongji <xieyongji@xxxxxxxxxxxxx>
---
drivers/net/virtio_net.c | 19 ++++++++++++++-----
1 file changed, 14 insertions(+), 5 deletions(-)

diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
index 01e54e99cae6..c4711e23af88 100644
--- a/drivers/net/virtio_net.c
+++ b/drivers/net/virtio_net.c
@@ -2341,6 +2341,7 @@ static void virtnet_freeze_down(struct virtio_device *vdev)
}

static int init_vqs(struct virtnet_info *vi);
+static void virtnet_del_vqs(struct virtnet_info *vi);

static int virtnet_restore_up(struct virtio_device *vdev)
{
@@ -2351,7 +2352,11 @@ static int virtnet_restore_up(struct virtio_device *vdev)
if (err)
return err;

- virtio_device_ready(vdev);
+ err = virtio_device_ready(vdev);
+ if (err) {
+ virtnet_del_vqs(vi);
+ return err;
+ }

if (netif_running(vi->dev)) {
for (i = 0; i < vi->curr_queue_pairs; i++)
@@ -3148,12 +3153,16 @@ static int virtnet_probe(struct virtio_device *vdev)
goto free_failover;
}

- virtio_device_ready(vdev);
+ err = virtio_device_ready(vdev);
+ if (err) {
+ pr_debug("virtio_net: enable virtio device failed\n");
+ goto free_unregister_netdev;
+ }

err = virtnet_cpu_notif_add(vi);
if (err) {
pr_debug("virtio_net: registering cpu notifier failed\n");
- goto free_unregister_netdev;
+ goto reset_virtio_device;
}

virtnet_set_queues(vi, vi->curr_queue_pairs);
@@ -3179,9 +3188,9 @@ static int virtnet_probe(struct virtio_device *vdev)

return 0;

-free_unregister_netdev:
+reset_virtio_device:
vi->vdev->config->reset(vdev);
-
+free_unregister_netdev:
unregister_netdev(dev);
free_failover:
net_failover_destroy(vi->failover);
--
2.11.0