]> git.ipfire.org Git - thirdparty/kernel/stable.git/commit
ALSA: timer: Fix mutex deadlock at releasing card
authorTakashi Iwai <tiwai@suse.de>
Wed, 30 Oct 2019 21:42:57 +0000 (22:42 +0100)
committerBen Hutchings <ben@decadent.org.uk>
Thu, 19 Dec 2019 15:58:52 +0000 (15:58 +0000)
commit55bdc8a20226bb813ffa39acdd8089bd76b60beb
tree28d000c5fab047c3d7e06b05a3dd0a5d2a10043c
parent7e625ef1b008551a72e6d579ca272d6cd162e672
ALSA: timer: Fix mutex deadlock at releasing card

commit a39331867335d4a94b6165e306265c9e24aca073 upstream.

When a card is disconnected while in use, the system waits until all
opened files are closed then releases the card.  This is done via
put_device() of the card device in each device release code.

The recently reported mutex deadlock bug happens in this code path;
snd_timer_close() for the timer device deals with the global
register_mutex and it calls put_device() there.  When this timer
device is the last one, the card gets freed and it eventually calls
snd_timer_free(), which has again the protection with the global
register_mutex -- boom.

Basically put_device() call itself is race-free, so a relative simple
workaround is to move this put_device() call out of the mutex.  For
achieving that, in this patch, snd_timer_close_locked() got a new
argument to store the card device pointer in return, and each caller
invokes put_device() with the returned object after the mutex unlock.

Reported-and-tested-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
sound/core/timer.c