Re: [PATCH] ALSA: core: serialize card->devices operations with a re-entrant devices lock
From: Takashi Iwai
Date: Wed Dec 02 2026 - 03:56:59 EST
On Wed, 02 Dec 2026 03:06:02 +0100,
Hanxiang Xu wrote:
>
> The card->devices list is manipulated with no serialization:
> snd_device_free() does list_del() and kfree(dev) while
> snd_device_disconnect_all() walks the list dereferencing every entry,
> so an independently removable sub-driver racing a card disconnect makes
> the walker read freed memory or advance through LIST_POISON2 and Oops.
>
> Add a devices_mutex to struct snd_card and take it in
> snd_device_new()/snd_device_free()/snd_device_disconnect()/
> snd_device_register()/snd_device_register_all()/
> snd_device_disconnect_all()/snd_device_free_all(). The lock tracks its
> owner so the legitimate re-entrancy keeps working: disconnect callbacks
> run under the lock and may themselves call snd_device_free() for
> sibling devices (the sequencer sub-driver remove path).
>
> Cc: <stable@xxxxxxxxxxxxxxx>
> Signed-off-by: Hanxiang Xu <xuhx@xxxxxxxxxxx>
This change conflicts with your other patch?
Manage your own patches better at first.
Takashi