Linux USB
 help / color / mirror / Atom feed
From: Johan Hovold <johan@kernel.org>
To: Danilo Krummrich <dakr@kernel.org>
Cc: Alan Stern <stern@rowland.harvard.edu>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	"Rafael J. Wysocki" <rafael@kernel.org>,
	Dmitry Torokhov <dmitry.torokhov@gmail.com>,
	driver-core@lists.linux.dev, linux-usb@vger.kernel.org,
	linux-kernel@vger.kernel.org,
	Mario Peter <mario.peter@leica-geosystems.com>,
	stable@vger.kernel.org
Subject: Re: [PATCH] driver core: take parent lock on deferred probe
Date: Wed, 14 Oct 2026 17:14:35 +0200	[thread overview]
Message-ID: <as-cW9ZwmMCPcftL@hovoldconsulting.com> (raw)
In-Reply-To: <DM4N25JXKTQM.3K7TP9HM68KQ2@kernel.org>

On Wed, Oct 14, 2026 at 04:42:09PM +0200, Danilo Krummrich wrote:
> On Wed Oct 14, 2026 at 10:15 AM CEST, Johan Hovold wrote:

> > But it's driver core that needs the extra reference. It seems
> > reasonable to require that any subsystem that sets a new
> > type->need_parent_lock also makes sure that any device of that type
> > holds a reference to its parent. And importantly, it's already the case
> > for the only user of this feature today (i.e. USB interfaces).
> 
> Exactly, it is the driver core that needs the extra reference count; for a field
> that is owned by the driver core, and for which the driver core manages its
> lifetime.  If it needs an additional reference count for async or deferred work
> it should obtain the reference count for this scope explicitly.

As I've mentioned, it's not just for async or deferred probe. It's also
needed when a driver gets added or when probe is triggered through
sysfs. The bus iterators only takes a reference to the each device and
not their parents before calling __driver_attach() etc.

> USB interfaces already holding an additional reference makes the proposed
> contract work for today's user, but I'd rather not make that prerequisite of the
> API.  It would push a prerequisite for an implementation detail to the user.

I understand your concern, but my reasoning is that this feature is only
needed when devices are tightly coupled with their parents and where it
therefore probably always make sense to pin the parent.

Note that the need_parent_lock flag is now set in the device type struct
which also holds a pointer to the release function that drops the
reference. So it's pretty easy to check any theoretical further users.

> Please, let's not add this API contract. Let's have the driver core deal with
> this internally.

I can take another look at it, but the alternatives seemed either error
prone or a bit icky (e.g. a helper that returns a reference to the
parent after checking the dead flag under the device lock).

Johan

      reply	other threads:[~2026-10-14 15:14 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-13 14:06 [PATCH] driver core: take parent lock on deferred probe Johan Hovold
2026-10-13 14:24 ` sashiko-bot
2026-10-13 17:43 ` Danilo Krummrich
2026-10-13 19:11   ` Alan Stern
2026-10-13 21:01     ` Danilo Krummrich
2026-10-14  2:38       ` Alan Stern
2026-10-14 14:30         ` Danilo Krummrich
2026-10-14 14:51           ` Johan Hovold
2026-10-14  8:15       ` Johan Hovold
2026-10-14 14:42         ` Danilo Krummrich
2026-10-14 15:14           ` Johan Hovold [this message]

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=as-cW9ZwmMCPcftL@hovoldconsulting.com \
    --to=johan@kernel.org \
    --cc=dakr@kernel.org \
    --cc=dmitry.torokhov@gmail.com \
    --cc=driver-core@lists.linux.dev \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=mario.peter@leica-geosystems.com \
    --cc=rafael@kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=stern@rowland.harvard.edu \
    /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