Skip to content

Commit 1334e47

Browse files
yiliu1765jgunthorpe
authored andcommitted
vfio: Wrap vfio group module init/clean code into helpers
This wraps the init/clean code of vfio group global variable to be helpers, and prepares for further moving vfio group specific code into separate file. As container is used by group, so vfio_container_init/cleanup() is moved into vfio_group_init/cleanup(). Link: https://lore.kernel.org/r/[email protected] Reviewed-by: Kevin Tian <[email protected]> Reviewed-by: Jason Gunthorpe <[email protected]> Reviewed-by: Alex Williamson <[email protected]> Tested-by: Lixiao Yang <[email protected]> Tested-by: Yu He <[email protected]> Signed-off-by: Yi Liu <[email protected]> Signed-off-by: Jason Gunthorpe <[email protected]>
1 parent 5c8d3d9 commit 1334e47

File tree

1 file changed

+36
-20
lines changed

1 file changed

+36
-20
lines changed

drivers/vfio/vfio_main.c

Lines changed: 36 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2066,12 +2066,11 @@ static char *vfio_devnode(struct device *dev, umode_t *mode)
20662066
return kasprintf(GFP_KERNEL, "vfio/%s", dev_name(dev));
20672067
}
20682068

2069-
static int __init vfio_init(void)
2069+
static int __init vfio_group_init(void)
20702070
{
20712071
int ret;
20722072

20732073
ida_init(&vfio.group_ida);
2074-
ida_init(&vfio.device_ida);
20752074
mutex_init(&vfio.group_lock);
20762075
INIT_LIST_HEAD(&vfio.group_list);
20772076

@@ -2088,43 +2087,60 @@ static int __init vfio_init(void)
20882087

20892088
vfio.class->devnode = vfio_devnode;
20902089

2091-
/* /sys/class/vfio-dev/vfioX */
2092-
vfio.device_class = class_create(THIS_MODULE, "vfio-dev");
2093-
if (IS_ERR(vfio.device_class)) {
2094-
ret = PTR_ERR(vfio.device_class);
2095-
goto err_dev_class;
2096-
}
2097-
20982090
ret = alloc_chrdev_region(&vfio.group_devt, 0, MINORMASK + 1, "vfio");
20992091
if (ret)
21002092
goto err_alloc_chrdev;
2101-
2102-
pr_info(DRIVER_DESC " version: " DRIVER_VERSION "\n");
21032093
return 0;
21042094

21052095
err_alloc_chrdev:
2106-
class_destroy(vfio.device_class);
2107-
vfio.device_class = NULL;
2108-
err_dev_class:
21092096
class_destroy(vfio.class);
21102097
vfio.class = NULL;
21112098
err_group_class:
21122099
vfio_container_cleanup();
21132100
return ret;
21142101
}
21152102

2116-
static void __exit vfio_cleanup(void)
2103+
static void vfio_group_cleanup(void)
21172104
{
21182105
WARN_ON(!list_empty(&vfio.group_list));
2119-
2120-
ida_destroy(&vfio.device_ida);
21212106
ida_destroy(&vfio.group_ida);
21222107
unregister_chrdev_region(vfio.group_devt, MINORMASK + 1);
2123-
class_destroy(vfio.device_class);
2124-
vfio.device_class = NULL;
21252108
class_destroy(vfio.class);
2126-
vfio_container_cleanup();
21272109
vfio.class = NULL;
2110+
vfio_container_cleanup();
2111+
}
2112+
2113+
static int __init vfio_init(void)
2114+
{
2115+
int ret;
2116+
2117+
ida_init(&vfio.device_ida);
2118+
2119+
ret = vfio_group_init();
2120+
if (ret)
2121+
return ret;
2122+
2123+
/* /sys/class/vfio-dev/vfioX */
2124+
vfio.device_class = class_create(THIS_MODULE, "vfio-dev");
2125+
if (IS_ERR(vfio.device_class)) {
2126+
ret = PTR_ERR(vfio.device_class);
2127+
goto err_dev_class;
2128+
}
2129+
2130+
pr_info(DRIVER_DESC " version: " DRIVER_VERSION "\n");
2131+
return 0;
2132+
2133+
err_dev_class:
2134+
vfio_group_cleanup();
2135+
return ret;
2136+
}
2137+
2138+
static void __exit vfio_cleanup(void)
2139+
{
2140+
ida_destroy(&vfio.device_ida);
2141+
class_destroy(vfio.device_class);
2142+
vfio.device_class = NULL;
2143+
vfio_group_cleanup();
21282144
xa_destroy(&vfio_device_set_xa);
21292145
}
21302146

0 commit comments

Comments
 (0)