From 3bbd1e66d236e8f1dce64a03af2467843196bae4 Mon Sep 17 00:00:00 2001 From: Arun Raghavan Date: Thu, 9 Nov 2023 09:24:09 -0500 Subject: [PATCH] alsa: Prevent pitch element probe from stepping on bind ctls Since they're both using the same device, we want to make sure one doesn't cause the other to be closed on failure. --- spa/plugins/alsa/alsa-pcm.c | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/spa/plugins/alsa/alsa-pcm.c b/spa/plugins/alsa/alsa-pcm.c index b84ffbd1c..184052149 100644 --- a/spa/plugins/alsa/alsa-pcm.c +++ b/spa/plugins/alsa/alsa-pcm.c @@ -868,16 +868,20 @@ static int probe_pitch_ctl(struct state *state, const char* device_name) state->stream == SND_PCM_STREAM_CAPTURE ? "Capture Pitch 1000000" : "Playback Pitch 1000000"; + bool opened = false; int err; snd_lib_error_set_handler(silence_error_handler); - err = snd_ctl_open(&state->ctl, device_name, SND_CTL_NONBLOCK); - if (err < 0) { - spa_log_info(state->log, "%s could not find ctl device: %s", - device_name, snd_strerror(err)); - state->ctl = NULL; - goto error; + if (!state->ctl) { + err = snd_ctl_open(&state->ctl, device_name, SND_CTL_NONBLOCK); + if (err < 0) { + spa_log_info(state->log, "%s could not find ctl device: %s", + device_name, snd_strerror(err)); + state->ctl = NULL; + goto error; + } + opened = true; } snd_ctl_elem_id_alloca(&id); @@ -895,9 +899,11 @@ static int probe_pitch_ctl(struct state *state, const char* device_name) snd_ctl_elem_value_free(state->pitch_elem); state->pitch_elem = NULL; - snd_ctl_close(state->ctl); - state->ctl = NULL; - goto error; + if (opened) { + snd_ctl_close(state->ctl); + state->ctl = NULL; + goto error; + } } snd_ctl_elem_value_set_integer(state->pitch_elem, 0, 1000000);