return 0;
}
-static char *vfio_device_devnode(const struct device *dev, umode_t *mode)
+int vfio_cdev_init(void)
{
- return kasprintf(GFP_KERNEL, "vfio/devices/%s", dev_name(dev));
-}
-
-int vfio_cdev_init(struct class *device_class)
-{
- device_class->devnode = vfio_device_devnode;
return alloc_chrdev_region(&device_devt, 0,
MINORMASK + 1, "vfio-dev");
}
long vfio_df_ioctl_bind_iommufd(struct vfio_device_file *df,
struct vfio_device_bind_iommufd __user *arg);
void vfio_df_unbind_iommufd(struct vfio_device_file *df);
-int vfio_cdev_init(struct class *device_class);
+int vfio_cdev_init(void);
void vfio_cdev_cleanup(void);
#else
static inline void vfio_init_device_cdev(struct vfio_device *device)
{
}
-static inline int vfio_cdev_init(struct class *device_class)
+static inline int vfio_cdev_init(void)
{
return 0;
}
#define VFIO_MAGIC 0x5646494f /* "VFIO" */
static struct vfio {
- struct class *device_class;
struct ida device_ida;
struct vfsmount *vfs_mount;
int fs_count;
static DEFINE_XARRAY(vfio_device_set_xa);
+static char *vfio_device_devnode(const struct device *dev, umode_t *mode)
+{
+ return kasprintf(GFP_KERNEL, "vfio/devices/%s", dev_name(dev));
+}
+
+static const struct class vfio_device_class = {
+ .name = "vfio-dev",
+ .devnode = vfio_device_devnode
+};
+
int vfio_assign_device_set(struct vfio_device *device, void *set_id)
{
unsigned long idx = (unsigned long)set_id;
device_initialize(&device->device);
device->device.release = vfio_device_release;
- device->device.class = vfio.device_class;
+ device->device.class = &vfio_device_class;
device->device.parent = device->dev;
return 0;
goto err_virqfd;
/* /sys/class/vfio-dev/vfioX */
- vfio.device_class = class_create("vfio-dev");
- if (IS_ERR(vfio.device_class)) {
- ret = PTR_ERR(vfio.device_class);
+ ret = class_register(&vfio_device_class);
+ if (ret)
goto err_dev_class;
- }
- ret = vfio_cdev_init(vfio.device_class);
+ ret = vfio_cdev_init();
if (ret)
goto err_alloc_dev_chrdev;
return 0;
err_alloc_dev_chrdev:
- class_destroy(vfio.device_class);
- vfio.device_class = NULL;
+ class_unregister(&vfio_device_class);
err_dev_class:
vfio_virqfd_exit();
err_virqfd:
vfio_debugfs_remove_root();
ida_destroy(&vfio.device_ida);
vfio_cdev_cleanup();
- class_destroy(vfio.device_class);
- vfio.device_class = NULL;
+ class_unregister(&vfio_device_class);
vfio_virqfd_exit();
vfio_group_cleanup();
xa_destroy(&vfio_device_set_xa);