[PATCH] ALSA: oxygen: use helper to activate the SPDIF PCM control
From: Runyu Xiao
Date: Sun Sep 27 2026 - 08:17:29 EST
oxygen_open() and oxygen_close() modify the SPDIF PCM control access
flags while holding chip->mutex. Direct access changes bypass the control
core locking and notification path.
Move the access transition outside the driver mutex and use
snd_ctl_activate_id(), which serializes the control update with the control
core.
Fixes: d0ce9946c52e ("[ALSA] add CMI8788 driver")
Assisted-by: LLM
Signed-off-by: Runyu Xiao <runyu.xiao@xxxxxxxxxx>
---
sound/pci/oxygen/oxygen_pcm.c | 37 +++++++++++++++--------------------
1 file changed, 16 insertions(+), 21 deletions(-)
diff --git a/sound/pci/oxygen/oxygen_pcm.c b/sound/pci/oxygen/oxygen_pcm.c
index b71635601..75efbf59a 100644
--- a/sound/pci/oxygen/oxygen_pcm.c
+++ b/sound/pci/oxygen/oxygen_pcm.c
@@ -171,16 +171,14 @@ static int oxygen_open(struct snd_pcm_substream *substream,
snd_pcm_set_sync(substream);
chip->streams[channel] = substream;
- guard(mutex)(&chip->mutex);
- chip->pcm_active |= 1 << channel;
- if (channel == PCM_SPDIF) {
- chip->spdif_pcm_bits = chip->spdif_bits;
- chip->controls[CONTROL_SPDIF_PCM]->vd[0].access &=
- ~SNDRV_CTL_ELEM_ACCESS_INACTIVE;
- snd_ctl_notify(chip->card, SNDRV_CTL_EVENT_MASK_VALUE |
- SNDRV_CTL_EVENT_MASK_INFO,
- &chip->controls[CONTROL_SPDIF_PCM]->id);
+ scoped_guard(mutex, &chip->mutex) {
+ chip->pcm_active |= 1 << channel;
+ if (channel == PCM_SPDIF)
+ chip->spdif_pcm_bits = chip->spdif_bits;
}
+ if (channel == PCM_SPDIF)
+ snd_ctl_activate_id(chip->card,
+ &chip->controls[CONTROL_SPDIF_PCM]->id, 1);
return 0;
}
@@ -220,19 +218,16 @@ static int oxygen_close(struct snd_pcm_substream *substream)
struct oxygen *chip = snd_pcm_substream_chip(substream);
unsigned int channel = oxygen_substream_channel(substream);
- guard(mutex)(&chip->mutex);
- chip->pcm_active &= ~(1 << channel);
- if (channel == PCM_SPDIF) {
- chip->controls[CONTROL_SPDIF_PCM]->vd[0].access |=
- SNDRV_CTL_ELEM_ACCESS_INACTIVE;
- snd_ctl_notify(chip->card, SNDRV_CTL_EVENT_MASK_VALUE |
- SNDRV_CTL_EVENT_MASK_INFO,
- &chip->controls[CONTROL_SPDIF_PCM]->id);
- }
- if (channel == PCM_SPDIF || channel == PCM_MULTICH)
- oxygen_update_spdif_source(chip);
+ scoped_guard(mutex, &chip->mutex) {
+ chip->pcm_active &= ~(1 << channel);
+ if (channel == PCM_SPDIF || channel == PCM_MULTICH)
+ oxygen_update_spdif_source(chip);
- chip->streams[channel] = NULL;
+ chip->streams[channel] = NULL;
+ }
+ if (channel == PCM_SPDIF)
+ snd_ctl_activate_id(chip->card,
+ &chip->controls[CONTROL_SPDIF_PCM]->id, 0);
return 0;
}
--
2.34.1