Skip to contentSkip to conversation

ASoC: fsl_xcvr: fix missing lock in fsl_xcvr_mode_put()

PATCH In review Ziyi Guo 3 participants 5 messages Feb 2 – Feb 10

Subsystems (3)
lore
Share & tools
lore

Ziyi Guo

author
#0 lore raw

PATCH 1/1 ASoC: fsl_xcvr: fix missing lock in fsl_xcvr_mode_put()

fsl_xcvr_activate_ctl() has lockdep_assert_held(&card->snd_card->controls_rwsem), but fsl_xcvr_mode_put() calls it without acquiring this lock.

Other callers of fsl_xcvr_activate_ctl() in fsl_xcvr_startup() and fsl_xcvr_shutdown() properly acquire the lock with down_read()/up_read().

Add the missing down_read()/up_read() calls around fsl_xcvr_activate_ctl() in fsl_xcvr_mode_put() to fix the lockdep assertion and prevent potential race conditions when multiple userspace threads access the control.

---
 sound/soc/fsl/fsl_xcvr.c | 3 +++
 1 file changed, 3 insertions(+)
sound/soc/fsl/fsl_xcvr.c +3 -0
index a268fb81a2f8..0b9dd64b9a82 100644
@@ -223,10 +223,13 @@ static int fsl_xcvr_mode_put(struct snd_kcontrol *kcontrol,
 
 	xcvr->mode = snd_soc_enum_item_to_val(e, item[0]);
 
+	down_read(&card->snd_card->controls_rwsem);
 	fsl_xcvr_activate_ctl(dai, fsl_xcvr_arc_mode_kctl.name,
 			      (xcvr->mode == FSL_XCVR_MODE_ARC));
 	fsl_xcvr_activate_ctl(dai, fsl_xcvr_earc_capds_kctl.name,
 			      (xcvr->mode == FSL_XCVR_MODE_EARC));
+	up_read(&card->snd_card->controls_rwsem);
+
 	/* Allow playback for SPDIF only */
 	rtd = snd_soc_get_pcm_runtime(card, card->dai_link);
 	rtd->pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream_count =
Signature · 1 line
2.34.1
maintainer
#1 lore raw
Quoted 8 lines · Ziyi Guo

fsl_xcvr_activate_ctl() has lockdep_assert_held(&card->snd_card->controls_rwsem), but fsl_xcvr_mode_put() calls it without acquiring this lock.

Other callers of fsl_xcvr_activate_ctl() in fsl_xcvr_startup() and fsl_xcvr_shutdown() properly acquire the lock with down_read()/up_read().

[...]

Applied to

https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-next

Thanks!

[1/1] ASoC: fsl_xcvr: fix missing lock in fsl_xcvr_mode_put()

      commit: f514248727606b9087bc38a284ff686e0093abf1

All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying to this mail.

Thanks,
Mark

#2 lore raw
In reply to Ziyi Guo

Hi,

Am Montag, 2. Februar 2026, 18:41:12 CET schrieb Ziyi Guo:

Quoted 21 lines

fsl_xcvr_activate_ctl() has lockdep_assert_held(&card->snd_card->controls_rwsem), but fsl_xcvr_mode_put() calls it without acquiring this lock.

Other callers of fsl_xcvr_activate_ctl() in fsl_xcvr_startup() and fsl_xcvr_shutdown() properly acquire the lock with down_read()/up_read().

Add the missing down_read()/up_read() calls around fsl_xcvr_activate_ctl() in fsl_xcvr_mode_put() to fix the lockdep assertion and prevent potential race conditions when multiple userspace threads access the control.

---
 sound/soc/fsl/fsl_xcvr.c | 3 +++
 1 file changed, 3 insertions(+)
sound/soc/fsl/fsl_xcvr.c +0 -0
index a268fb81a2f8..0b9dd64b9a82 100644

sound/soc/fsl/fsl_xcvr.c static int fsl_xcvr_mode_put(struct snd_kcontrol *kcontrol, · line 226

Quoted 4 lines
sound/soc/fsl/fsl_xcvr.c +1 -0
@@ -223,10 +223,13 @@ static int fsl_xcvr_mode_put(struct snd_kcontrol *kcontrol,
 
 	xcvr->mode = snd_soc_enum_item_to_val(e, item[0]);
 
+	down_read(&card->snd_card->controls_rwsem);

This lock causes a blocked task on my TQMa8MPxL based board:

INFO: task alsactl:1969 blocked for more than 120 seconds.
      Tainted: G        W           6.19.0-next-20260209+ #3331
"echo 0 > /proc/sys/kernel/hung_task_timeout_secs" disables this message.
task:alsactl         state:D stack:0     pid:1969  tgid:1969  ppid:1      task_flags:0x400100 flags:0x00000a01
Call trace:
 __switch_to+0xdc/0x120 (T)
 __schedule+0x258/0x790
 schedule+0x30/0xb0
 schedule_preempt_disabled+0x20/0x40
 rwsem_down_read_slowpath+0x214/0x68c
 down_read+0xb0/0xb8
 fsl_xcvr_mode_put+0x4c/0xc0 [snd_soc_fsl_xcvr ac1b31380c6a6ea0d613bd5f78489e314a40f91f]
 snd_ctl_elem_write+0xdc/0x180 [snd 852e63996474051c57bcd1a86ebfd81083073853]
 snd_ctl_ioctl+0x7a4/0xaec [snd 852e63996474051c57bcd1a86ebfd81083073853]
 __arm64_sys_ioctl+0x9c/0xe4
 invoke_syscall.constprop.0+0x58/0xcc
 el0_svc_common.constprop.0+0xac/0xd4
 do_el0_svc+0x18/0x20
 el0_svc+0x24/0xa0
 el0t_64_sync_handler+0x98/0xdc
 el0t_64_sync+0x154/0x158
INFO: task alsactl:1969 <reader> blocked on an rw-semaphore likely owned by task alsactl:1969 <writer>

Best regards,
Alexander

Quoted 10 lines
sound/soc/fsl/fsl_xcvr.c +2 -0
 	fsl_xcvr_activate_ctl(dai, fsl_xcvr_arc_mode_kctl.name,
 			      (xcvr->mode == FSL_XCVR_MODE_ARC));
 	fsl_xcvr_activate_ctl(dai, fsl_xcvr_earc_capds_kctl.name,
 			      (xcvr->mode == FSL_XCVR_MODE_EARC));
+	up_read(&card->snd_card->controls_rwsem);
+
 	/* Allow playback for SPDIF only */
 	rtd = snd_soc_get_pcm_runtime(card, card->dai_link);
 	rtd->pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream_count =
Signature · 4 lines
TQ-Systems GmbH | Mühlstraße 2, Gut Delling | 82229 Seefeld, Germany
Amtsgericht München, HRB 105018
Geschäftsführer: Detlef Schneider, Rüdiger Stahl, Stefan Schneider
http://www.tq-group.com/
author
#3 lore raw
Quoted 17 lines

This lock causes a blocked task on my TQMa8MPxL based board:

INFO: task alsactl:1969 blocked for more than 120 seconds.
      Tainted: G        W           6.19.0-next-20260209+ #3331
"echo 0 > /proc/sys/kernel/hung_task_timeout_secs" disables this message.
task:alsactl         state:D stack:0     pid:1969  tgid:1969  ppid:1      task_flags:0x400100 flags:0x00000a01
Call trace:
 __switch_to+0xdc/0x120 (T)
 __schedule+0x258/0x790
 schedule+0x30/0xb0
 schedule_preempt_disabled+0x20/0x40
 rwsem_down_read_slowpath+0x214/0x68c
 down_read+0xb0/0xb8
 fsl_xcvr_mode_put+0x4c/0xc0 [snd_soc_fsl_xcvr ac1b31380c6a6ea0d613bd5f78489e314a40f91f]
 snd_ctl_elem_write+0xdc/0x180 [snd 852e63996474051c57bcd1a86ebfd81083073853]
 snd_ctl_ioctl+0x7a4/0xaec [snd 852e63996474051c57bcd1a86ebfd81083073853]
Quoted 8 lines
 __arm64_sys_ioctl+0x9c/0xe4
 invoke_syscall.constprop.0+0x58/0xcc
 el0_svc_common.constprop.0+0xac/0xd4
 do_el0_svc+0x18/0x20
 el0_svc+0x24/0xa0
 el0t_64_sync_handler+0x98/0xdc
 el0t_64_sync+0x154/0x158
INFO: task alsactl:1969 <reader> blocked on an rw-semaphore likely owned by task alsactl:1969 <writer>

Thanks Alexander for reminding this, it seems that in the context of the whole put operation, the lock is held through upper ALSA core layer, so we don't need to add lock protection simply for fsl_xcvr_activate_ctl() in the driver layer.

Thanks for your time and apologies for the inconvenience. I think we can drop this patch.

maintainer
#4 lore raw
Quoted 2 lines · Ziyi Guo

Thanks for your time and apologies for the inconvenience. I think we can drop this patch.

Please send a revert explaining the issue.