Re: [PATCH 1/3] driver core: Require explicit initialization of class and bus_type name

From: Ian Rogers

Date: Tue Dec 01 2026 - 11:36:55 EST


On Tue, Dec 1, 2026 at 12:26 AM Johan Hovold <johan@xxxxxxxxxx> wrote:
>
> On Mon, Nov 30, 2026 at 02:53:38PM -0800, Ian Rogers wrote:
> > class_register() and bus_register() pass .name to kobject_set_name() to
> > register the subsystem kset in sysfs, which fails with -ENOMEM if .name
> > is NULL.
> >
> > Annotate .name on struct class and struct bus_type with __must_init so
> > missing names are caught at compile time.
>
> I don't see the point in doing this as any superficial testing
> (i.e. registering the bus or class) will catch this.

Hi Johan,

You are right. The hope is to push a run time problem into a compile
time failure. If we have good run time test coverage a compile time
attribute won't catch anything new.

For context, I gave this presentation at LPC:
https://lpc.events/event/20/contributions/2392/
And the series adding the attribute is here, with the first user being
kobject::release:
https://lore.kernel.org/lkml/20261119192520.1983406-1-irogers@xxxxxxxxxx/

The patches here come from a desire to try to capture this __must_init
behavior as much as possible. kobject::release showed issues with
users not initializing kobjects properly, these changes did not. I
think there are 3 things I can do:

1) try to adopt __must_init widely based on inspecting runtime code to
try to make runtime problems compile time ones (the approach here),
2) adopt __must_init only when bugs were encountered and __must_init
would have prevented them,
3) just avoiding __must_init altogether.

For (2) it is also evidence that we can add runtime checks. For (3)
the feedback from people like Kees and Greg was that the attributes
were useful and we should add them.

I feel this change doesn't introduce much noise. There are advantages
in terms of documentation and for new users, so overall, I prefer the
change (and approach 1 in general).

Do you feel the change is excessively noisy and creates churn, so you
don't want to see it land or are you just kind of meh on the
__must_init attribute idea?

Thanks for the feedback,
Ian

> Johan