[RFC PATCH 10/15] virtio: Handle virtio_device_ready() failure

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


Now virtio_device_ready() will return error if we get
invalid status. Let's handle this case in virtio_dev_probe().

Signed-off-by: Xie Yongji <xieyongji@xxxxxxxxxxxxx>
---
drivers/virtio/virtio.c | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/drivers/virtio/virtio.c b/drivers/virtio/virtio.c
index 4b15c00c0a0a..ff16e1cce2e7 100644
--- a/drivers/virtio/virtio.c
+++ b/drivers/virtio/virtio.c
@@ -263,8 +263,11 @@ static int virtio_dev_probe(struct device *_d)
goto err;

/* If probe didn't do it, mark device DRIVER_OK ourselves. */
- if (!(dev->config->get_status(dev) & VIRTIO_CONFIG_S_DRIVER_OK))
- virtio_device_ready(dev);
+ if (!(dev->config->get_status(dev) & VIRTIO_CONFIG_S_DRIVER_OK)) {
+ err = virtio_device_ready(dev);
+ if (err)
+ goto err_ready;
+ }

if (drv->scan)
drv->scan(dev);
@@ -272,6 +275,8 @@ static int virtio_dev_probe(struct device *_d)
virtio_config_enable(dev);

return 0;
+err_ready:
+ drv->remove(dev);
err:
virtio_add_status(dev, VIRTIO_CONFIG_S_FAILED);
return err;
--
2.11.0