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. 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 342785c76..9118377d7 100644 --- a/drivers/iommu/virtio-iommu.c +++ b/drivers/iommu/virtio-iommu.c @@ -1240,7 +1240,9 @@ static int viommu_probe(struct virtio_device *vdev) 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_remove_sysfs; dev_info(dev, "input address: %u bits\n", order_base_2(viommu->geometry.aperture_end)); @@ -1248,8 +1250,11 @@ static int viommu_probe(struct virtio_device *vdev) return 0; +err_remove_sysfs: + iommu_device_sysfs_remove(&viommu->iommu); err_free_vqs: vdev->config->del_vqs(vdev); + vdev->priv = NULL; return ret; } -- 2.43.0

