ASoC: soc-pcm: protect BE dailink state changes in trigger
authorPierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
Tue, 17 Aug 2021 16:40:53 +0000 (11:40 -0500)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 18 Sep 2021 11:42:17 +0000 (13:42 +0200)
commitd70238b49fbb9b947397668ecac9a2d16fbf6441
treee41a46c2fb687b073b24047e48e5b2f55b339ba7
parent0db418de9b6ce7015381108761c46106da7437b4
ASoC: soc-pcm: protect BE dailink state changes in trigger

[ Upstream commit 0c75fc7193387776c10f7c7b440d93496e3d5e21 ]

When more than one FE is connected to a BE, e.g. in a mixing use case,
the BE can be triggered multiple times when the FE are opened/started
concurrently. This race condition is problematic in the case of
SoundWire BE dailinks, and this is not desirable in a general
case. The code carefully checks when the BE can be stopped or
hw_free'ed, but the trigger code does not use any mutual exclusion.

Fix by using the same spinlock already used to check FE states, and
set the state before the trigger. In case of errors,  the initial
state will be restored.

This patch does not change how the triggers are handled, it only makes
sure the states are handled in critical sections.

Signed-off-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
Message-Id: <20210817164054.250028-2-pierre-louis.bossart@linux.intel.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
sound/soc/soc-pcm.c