* [PATCH] vfio: replace vfio->class with a const struct class
@ 2026-03-06 19:06 Jori Koolstra
2026-03-20 21:18 ` Alex Williamson
0 siblings, 1 reply; 2+ messages in thread
From: Jori Koolstra @ 2026-03-06 19:06 UTC (permalink / raw)
To: Alex Williamson
Cc: Jori Koolstra, Greg Kroah-Hartman, open list:VFIO DRIVER,
open list
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>
---
drivers/vfio/group.c | 23 +++++++++++------------
1 file changed, 11 insertions(+), 12 deletions(-)
diff --git a/drivers/vfio/group.c b/drivers/vfio/group.c
index 4f15016d2a5f..d4a53f8c5be0 100644
--- a/drivers/vfio/group.c
+++ b/drivers/vfio/group.c
@@ -15,8 +15,13 @@
#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();
}
base-commit: d466c332e106fe666d1e2f5a24d08e308bebbfa1
--
2.53.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] vfio: replace vfio->class with a const struct class
2026-03-06 19:06 [PATCH] vfio: replace vfio->class with a const struct class Jori Koolstra
@ 2026-03-20 21:18 ` Alex Williamson
0 siblings, 0 replies; 2+ messages in thread
From: Alex Williamson @ 2026-03-20 21:18 UTC (permalink / raw)
To: Jori Koolstra; +Cc: Greg Kroah-Hartman, open list:VFIO DRIVER, open list, alex
On Fri, 6 Mar 2026 20:06:28 +0100
Jori Koolstra <jkoolstra@xs4all.nl> wrote:
> 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>
> ---
> drivers/vfio/group.c | 23 +++++++++++------------
> 1 file changed, 11 insertions(+), 12 deletions(-)
Applied to vfio next branch for v7.1. Thanks,
Alex
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-03-20 21:19 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-06 19:06 [PATCH] vfio: replace vfio->class with a const struct class Jori Koolstra
2026-03-20 21:18 ` Alex Williamson
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox