aboutsummaryrefslogtreecommitdiff
path: root/samples
diff options
context:
space:
mode:
authorJori Koolstra <jkoolstra@xs4all.nl>2026-03-08 22:49:39 +0100
committerAlex Williamson <alex@shazbot.org>2026-03-19 12:32:07 -0600
commit06ed87b3197e9b80dccac0b764fdffe44192e010 (patch)
tree18facd4e16e9ce6bcb98e9b094ebb69453877730 /samples
parent5efa9a54c6a5f22080f33012c41a94112e955b53 (diff)
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. 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> Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Link: https://lore.kernel.org/r/20260308214939.1215682-1-jkoolstra@xs4all.nl Signed-off-by: Alex Williamson <alex@shazbot.org>
Diffstat (limited to 'samples')
-rw-r--r--samples/vfio-mdev/mtty.c17
1 files changed, 9 insertions, 8 deletions
diff --git a/samples/vfio-mdev/mtty.c b/samples/vfio-mdev/mtty.c
index bd92c38379b8..01a9db84c4ab 100644
--- a/samples/vfio-mdev/mtty.c
+++ b/samples/vfio-mdev/mtty.c
@@ -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 @@ err_device:
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");
}