vfio: mdev: replace mtty_dev->vd_class with a const struct class
Subsystems (2)
PATCH v2 1/1 vfio: mdev: replace mtty_dev->vd_class with a const struct class
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 mtty_dev->vd_class with a const struct class and drop the class_create() call.
Compile tested and found no errors/warns in dmesg after enabling CONFIG_VFIO and CONFIG_SAMPLE_VFIO_MDEV_MTTY.
---
v2: undo whitespace reformating of struct mtty_dev
samples/vfio-mdev/mtty.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-)
samples/vfio-mdev/mtty.c +9 -8
@@ -68,9 +68,12 @@* Global Structures */ +static const struct class mtty_class = { + .name =MTTY_CLASS_NAME +}; + static struct mtty_dev { dev_t vd_devt; - struct class *vd_class; struct cdev vd_cdev; struct idr vd_idr; struct device dev;
@@ -1980,15 +1983,14 @@ static int __init mtty_dev_init(void)if (ret) goto err_cdev; - mtty_dev.vd_class =class_create (MTTY_CLASS_NAME ); + ret =class_register (&mtty_class); -if (IS_ERR (mtty_dev.vd_class)) { +if (ret) {pr_err ("Error: failed to register mtty_dev class\n" ); - ret =PTR_ERR (mtty_dev.vd_class); goto err_driver; } - mtty_dev.dev.class = mtty_dev.vd_class; + mtty_dev.dev.class = &mtty_class; mtty_dev.dev.release = mtty_device_release;dev_set_name (&mtty_dev.dev,"%s" ,MTTY_NAME );
@@ -2007,7 +2009,7 @@ static int __init mtty_dev_init(void)device_del (&mtty_dev.dev); err_put:put_device (&mtty_dev.dev); -class_destroy (mtty_dev.vd_class); +class_unregister (&mtty_class); err_driver:mdev_unregister_driver (&mtty_driver); err_cdev:
@@ -2026,8 +2028,7 @@ static void __exit mtty_dev_exit(void)mdev_unregister_driver (&mtty_driver);cdev_del (&mtty_dev.vd_cdev);unregister_chrdev_region (mtty_dev.vd_devt,MINORMASK +1 ); -class_destroy (mtty_dev.vd_class); - mtty_dev.vd_class =NULL ; +class_unregister (&mtty_class);pr_info ("mtty_dev: Unloaded!\n" ); }
base-commit: d466c332e106fe666d1e2f5a24d08e308bebbfa1
Signature · 1 line
2.53.0
Quoted 8 lines · Jori Koolstra
The
class_create()call has been deprecated in favor ofclass_register()as the driver core now allows for a struct class to be in read-only memory. Replacemtty_dev->vd_classwith a const struct class and drop theclass_create()call.Compile tested and found no errors/warns in dmesg after enabling
CONFIG_VFIOandCONFIG_SAMPLE_VFIO_MDEV_MTTY.
Quoted 6 lines
Suggested-by Greg Kroah-Hartman <[email protected]>Signed-off-by Jori Koolstra <[email protected]>---
v2: undo whitespace reformating of structmtty_dev
Alex Williamson
AppliedQuoted 10 lines · On Sun, 8 Mar 2026 22:49:39 +0100 Jori Koolstra <[email protected]> wrote:
The
class_create()call has been deprecated in favor ofclass_register()as the driver core now allows for a struct class to be in read-only memory. Replacemtty_dev->vd_classwith a const struct class and drop theclass_create()call.Compile tested and found no errors/warns in dmesg after enabling
CONFIG_VFIOandCONFIG_SAMPLE_VFIO_MDEV_MTTY.
Quoted 7 lines
Suggested-by Greg Kroah-Hartman <[email protected]>Signed-off-by Jori Koolstra <[email protected]>---
v2: undo whitespace reformating of structmtty_devsamples/vfio-mdev/mtty.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-)
Applied to vfio next branch for v7.1. Thanks,
Alex