linux/sound/soc/fsl
Richard Fitzgerald eba2eb2495
ASoC: soc-card: Fix missing locking in snd_soc_card_get_kcontrol()
snd_soc_card_get_kcontrol() must be holding a read lock on
card->controls_rwsem while walking the controls list.

Compare with snd_ctl_find_numid().

The existing function is renamed snd_soc_card_get_kcontrol_locked()
so that it can be called from contexts that are already holding
card->controls_rwsem (for example, control get/put functions).

There are few direct or indirect callers of
snd_soc_card_get_kcontrol(), and most are safe. Three require
changes, which have been included in this patch:

codecs/cs35l45.c:
  cs35l45_activate_ctl() is called from a control put() function so
  is changed to call snd_soc_card_get_kcontrol_locked().

codecs/cs35l56.c:
  cs35l56_sync_asp1_mixer_widgets_with_firmware() is called from
  control get()/put() functions so is changed to call
  snd_soc_card_get_kcontrol_locked().

fsl/fsl_xcvr.c:
  fsl_xcvr_activate_ctl() is called from three places, one of which
  already holds card->controls_rwsem:
  1. fsl_xcvr_mode_put(), a control put function, which will
     already be holding card->controls_rwsem.
  2. fsl_xcvr_startup(), a DAI startup function.
  3. fsl_xcvr_shutdown(), a DAI shutdown function.

  To fix this, fsl_xcvr_activate_ctl() has been changed to call
  snd_soc_card_get_kcontrol_locked() so that it is safe to call
  directly from fsl_xcvr_mode_put().
  The fsl_xcvr_startup() and fsl_xcvr_shutdown() functions have been
  changed to take a read lock on card->controls_rsem() around calls
  to fsl_xcvr_activate_ctl(). While this is not very elegant, it
  keeps the change small, to avoid this patch creating a large
  collateral churn in fsl/fsl_xcvr.c.

Analysis of other callers of snd_soc_card_get_kcontrol() is that
they do not need any changes, they are not holding card->controls_rwsem
when they call snd_soc_card_get_kcontrol().

Direct callers of snd_soc_card_get_kcontrol():
  fsl/fsl_spdif.c: fsl_spdif_dai_probe() - DAI probe function
  fsl/fsl_micfil.c: voice_detected_fn() - IRQ handler

Indirect callers via soc_component_notify_control():
  codecs/cs42l43: cs42l43_mic_shutter() - IRQ handler
  codecs/cs42l43: cs42l43_spk_shutter() - IRQ handler
  codecs/ak4118.c: ak4118_irq_handler() - IRQ handler
  codecs/wm_adsp.c: wm_adsp_write_ctl() - not currently used

Indirect callers via snd_soc_limit_volume():
  qcom/sc8280xp.c: sc8280xp_snd_init() - DAIlink init function
  ti/rx51.c: rx51_aic34_init() - DAI init function

I don't have hardware to test the fsl/*, qcom/sc828xp.c, ti/rx51.c
and ak4118.c changes.

Backport note:
The fsl/, qcom/, cs35l45, cs35l56 and cs42l43 callers were added
since the Fixes commit so won't all be present on older kernels.

Signed-off-by: Richard Fitzgerald <rf@opensource.cirrus.com>
Fixes: 209c6cdfd2 ("ASoC: soc-card: move snd_soc_card_get_kcontrol() to soc-card")
Link: https://lore.kernel.org/r/20240221123710.690224-1-rf@opensource.cirrus.com
Signed-off-by: Mark Brown <broonie@kernel.org>
2024-02-23 13:40:06 +00:00
..
efika-audio-fabric.c ASoC: Explicitly include correct DT includes 2023-10-09 13:13:56 +01:00
eukrea-tlv320.c ASoC: fsl: convert not to use asoc_xxx() 2023-09-25 14:16:20 +02:00
fsl_asrc_common.h
fsl_asrc_dma.c ASoC: fsl: convert not to use asoc_xxx() 2023-09-25 14:16:20 +02:00
fsl_asrc.c ASoC: fsl: merge DAI call back functions into ops 2023-08-14 13:10:07 +01:00
fsl_asrc.h
fsl_aud2htx.c ASoC: Explicitly include correct DT includes 2023-10-09 13:13:56 +01:00
fsl_aud2htx.h
fsl_audmix.c ASoC: fsl: fsl_audmix: Convert to platform remove callback returning void 2023-03-20 13:07:58 +00:00
fsl_audmix.h
fsl_dma.c ASoC: fsl: convert not to use asoc_xxx() 2023-09-25 14:16:20 +02:00
fsl_dma.h
fsl_easrc.c ASoC: fsl: Fix PM disable depth imbalance in fsl_easrc_probe 2023-10-23 13:27:13 +01:00
fsl_easrc.h ASoC: fsl_easrc: use snd_pcm_format_t type for sample_format 2022-07-21 13:38:51 +01:00
fsl_esai.c ASoC: fsl: merge DAI call back functions into ops 2023-08-14 13:10:07 +01:00
fsl_esai.h
fsl_micfil.c ASoC: fsl: merge DAI call back functions into ops 2023-08-14 13:10:07 +01:00
fsl_micfil.h ASoC: Merge up fixes 2023-08-10 00:19:02 +01:00
fsl_mqs.c ASoC: fsl_mqs: remove duplicated including 2023-12-15 12:58:08 +00:00
fsl_qmc_audio.c soc: fsl: cpm1: qmc: Extend the API to provide Rx status 2023-12-12 10:29:20 +01:00
fsl_rpmsg.c ASoC: fsl_rpmsg: Fix error handler with pm_runtime_enable 2023-12-29 02:08:55 +00:00
fsl_rpmsg.h ASoC: fsl_rpmsg: add soc specific data structure 2021-09-13 01:59:15 +01:00
fsl_sai.c ASoC: fsl_sai: Fix channel swap issue on i.MX8MP 2023-12-19 13:23:39 +00:00
fsl_sai.h ASoC: fsl_sai: Disable bit clock with transmitter 2023-07-17 19:15:07 +01:00
fsl_spdif.c ASoC: Explicitly include correct DT includes 2023-10-09 13:13:56 +01:00
fsl_spdif.h ASoC: fsl_spdif: Add support for 22.05 kHz sample rate 2023-07-19 18:47:18 +01:00
fsl_ssi_dbg.c
fsl_ssi.c ASoC: fsl: convert not to use asoc_xxx() 2023-09-25 14:16:20 +02:00
fsl_ssi.h
fsl_utils.c ASoC: fsl: fsl-utils: remove useless assignment 2022-08-31 12:13:03 +01:00
fsl_utils.h ASoC: fsl_utils: Add function to handle PLL clock source 2022-07-05 13:00:37 +01:00
fsl_xcvr.c ASoC: soc-card: Fix missing locking in snd_soc_card_get_kcontrol() 2024-02-23 13:40:06 +00:00
fsl_xcvr.h ASoC: fsl_xcvr: Add support for i.MX93 platform 2023-01-09 13:04:22 +00:00
fsl-asoc-card.c ASoC: fsl: fsl-asoc-card: don't need DUMMY Platform 2023-12-19 13:23:42 +00:00
imx-audio-rpmsg.c ASoC: imx-audio-rpmsg: Remove redundant initialization owner in imx_audio_rpmsg_driver 2023-08-08 18:57:14 +01:00
imx-audmix.c ASoC: Merge up fixes 2023-09-26 16:14:44 +02:00
imx-audmux.c ASoC: Explicitly include correct DT includes 2023-10-09 13:13:56 +01:00
imx-audmux.h
imx-card.c ASoC: Explicitly include correct DT includes 2023-10-09 13:13:56 +01:00
imx-es8328.c ASoC: imx-es8328: Map missing jack kcontrols 2023-08-07 14:32:49 +01:00
imx-hdmi.c ASoC: fsl: convert not to use asoc_xxx() 2023-09-25 14:16:20 +02:00
imx-pcm-dma.c ASoC: fsl: Drop unused argument from imx_pcm_dma_init() 2022-02-28 13:33:57 +00:00
imx-pcm-fiq.c ASoC: fsl: imx-pcm-fiq: Use managed buffer allocation 2021-08-04 08:08:42 +02:00
imx-pcm-rpmsg.c ASoC: fsl: convert not to use asoc_xxx() 2023-09-25 14:16:20 +02:00
imx-pcm-rpmsg.h ASoC: imx-pcm-rpmsg: Fix warning of incorrect type in assignment 2021-05-10 13:05:38 +01:00
imx-pcm.h ASoC: fsl: Remove unused inline function imx_pcm_dma_params_init_data() 2022-09-23 13:56:25 +01:00
imx-rpmsg.c ASoC: imx-rpmsg: Force codec power on in low power audio mode 2023-11-21 14:43:00 +00:00
imx-sgtl5000.c ASoC: fsl: convert not to use asoc_xxx() 2023-09-25 14:16:20 +02:00
imx-spdif.c ASoC: fsl: convert not to use asoc_xxx() 2023-09-25 14:16:20 +02:00
imx-ssi.h dmaengine: imx: Move header to include/dma/ 2022-04-19 12:06:18 +01:00
Kconfig ASoC: Updates for v6.8 2024-01-08 08:18:02 +01:00
Makefile ASoC: fsl: mpc8610_hpcd: Remove unused driver 2023-11-22 14:29:27 +00:00
mpc5200_dma.c ASoC: fsl: mpc5200_dma.c: Fix warning of Function parameter or member not described 2023-10-10 12:39:37 +01:00
mpc5200_dma.h
mpc5200_psc_ac97.c ASoC: Explicitly include correct DT includes 2023-10-09 13:13:56 +01:00
mpc5200_psc_i2s.c ASoC: Explicitly include correct DT includes 2023-10-09 13:13:56 +01:00
p1022_ds.c ASoC: Explicitly include correct DT includes 2023-10-09 13:13:56 +01:00
p1022_rdk.c ASoC: Explicitly include correct DT includes 2023-10-09 13:13:56 +01:00
pcm030-audio-fabric.c ASoC: Explicitly include correct DT includes 2023-10-09 13:13:56 +01:00