mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Johan Hovold <johan@kernel.org>
To: Ian Rogers <irogers@google.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	"Rafael J . Wysocki" <rafael@kernel.org>,
	Danilo Krummrich <dakr@kernel.org>,
	Luis Chamberlain <mcgrof@kernel.org>,
	Dave Ertman <david.m.ertman@intel.com>,
	Ira Weiny <iweiny@kernel.org>, Leon Romanovsky <leon@kernel.org>,
	Kees Cook <kees@kernel.org>, Miguel Ojeda <ojeda@kernel.org>,
	Nathan Chancellor <nathan@kernel.org>,
	driver-core@lists.linux.dev, llvm@lists.linux.dev,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/3] driver core: Require explicit initialization of class and bus_type name
Date: Thu, 3 Dec 2026 10:55:33 +0100	[thread overview]
Message-ID: <axE8lZ5r-p3VX0ff@hovoldconsulting.com> (raw)
In-Reply-To: <CAP-5=fW5r08PAHJxiVKe6=CqdhxB-95p7Ukakx3ow6yOt=UB-Q@mail.gmail.com>

On Tue, Dec 01, 2026 at 08:36:26AM -0800, Ian Rogers wrote:
> On Tue, Dec 1, 2026 at 12:26 AM Johan Hovold <johan@kernel.org> 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.

> 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@google.com/

Thanks for the pointers.

> 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 can see it being useful for fields like .release and other callbacks
not used during registration/probe, but for the first two patches here
it really only helps a developer with recent clang before the very first
test run (e.g. in the theoretical case that they forget to name their
new bus or class).

So maybe start with a variant of 1 by adding it to structs where there
is a potential benefit?

> 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).

It does add some newlines and clutter to the declarations, but I guess
that's not too much of an issue.

> 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?

No, I'm fine with this. It was just seeing this applied to two instances
where the benefit is essentially zero that threw me off.

Johan

  reply	other threads:[~2026-12-03  9:55 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-30 22:53 [PATCH 0/3] driver core: Add __must_init annotations to core registration structs Ian Rogers
2026-11-30 22:53 ` [PATCH 1/3] driver core: Require explicit initialization of class and bus_type name Ian Rogers
2026-12-01  8:26   ` Johan Hovold
2026-12-01 16:36     ` Ian Rogers
2026-12-03  9:55       ` Johan Hovold [this message]
2026-12-03 17:09         ` Ian Rogers
2026-11-30 22:53 ` [PATCH 2/3] driver core: auxiliary: Annotate probe and id_table with __must_init Ian Rogers
2026-12-01  8:32   ` Johan Hovold
2026-11-30 22:53 ` [PATCH 3/3] firmware_loader: Annotate mandatory fw_upload_ops " Ian Rogers
2026-12-01  8:35   ` Johan Hovold

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=axE8lZ5r-p3VX0ff@hovoldconsulting.com \
    --to=johan@kernel.org \
    --cc=dakr@kernel.org \
    --cc=david.m.ertman@intel.com \
    --cc=driver-core@lists.linux.dev \
    --cc=gregkh@linuxfoundation.org \
    --cc=irogers@google.com \
    --cc=iweiny@kernel.org \
    --cc=kees@kernel.org \
    --cc=leon@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=llvm@lists.linux.dev \
    --cc=mcgrof@kernel.org \
    --cc=nathan@kernel.org \
    --cc=ojeda@kernel.org \
    --cc=rafael@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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®