Re: [PATCH 2/9] driver core: prevent device_add() during system shutdown

From: sashiko-bot

Date: Thu Sep 17 2026 - 17:49:45 EST


> From: Tarun Sahu <tarunsahu@xxxxxxxxxx>
>
> In Async device shutdown, device_kset->list lock is released to handle
> asynchronisation and hold again to get entry from device_kset->list.
> Which will leave window when device_add can try to add the device to
> device_kset list and temper with ongoing shutdown process. New added
> device can be async type or sync type and might also introduce new
> dependency which can cause device_shutdown path to deadlock. S is
> waiting C to finish but C is never scheduled as it was added recently
> from device_add path. And C can only be scheduled when main loops
> continue to reach to C which is waiting on S.
>
> So, When a system enters shutdown (SYSTEM_HALT, SYSTEM_POWER_OFF, or
> SYSTEM_RESTART), new devices should not be allowed to be added.
> Adding system_state check (system_is_shutting_down()) to avoid
> device_add incase of these states of the system. And use srcu so the
> device shutdown operation can synchronize device_add and ensure any
> device_add in progress is finished.
>
> Signed-off-by: Tarun Sahu <tarunsahu@xxxxxxxxxx>
> Signed-off-by: David Jeffery <djeffery@xxxxxxxxxx>

Sashiko has reviewed this patch and found no issues. It looks great!

--
Sashiko AI review · https://sashiko.dev/#/patchset/20260917163744.191748-1-djeffery@xxxxxxxxxx?part=2