]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
vfio: replace vfio->class with a const struct class
authorJori Koolstra <jkoolstra@xs4all.nl>
Fri, 6 Mar 2026 19:06:28 +0000 (20:06 +0100)
committerAlex Williamson <alex@shazbot.org>
Mon, 16 Mar 2026 19:38:50 +0000 (13:38 -0600)
The class_create() call has been deprecated in favor of class_register()
as the driver core now allows for a struct class to be in read-only
memory. Replace vfio->class with a const struct class and drop the
class_create() call.

Compile tested and found no errors/warns in dmesg after enabling
VFIO_GROUP.

Link: https://lore.kernel.org/all/2023040244-duffel-pushpin-f738@gregkh/
Suggested-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Jori Koolstra <jkoolstra@xs4all.nl>
Link: https://lore.kernel.org/r/20260306190628.259203-1-jkoolstra@xs4all.nl
Signed-off-by: Alex Williamson <alex@shazbot.org>
drivers/vfio/group.c

index 4f15016d2a5fdebc8937d1b78c0177b2d4de31b6..d4a53f8c5be000195bde507803d9c300518f0192 100644 (file)
 #include <linux/anon_inodes.h>
 #include "vfio.h"
 
+static char *vfio_devnode(const struct device *, umode_t *);
+static const struct class vfio_class = {
+       .name   = "vfio",
+       .devnode = vfio_devnode
+};
+
 static struct vfio {
-       struct class                    *class;
        struct list_head                group_list;
        struct mutex                    group_lock; /* locks group_list */
        struct ida                      group_ida;
@@ -527,7 +532,7 @@ static struct vfio_group *vfio_group_alloc(struct iommu_group *iommu_group,
 
        device_initialize(&group->dev);
        group->dev.devt = MKDEV(MAJOR(vfio.group_devt), minor);
-       group->dev.class = vfio.class;
+       group->dev.class = &vfio_class;
        group->dev.release = vfio_group_release;
        cdev_init(&group->cdev, &vfio_group_fops);
        group->cdev.owner = THIS_MODULE;
@@ -901,13 +906,9 @@ int __init vfio_group_init(void)
                return ret;
 
        /* /dev/vfio/$GROUP */
-       vfio.class = class_create("vfio");
-       if (IS_ERR(vfio.class)) {
-               ret = PTR_ERR(vfio.class);
+       ret = class_register(&vfio_class);
+       if (ret)
                goto err_group_class;
-       }
-
-       vfio.class->devnode = vfio_devnode;
 
        ret = alloc_chrdev_region(&vfio.group_devt, 0, MINORMASK + 1, "vfio");
        if (ret)
@@ -915,8 +916,7 @@ int __init vfio_group_init(void)
        return 0;
 
 err_alloc_chrdev:
-       class_destroy(vfio.class);
-       vfio.class = NULL;
+       class_unregister(&vfio_class);
 err_group_class:
        vfio_container_cleanup();
        return ret;
@@ -927,7 +927,6 @@ void vfio_group_cleanup(void)
        WARN_ON(!list_empty(&vfio.group_list));
        ida_destroy(&vfio.group_ida);
        unregister_chrdev_region(vfio.group_devt, MINORMASK + 1);
-       class_destroy(vfio.class);
-       vfio.class = NULL;
+       class_unregister(&vfio_class);
        vfio_container_cleanup();
 }