Re: [PATCH] virt: coco: change tsm_class to a const struct

From: Greg Kroah-Hartman

Date: Wed Mar 04 2026 - 04:59:29 EST


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@xxxxxxxxxxxxx>:
> >
> > > @@ -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