Re: [PATCH] vfio: mdev: replace mtty_dev->vd_class with a const struct class

From: Greg KH

Date: Sun Mar 08 2026 - 12:20:31 EST


On Sun, Mar 08, 2026 at 02:37:33PM +0100, Jori Koolstra 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 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@xxxxxxxxxxxxxxxxxxx>
> Signed-off-by: Jori Koolstra <jkoolstra@xxxxxxxxx>
> ---
> samples/vfio-mdev/mtty.c | 27 ++++++++++++++-------------
> 1 file changed, 14 insertions(+), 13 deletions(-)
>
> diff --git a/samples/vfio-mdev/mtty.c b/samples/vfio-mdev/mtty.c
> index bd92c38379b8..792f5c212fd1 100644
> --- a/samples/vfio-mdev/mtty.c
> +++ b/samples/vfio-mdev/mtty.c
> @@ -68,13 +68,16 @@
> * 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;
> - struct mdev_parent parent;
> + dev_t vd_devt;
> + struct cdev vd_cdev;
> + struct idr vd_idr;
> + struct device dev;
> + struct mdev_parent parent;

No need to reformat this structure :(

thanks,

greg k-h