public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] vfio: mdev: replace mtty_dev->vd_class with a const struct class
@ 2026-03-08 13:37 Jori Koolstra
  2026-03-08 16:20 ` Greg KH
  0 siblings, 1 reply; 2+ messages in thread
From: Jori Koolstra @ 2026-03-08 13:37 UTC (permalink / raw)
  To: gregkh, Kirti Wankhede
  Cc: Jori Koolstra, open list:VFIO MEDIATED DEVICE DRIVERS, 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 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>
---
 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;
 } mtty_dev;
 
 struct mdev_region_info {
@@ -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
-- 
2.53.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] vfio: mdev: replace mtty_dev->vd_class with a const struct class
  2026-03-08 13:37 [PATCH] vfio: mdev: replace mtty_dev->vd_class with a const struct class Jori Koolstra
@ 2026-03-08 16:20 ` Greg KH
  0 siblings, 0 replies; 2+ messages in thread
From: Greg KH @ 2026-03-08 16:20 UTC (permalink / raw)
  To: Jori Koolstra
  Cc: Kirti Wankhede, open list:VFIO MEDIATED DEVICE DRIVERS, open list

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@linuxfoundation.org>
> Signed-off-by: Jori Koolstra <jkoolstra@xs4all.nl>
> ---
>  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

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-03-08 16:20 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-08 13:37 [PATCH] vfio: mdev: replace mtty_dev->vd_class with a const struct class Jori Koolstra
2026-03-08 16:20 ` Greg KH

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox