From: Xiong Weimin <[email protected]>

From: Xiong Weimin <[email protected]>

The event virtqueue callback retrieves the driver state through
vq->vdev->priv. viommu_probe() currently initializes that pointer only
after virtio_device_ready() and after the event queue is populated.

Store the driver data before creating the virtqueues so callbacks always
see initialized driver state once the device is made ready. Clear the
pointer again on probe failure.

Signed-off-by: Xiong Weimin <[email protected]>
---
 drivers/iommu/virtio-iommu.c | 14 ++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/drivers/iommu/virtio-iommu.c b/drivers/iommu/virtio-iommu.c
index 587fc1319..fb19d0bf4 100644
--- a/drivers/iommu/virtio-iommu.c
+++ b/drivers/iommu/virtio-iommu.c
@@ -1169,11 +1169,12 @@ static int viommu_probe(struct virtio_device *vdev)
        ida_init(&viommu->domain_ids);
        viommu->dev = dev;
        viommu->vdev = vdev;
+       vdev->priv = viommu;
        INIT_LIST_HEAD(&viommu->requests);
 
        ret = viommu_init_vqs(viommu);
        if (ret)
-               return ret;
+               goto err_clear_priv;
 
        virtio_cread_le(vdev, struct virtio_iommu_config, page_size_mask,
                        &viommu->pgsize_bitmap);
@@ -1234,9 +1235,9 @@ static int viommu_probe(struct virtio_device *vdev)
        if (ret)
                goto err_free_vqs;
 
-       vdev->priv = viommu;
-
-       iommu_device_register(&viommu->iommu, &viommu_ops, parent_dev);
+       ret = iommu_device_register(&viommu->iommu, &viommu_ops, parent_dev);
+       if (ret)
+               goto err_free_sysfs;
 
        dev_info(dev, "input address: %u bits\n",
                 order_base_2(viommu->geometry.aperture_end));
@@ -1244,8 +1245,12 @@ static int viommu_probe(struct virtio_device *vdev)
 
        return 0;
 
+err_free_sysfs:
+       iommu_device_sysfs_remove(&viommu->iommu);
 err_free_vqs:
        vdev->config->del_vqs(vdev);
+err_clear_priv:
+       vdev->priv = NULL;
 
        return ret;
 }
-- 
2.43.0


Reply via email to