mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v2] virt: coco: change tsm_class to a const struct
@ 2026-03-06 18:33 Jori Koolstra
  2026-04-01 22:26 ` Dan Williams
  0 siblings, 1 reply; 2+ messages in thread
From: Jori Koolstra @ 2026-03-06 18:33 UTC (permalink / raw)
  To: thomas.weissschuh
  Cc: Jori Koolstra, Greg Kroah-Hartman, Dan Williams,
	Alexey Kardashevskiy, Bjorn Helgaas, Jonathan Cameron, Xu Yilun,
	Kees Cook, 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. Change tsm_class to be a const struct class and drop the
class_create() call. Compile tested only.

Link: https://lore.kernel.org/all/2023040244-duffel-pushpin-f738@gregkh/

Changes with v1:
- Removed redundant int err variable. 

Suggested-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Jori Koolstra <jkoolstra@xs4all.nl>
Reviewed-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de>
---
 drivers/virt/coco/tsm-core.c | 19 +++++++++----------
 1 file changed, 9 insertions(+), 10 deletions(-)

diff --git a/drivers/virt/coco/tsm-core.c b/drivers/virt/coco/tsm-core.c
index 98dcf7d836df..e784993353d8 100644
--- a/drivers/virt/coco/tsm-core.c
+++ b/drivers/virt/coco/tsm-core.c
@@ -9,7 +9,11 @@
 #include <linux/cleanup.h>
 #include <linux/pci-tsm.h>
 
-static struct class *tsm_class;
+static void tsm_release(struct device *);
+static const struct class tsm_class = {
+	.name		= "tsm",
+	.dev_release	= tsm_release
+};
 static DEFINE_IDA(tsm_ida);
 
 static int match_id(struct device *dev, const void *data)
@@ -22,7 +26,7 @@ static int match_id(struct device *dev, const void *data)
 
 struct tsm_dev *find_tsm_dev(int id)
 {
-	struct device *dev = class_find_device(tsm_class, NULL, &id, match_id);
+	struct device *dev = class_find_device(&tsm_class, NULL, &id, match_id);
 
 	if (!dev)
 		return NULL;
@@ -46,7 +50,7 @@ static struct tsm_dev *alloc_tsm_dev(struct device *parent)
 	tsm_dev->id = id;
 	dev = &tsm_dev->dev;
 	dev->parent = parent;
-	dev->class = tsm_class;
+	dev->class = &tsm_class;
 	device_initialize(dev);
 
 	return no_free_ptr(tsm_dev);
@@ -114,18 +118,13 @@ static void tsm_release(struct device *dev)
 
 static int __init tsm_init(void)
 {
-	tsm_class = class_create("tsm");
-	if (IS_ERR(tsm_class))
-		return PTR_ERR(tsm_class);
-
-	tsm_class->dev_release = tsm_release;
-	return 0;
+	return class_register(&tsm_class);
 }
 module_init(tsm_init)
 
 static void __exit tsm_exit(void)
 {
-	class_destroy(tsm_class);
+	class_unregister(&tsm_class);
 }
 module_exit(tsm_exit)
 

base-commit: d466c332e106fe666d1e2f5a24d08e308bebbfa1
-- 
2.53.0


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

* Re: [PATCH v2] virt: coco: change tsm_class to a const struct
  2026-03-06 18:33 [PATCH v2] virt: coco: change tsm_class to a const struct Jori Koolstra
@ 2026-04-01 22:26 ` Dan Williams
  0 siblings, 0 replies; 2+ messages in thread
From: Dan Williams @ 2026-04-01 22:26 UTC (permalink / raw)
  To: Jori Koolstra, thomas.weissschuh
  Cc: Jori Koolstra, Greg Kroah-Hartman, Dan Williams,
	Alexey Kardashevskiy, Bjorn Helgaas, Jonathan Cameron, Xu Yilun,
	Kees Cook, open list

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. Change tsm_class to be a const struct class and drop the
> class_create() call. Compile tested only.
> 
> Link: https://lore.kernel.org/all/2023040244-duffel-pushpin-f738@gregkh/
> 
> Changes with v1:
> - Removed redundant int err variable. 
> 
> Suggested-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> Signed-off-by: Jori Koolstra <jkoolstra@xs4all.nl>
> Reviewed-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de>

Missed this earlier, will get it pushed out for v7.1, thanks!

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

end of thread, other threads:[~2026-04-01 22:26 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-03-06 18:33 [PATCH v2] virt: coco: change tsm_class to a const struct Jori Koolstra
2026-04-01 22:26 ` Dan Williams

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

all inboxes | Powered by JetHome®