vfio: check vfio_register_iommu_driver() return value
authorBo Liu <liubo03@inspur.com>
Wed, 22 Jun 2022 04:56:51 +0000 (00:56 -0400)
committerAlex Williamson <alex.williamson@redhat.com>
Mon, 27 Jun 2022 19:57:08 +0000 (13:57 -0600)
As vfio_register_iommu_driver() can fail, we should check the return value.

Signed-off-by: Bo Liu <liubo03@inspur.com>
Acked-by: Cornelia Huck <cohuck@redhat.com>
Link: https://lore.kernel.org/r/20220622045651.5416-1-liubo03@inspur.com
Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
drivers/vfio/vfio.c

index 61e71c1..8f435c0 100644 (file)
@@ -2156,13 +2156,17 @@ static int __init vfio_init(void)
        if (ret)
                goto err_alloc_chrdev;
 
-       pr_info(DRIVER_DESC " version: " DRIVER_VERSION "\n");
-
 #ifdef CONFIG_VFIO_NOIOMMU
-       vfio_register_iommu_driver(&vfio_noiommu_ops);
+       ret = vfio_register_iommu_driver(&vfio_noiommu_ops);
 #endif
+       if (ret)
+               goto err_driver_register;
+
+       pr_info(DRIVER_DESC " version: " DRIVER_VERSION "\n");
        return 0;
 
+err_driver_register:
+       unregister_chrdev_region(vfio.group_devt, MINORMASK + 1);
 err_alloc_chrdev:
        class_destroy(vfio.class);
        vfio.class = NULL;