ASoC: mchp-spdifrx: fix controls that works with completion mechanism
authorClaudiu Beznea <claudiu.beznea@microchip.com>
Mon, 30 Jan 2023 12:06:42 +0000 (14:06 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 10 Mar 2023 08:33:19 +0000 (09:33 +0100)
commitbbded1ed4c448806a3e8bc247d5b819e7df0e22e
treeb201d179f609b710f63c7c694fe4677b612d9949
parent9e72142dcc064e680b78072915c4baa869333de0
ASoC: mchp-spdifrx: fix controls that works with completion mechanism

[ Upstream commit d3681df44e856aab523a6eb7ba15b5e41efcbb1c ]

Channel status get and channel subcode get controls relies on data
returned by controls when certain IRQs are raised. To achieve that
completions are used b/w controls and interrupt service routine. The
concurrent accesses to these controls are protected by
struct snd_card::controls_rwsem.

Issues identified:
- reinit_completion() may be called while waiting for completion
  which should be avoided
- in case of multiple threads waiting, the complete() call in interrupt
  will signal only one waiting thread per interrupt which may lead to
  timeout for the others
- in case of channel status get as the CSC interrupt is not refcounted
  ISR may disable interrupt for threads that were just enabled it.

To solve these the access to controls were protected by a mutex. Along
with this there is no need for spinlock to protect the software cache
reads/updates b/w controls and ISR as the update is happening only when
requested from control, and only one reader can reach the control.

Fixes: ef265c55c1ac ("ASoC: mchp-spdifrx: add driver for SPDIF RX")
Signed-off-by: Claudiu Beznea <claudiu.beznea@microchip.com>
Link: https://lore.kernel.org/r/20230130120647.638049-4-claudiu.beznea@microchip.com
Signed-off-by: Mark Brown <broonie@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
sound/soc/atmel/mchp-spdifrx.c