mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2026-02-19 06:38:26 -05:00
ALSA: hda/generic: Use guard() for mutex locks
Replace the manual mutex lock/unlock pairs with guard(). Only code refactoring, and no behavior change. Signed-off-by: Takashi Iwai <tiwai@suse.de> Link: https://patch.msgid.link/20250827072916.31933-17-tiwai@suse.de
This commit is contained in:
@@ -1118,12 +1118,11 @@ static int hda_gen_bind_mute_get(struct snd_kcontrol *kcontrol,
|
||||
unsigned long pval;
|
||||
int err;
|
||||
|
||||
mutex_lock(&codec->control_mutex);
|
||||
guard(mutex)(&codec->control_mutex);
|
||||
pval = kcontrol->private_value;
|
||||
kcontrol->private_value = pval & ~AMP_VAL_IDX_MASK; /* index 0 */
|
||||
err = snd_hda_mixer_amp_switch_get(kcontrol, ucontrol);
|
||||
kcontrol->private_value = pval;
|
||||
mutex_unlock(&codec->control_mutex);
|
||||
return err;
|
||||
}
|
||||
|
||||
@@ -1136,7 +1135,7 @@ static int hda_gen_bind_mute_put(struct snd_kcontrol *kcontrol,
|
||||
|
||||
sync_auto_mute_bits(kcontrol, ucontrol);
|
||||
|
||||
mutex_lock(&codec->control_mutex);
|
||||
guard(mutex)(&codec->control_mutex);
|
||||
pval = kcontrol->private_value;
|
||||
indices = (pval & AMP_VAL_IDX_MASK) >> AMP_VAL_IDX_SHIFT;
|
||||
for (i = 0; i < indices; i++) {
|
||||
@@ -1148,7 +1147,6 @@ static int hda_gen_bind_mute_put(struct snd_kcontrol *kcontrol,
|
||||
change |= err;
|
||||
}
|
||||
kcontrol->private_value = pval;
|
||||
mutex_unlock(&codec->control_mutex);
|
||||
return err < 0 ? err : change;
|
||||
}
|
||||
|
||||
@@ -2249,11 +2247,9 @@ static int indep_hp_put(struct snd_kcontrol *kcontrol,
|
||||
unsigned int select = ucontrol->value.enumerated.item[0];
|
||||
int ret = 0;
|
||||
|
||||
mutex_lock(&spec->pcm_mutex);
|
||||
if (spec->active_streams) {
|
||||
ret = -EBUSY;
|
||||
goto unlock;
|
||||
}
|
||||
guard(mutex)(&spec->pcm_mutex);
|
||||
if (spec->active_streams)
|
||||
return -EBUSY;
|
||||
|
||||
if (spec->indep_hp_enabled != select) {
|
||||
hda_nid_t *dacp;
|
||||
@@ -2285,8 +2281,6 @@ static int indep_hp_put(struct snd_kcontrol *kcontrol,
|
||||
call_hp_automute(codec, NULL);
|
||||
ret = 1;
|
||||
}
|
||||
unlock:
|
||||
mutex_unlock(&spec->pcm_mutex);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -3475,22 +3469,20 @@ static int cap_put_caller(struct snd_kcontrol *kcontrol,
|
||||
|
||||
imux = &spec->input_mux;
|
||||
adc_idx = kcontrol->id.index;
|
||||
mutex_lock(&codec->control_mutex);
|
||||
for (i = 0; i < imux->num_items; i++) {
|
||||
path = get_input_path(codec, adc_idx, i);
|
||||
if (!path || !path->ctls[type])
|
||||
continue;
|
||||
kcontrol->private_value = path->ctls[type];
|
||||
ret = func(kcontrol, ucontrol);
|
||||
if (ret < 0) {
|
||||
err = ret;
|
||||
break;
|
||||
scoped_guard(mutex, &codec->control_mutex) {
|
||||
for (i = 0; i < imux->num_items; i++) {
|
||||
path = get_input_path(codec, adc_idx, i);
|
||||
if (!path || !path->ctls[type])
|
||||
continue;
|
||||
kcontrol->private_value = path->ctls[type];
|
||||
ret = func(kcontrol, ucontrol);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
if (ret > 0)
|
||||
err = 1;
|
||||
}
|
||||
if (ret > 0)
|
||||
err = 1;
|
||||
}
|
||||
mutex_unlock(&codec->control_mutex);
|
||||
if (err >= 0 && spec->cap_sync_hook)
|
||||
if (spec->cap_sync_hook)
|
||||
spec->cap_sync_hook(codec, kcontrol, ucontrol);
|
||||
return err;
|
||||
}
|
||||
@@ -5332,17 +5324,17 @@ static int playback_pcm_open(struct hda_pcm_stream *hinfo,
|
||||
struct hda_gen_spec *spec = codec->spec;
|
||||
int err;
|
||||
|
||||
mutex_lock(&spec->pcm_mutex);
|
||||
guard(mutex)(&spec->pcm_mutex);
|
||||
err = snd_hda_multi_out_analog_open(codec,
|
||||
&spec->multiout, substream,
|
||||
hinfo);
|
||||
if (!err) {
|
||||
spec->active_streams |= 1 << STREAM_MULTI_OUT;
|
||||
call_pcm_playback_hook(hinfo, codec, substream,
|
||||
HDA_GEN_PCM_ACT_OPEN);
|
||||
}
|
||||
mutex_unlock(&spec->pcm_mutex);
|
||||
return err;
|
||||
if (err < 0)
|
||||
return err;
|
||||
|
||||
spec->active_streams |= 1 << STREAM_MULTI_OUT;
|
||||
call_pcm_playback_hook(hinfo, codec, substream,
|
||||
HDA_GEN_PCM_ACT_OPEN);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int playback_pcm_prepare(struct hda_pcm_stream *hinfo,
|
||||
@@ -5381,11 +5373,11 @@ static int playback_pcm_close(struct hda_pcm_stream *hinfo,
|
||||
struct snd_pcm_substream *substream)
|
||||
{
|
||||
struct hda_gen_spec *spec = codec->spec;
|
||||
mutex_lock(&spec->pcm_mutex);
|
||||
|
||||
guard(mutex)(&spec->pcm_mutex);
|
||||
spec->active_streams &= ~(1 << STREAM_MULTI_OUT);
|
||||
call_pcm_playback_hook(hinfo, codec, substream,
|
||||
HDA_GEN_PCM_ACT_CLOSE);
|
||||
mutex_unlock(&spec->pcm_mutex);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -5434,14 +5426,13 @@ static int alt_playback_pcm_open(struct hda_pcm_stream *hinfo,
|
||||
struct hda_gen_spec *spec = codec->spec;
|
||||
int err = 0;
|
||||
|
||||
mutex_lock(&spec->pcm_mutex);
|
||||
guard(mutex)(&spec->pcm_mutex);
|
||||
if (spec->indep_hp && !spec->indep_hp_enabled)
|
||||
err = -EBUSY;
|
||||
else
|
||||
spec->active_streams |= 1 << STREAM_INDEP_HP;
|
||||
call_pcm_playback_hook(hinfo, codec, substream,
|
||||
HDA_GEN_PCM_ACT_OPEN);
|
||||
mutex_unlock(&spec->pcm_mutex);
|
||||
return err;
|
||||
}
|
||||
|
||||
@@ -5450,11 +5441,11 @@ static int alt_playback_pcm_close(struct hda_pcm_stream *hinfo,
|
||||
struct snd_pcm_substream *substream)
|
||||
{
|
||||
struct hda_gen_spec *spec = codec->spec;
|
||||
mutex_lock(&spec->pcm_mutex);
|
||||
|
||||
guard(mutex)(&spec->pcm_mutex);
|
||||
spec->active_streams &= ~(1 << STREAM_INDEP_HP);
|
||||
call_pcm_playback_hook(hinfo, codec, substream,
|
||||
HDA_GEN_PCM_ACT_CLOSE);
|
||||
mutex_unlock(&spec->pcm_mutex);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user