Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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>

authored by

Jori Koolstra and committed by
Alex Williamson
06ed87b3 5efa9a54

+9 -8
+9 -8
samples/vfio-mdev/mtty.c
··· 68 68 * Global Structures 69 69 */ 70 70 71 + static const struct class mtty_class = { 72 + .name = MTTY_CLASS_NAME 73 + }; 74 + 71 75 static struct mtty_dev { 72 76 dev_t vd_devt; 73 - struct class *vd_class; 74 77 struct cdev vd_cdev; 75 78 struct idr vd_idr; 76 79 struct device dev; ··· 1983 1980 if (ret) 1984 1981 goto err_cdev; 1985 1982 1986 - mtty_dev.vd_class = class_create(MTTY_CLASS_NAME); 1983 + ret = class_register(&mtty_class); 1987 1984 1988 - if (IS_ERR(mtty_dev.vd_class)) { 1985 + if (ret) { 1989 1986 pr_err("Error: failed to register mtty_dev class\n"); 1990 - ret = PTR_ERR(mtty_dev.vd_class); 1991 1987 goto err_driver; 1992 1988 } 1993 1989 1994 - mtty_dev.dev.class = mtty_dev.vd_class; 1990 + mtty_dev.dev.class = &mtty_class; 1995 1991 mtty_dev.dev.release = mtty_device_release; 1996 1992 dev_set_name(&mtty_dev.dev, "%s", MTTY_NAME); 1997 1993 ··· 2009 2007 device_del(&mtty_dev.dev); 2010 2008 err_put: 2011 2009 put_device(&mtty_dev.dev); 2012 - class_destroy(mtty_dev.vd_class); 2010 + class_unregister(&mtty_class); 2013 2011 err_driver: 2014 2012 mdev_unregister_driver(&mtty_driver); 2015 2013 err_cdev: ··· 2028 2026 mdev_unregister_driver(&mtty_driver); 2029 2027 cdev_del(&mtty_dev.vd_cdev); 2030 2028 unregister_chrdev_region(mtty_dev.vd_devt, MINORMASK + 1); 2031 - class_destroy(mtty_dev.vd_class); 2032 - mtty_dev.vd_class = NULL; 2029 + class_unregister(&mtty_class); 2033 2030 pr_info("mtty_dev: Unloaded!\n"); 2034 2031 } 2035 2032