Re: [PATCH v5] driver core: enforce device_lock for driver_match_device()

From: Danilo Krummrich

Date: Tue Jan 20 2026 - 10:03:07 EST


On Tue Jan 20, 2026 at 2:22 PM CET, Mark Brown wrote:
> On Wed, Jan 14, 2026 at 12:28:43AM +0800, Gui-Dong Han wrote:
>> Currently, driver_match_device() is called from three sites. One site
>> (__device_attach_driver) holds device_lock(dev), but the other two
>> (bind_store and __driver_attach) do not. This inconsistency means that
>> bus match() callbacks are not guaranteed to be called with the lock
>> held.
>
> I'm seeing boot hangs on Arm Juno in next/pending-fixes which bisect to
> this commit. The boot grinds to a halt near the end of boot:
>
> [ 2.570549] ledtrig-cpu: registered to indicate activity on CPUs
> [ 2.618301] Serial: 8250/16550 driver, 4 ports, IRQ sharing enabled
> [ 2.623547] msm_serial: driver initialized
> [ 2.624058] SuperH (H)SCI(F) driver initialized
> [ 2.624312] STM32 USART driver initialized

Hm..sounds a bit like some match() callback manually takes the device_lock() and
the reason we're not seeing anything from lockdep is because it happens with the
serial driver.

I don't have a machine to reproduce it, but for debugging it would probably help
to not actually take the lock in __driver_attach(), but only acquire / release
the corresponding lockdep map. If my suspicion is correct, we should see a
lockdep splat pointing out the issue.