* [PATCH] virt: coco: change tsm_class to a const struct
@ 2026-03-03 19:05 Jori Koolstra
2026-03-04 7:12 ` Thomas Weißschuh
0 siblings, 1 reply; 5+ messages in thread
From: Jori Koolstra @ 2026-03-03 19:05 UTC (permalink / raw)
To: kees
Cc: Jori Koolstra, Greg Kroah-Hartman, Dan Williams,
Alexey Kardashevskiy, Jonathan Cameron, Bjorn Helgaas, Xu Yilun,
Thomas Weißschuh, 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/
Suggested-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Jori Koolstra <jkoolstra@xs4all.nl>
---
drivers/virt/coco/tsm-core.c | 20 +++++++++++---------
1 file changed, 11 insertions(+), 9 deletions(-)
diff --git a/drivers/virt/coco/tsm-core.c b/drivers/virt/coco/tsm-core.c
index 98dcf7d836df..04e347ea4b7c 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,16 @@ 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);
+ int err;
- tsm_class->dev_release = tsm_release;
- return 0;
+ err = class_register(&tsm_class);
+ return err;
}
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 related [flat|nested] 5+ messages in thread
* Re: [PATCH] virt: coco: change tsm_class to a const struct
2026-03-03 19:05 [PATCH] virt: coco: change tsm_class to a const struct Jori Koolstra
@ 2026-03-04 7:12 ` Thomas Weißschuh
2026-03-04 9:35 ` Jori Koolstra
2026-04-01 17:07 ` Jori Koolstra
0 siblings, 2 replies; 5+ messages in thread
From: Thomas Weißschuh @ 2026-03-04 7:12 UTC (permalink / raw)
To: Jori Koolstra
Cc: kees, Greg Kroah-Hartman, Dan Williams, Alexey Kardashevskiy,
Jonathan Cameron, Bjorn Helgaas, Xu Yilun, open list
On Tue, Mar 03, 2026 at 08:05:55PM +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. 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/
>
> Suggested-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> Signed-off-by: Jori Koolstra <jkoolstra@xs4all.nl>
A small nitpick below, but in any case:
Reviewed-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de>
(...)
> @@ -114,18 +118,16 @@ 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);
> + int err;
>
> - tsm_class->dev_release = tsm_release;
> - return 0;
> + err = class_register(&tsm_class);
> + return err;
'err' looks to be unnecessary now.
> }
(...)
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] virt: coco: change tsm_class to a const struct
2026-03-04 7:12 ` Thomas Weißschuh
@ 2026-03-04 9:35 ` Jori Koolstra
2026-03-04 9:59 ` Greg Kroah-Hartman
2026-04-01 17:07 ` Jori Koolstra
1 sibling, 1 reply; 5+ messages in thread
From: Jori Koolstra @ 2026-03-04 9:35 UTC (permalink / raw)
To: Thomas Weißschuh
Cc: kees, Greg Kroah-Hartman, Dan Williams, Alexey Kardashevskiy,
Jonathan Cameron, Bjorn Helgaas, Xu Yilun, open list
Hi Thomas,
> Op 04-03-2026 08:12 CET schreef Thomas Weißschuh <thomas.weissschuh@linutronix.de>:
>
> > @@ -114,18 +118,16 @@ 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);
> > + int err;
> >
> > - tsm_class->dev_release = tsm_release;
> > - return 0;
> > + err = class_register(&tsm_class);
> > + return err;
>
> 'err' looks to be unnecessary now.
>
> > }
This was what I had before. I thought that returning class_register() immediately,
even though it saves two lines, might be less readable. You either have to click
through to class_register() or know that these init functions return an error.
Is there convention for this?
thanks,
Jori.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] virt: coco: change tsm_class to a const struct
2026-03-04 9:35 ` Jori Koolstra
@ 2026-03-04 9:59 ` Greg Kroah-Hartman
0 siblings, 0 replies; 5+ messages in thread
From: Greg Kroah-Hartman @ 2026-03-04 9:59 UTC (permalink / raw)
To: Jori Koolstra
Cc: Thomas Weißschuh, kees, Dan Williams, Alexey Kardashevskiy,
Jonathan Cameron, Bjorn Helgaas, Xu Yilun, open list
On Wed, Mar 04, 2026 at 10:35:03AM +0100, Jori Koolstra wrote:
> Hi Thomas,
>
> > Op 04-03-2026 08:12 CET schreef Thomas Weißschuh <thomas.weissschuh@linutronix.de>:
> >
> > > @@ -114,18 +118,16 @@ 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);
> > > + int err;
> > >
> > > - tsm_class->dev_release = tsm_release;
> > > - return 0;
> > > + err = class_register(&tsm_class);
> > > + return err;
> >
> > 'err' looks to be unnecessary now.
> >
> > > }
>
> This was what I had before. I thought that returning class_register() immediately,
> even though it saves two lines, might be less readable. You either have to click
> through to class_register() or know that these init functions return an error.
> Is there convention for this?
A single line function of:
static int __init tsm_init(void)
{
return class_register(&tsm_class);
}
Is just fine.
thanks,
greg k-h
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] virt: coco: change tsm_class to a const struct
2026-03-04 7:12 ` Thomas Weißschuh
2026-03-04 9:35 ` Jori Koolstra
@ 2026-04-01 17:07 ` Jori Koolstra
1 sibling, 0 replies; 5+ messages in thread
From: Jori Koolstra @ 2026-04-01 17:07 UTC (permalink / raw)
To: Thomas Weißschuh
Cc: kees, Greg Kroah-Hartman, Dan Williams, Alexey Kardashevskiy,
Jonathan Cameron, Bjorn Helgaas, Xu Yilun, open list
> Op 04-03-2026 08:12 CET schreef Thomas Weißschuh <thomas.weissschuh@linutronix.de>:
>
>
> On Tue, Mar 03, 2026 at 08:05:55PM +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. 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/
> >
> > Suggested-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> > Signed-off-by: Jori Koolstra <jkoolstra@xs4all.nl>
>
> A small nitpick below, but in any case:
>
> Reviewed-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de>
>
> (...)
>
> > @@ -114,18 +118,16 @@ 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);
> > + int err;
> >
> > - tsm_class->dev_release = tsm_release;
> > - return 0;
> > + err = class_register(&tsm_class);
> > + return err;
>
> 'err' looks to be unnecessary now.
>
> > }
>
> (...)
Hi Thomas,
I sent a v2 a while ago; I am not sure how to check if it has been applied.
Just going over the remaining class_create() patches again.
Thanks,
Jori.
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-04-01 17:07 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-03 19:05 [PATCH] virt: coco: change tsm_class to a const struct Jori Koolstra
2026-03-04 7:12 ` Thomas Weißschuh
2026-03-04 9:35 ` Jori Koolstra
2026-03-04 9:59 ` Greg Kroah-Hartman
2026-04-01 17:07 ` Jori Koolstra
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox