From: Xiong Weimin <[email protected]> From: Xiong Weimin <[email protected]>
iommu_device_register() returns an error when the IOMMU core fails to register the hardware instance or probe the buses. viommu_probe() currently ignores that error and continues as if the device was registered successfully. Propagate the failure and unwind the sysfs entry and virtqueues that were set up earlier. Clear the driver data on the error path as well, since it is set before registration so bus probing can find the virtio-IOMMU instance. Reviewed-by: Will Deacon <[email protected]> Signed-off-by: Xiong Weimin <[email protected]> --- drivers/iommu/virtio-iommu.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) 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 @@ -1234,9 +1234,11 @@ 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 +1246,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

