ALSA: hda/realtek: Use guard() for mutex locks and COEF locks
Replace the manual mutex lock/unlock pairs with guard(). Also, introduce the guard() for coef_mutex_lock() and _unlock() pairs, and replace accordingly, too. The coef_mutex_lock() and *_unlock() are moved to readtek.h as static inline functions along with it. Only code refactoring, and no behavior change. Signed-off-by: Takashi Iwai <tiwai@suse.de> Link: https://patch.msgid.link/20250827072916.31933-12-tiwai@suse.depull/476/head
parent
2387cf78f5
commit
ece590486b
|
|
@ -12,7 +12,7 @@ static int alc268_beep_switch_put(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 & ~0xff) | 0x0f;
|
||||
err = snd_hda_mixer_amp_switch_put(kcontrol, ucontrol);
|
||||
|
|
@ -21,7 +21,6 @@ static int alc268_beep_switch_put(struct snd_kcontrol *kcontrol,
|
|||
err = snd_hda_mixer_amp_switch_put(kcontrol, ucontrol);
|
||||
}
|
||||
kcontrol->private_value = pval;
|
||||
mutex_unlock(&codec->control_mutex);
|
||||
return err;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -7,26 +7,6 @@
|
|||
#include <linux/module.h>
|
||||
#include "realtek.h"
|
||||
|
||||
/*
|
||||
* COEF access helper functions
|
||||
*/
|
||||
|
||||
static void coef_mutex_lock(struct hda_codec *codec)
|
||||
{
|
||||
struct alc_spec *spec = codec->spec;
|
||||
|
||||
snd_hda_power_up_pm(codec);
|
||||
mutex_lock(&spec->coef_mutex);
|
||||
}
|
||||
|
||||
static void coef_mutex_unlock(struct hda_codec *codec)
|
||||
{
|
||||
struct alc_spec *spec = codec->spec;
|
||||
|
||||
mutex_unlock(&spec->coef_mutex);
|
||||
snd_hda_power_down_pm(codec);
|
||||
}
|
||||
|
||||
static int __alc_read_coefex_idx(struct hda_codec *codec, hda_nid_t nid,
|
||||
unsigned int coef_idx)
|
||||
{
|
||||
|
|
@ -40,12 +20,8 @@ static int __alc_read_coefex_idx(struct hda_codec *codec, hda_nid_t nid,
|
|||
int alc_read_coefex_idx(struct hda_codec *codec, hda_nid_t nid,
|
||||
unsigned int coef_idx)
|
||||
{
|
||||
unsigned int val;
|
||||
|
||||
coef_mutex_lock(codec);
|
||||
val = __alc_read_coefex_idx(codec, nid, coef_idx);
|
||||
coef_mutex_unlock(codec);
|
||||
return val;
|
||||
guard(coef_mutex)(codec);
|
||||
return __alc_read_coefex_idx(codec, nid, coef_idx);
|
||||
}
|
||||
EXPORT_SYMBOL_NS_GPL(alc_read_coefex_idx, "SND_HDA_CODEC_REALTEK");
|
||||
|
||||
|
|
@ -59,9 +35,8 @@ static void __alc_write_coefex_idx(struct hda_codec *codec, hda_nid_t nid,
|
|||
void alc_write_coefex_idx(struct hda_codec *codec, hda_nid_t nid,
|
||||
unsigned int coef_idx, unsigned int coef_val)
|
||||
{
|
||||
coef_mutex_lock(codec);
|
||||
guard(coef_mutex)(codec);
|
||||
__alc_write_coefex_idx(codec, nid, coef_idx, coef_val);
|
||||
coef_mutex_unlock(codec);
|
||||
}
|
||||
EXPORT_SYMBOL_NS_GPL(alc_write_coefex_idx, "SND_HDA_CODEC_REALTEK");
|
||||
|
||||
|
|
@ -80,9 +55,8 @@ void alc_update_coefex_idx(struct hda_codec *codec, hda_nid_t nid,
|
|||
unsigned int coef_idx, unsigned int mask,
|
||||
unsigned int bits_set)
|
||||
{
|
||||
coef_mutex_lock(codec);
|
||||
guard(coef_mutex)(codec);
|
||||
__alc_update_coefex_idx(codec, nid, coef_idx, mask, bits_set);
|
||||
coef_mutex_unlock(codec);
|
||||
}
|
||||
EXPORT_SYMBOL_NS_GPL(alc_update_coefex_idx, "SND_HDA_CODEC_REALTEK");
|
||||
|
||||
|
|
@ -99,7 +73,7 @@ EXPORT_SYMBOL_NS_GPL(alc_get_coef0, "SND_HDA_CODEC_REALTEK");
|
|||
|
||||
void alc_process_coef_fw(struct hda_codec *codec, const struct coef_fw *fw)
|
||||
{
|
||||
coef_mutex_lock(codec);
|
||||
guard(coef_mutex)(codec);
|
||||
for (; fw->nid; fw++) {
|
||||
if (fw->mask == (unsigned short)-1)
|
||||
__alc_write_coefex_idx(codec, fw->nid, fw->idx, fw->val);
|
||||
|
|
@ -107,7 +81,6 @@ void alc_process_coef_fw(struct hda_codec *codec, const struct coef_fw *fw)
|
|||
__alc_update_coefex_idx(codec, fw->nid, fw->idx,
|
||||
fw->mask, fw->val);
|
||||
}
|
||||
coef_mutex_unlock(codec);
|
||||
}
|
||||
EXPORT_SYMBOL_NS_GPL(alc_process_coef_fw, "SND_HDA_CODEC_REALTEK");
|
||||
|
||||
|
|
|
|||
|
|
@ -295,4 +295,25 @@ void alc233_alc662_fixup_lenovo_dual_codecs(struct hda_codec *codec,
|
|||
void alc_fixup_dell_xps13(struct hda_codec *codec,
|
||||
const struct hda_fixup *fix, int action);
|
||||
|
||||
/*
|
||||
* COEF access helper functions
|
||||
*/
|
||||
static inline void coef_mutex_lock(struct hda_codec *codec)
|
||||
{
|
||||
struct alc_spec *spec = codec->spec;
|
||||
|
||||
snd_hda_power_up_pm(codec);
|
||||
mutex_lock(&spec->coef_mutex);
|
||||
}
|
||||
|
||||
static inline void coef_mutex_unlock(struct hda_codec *codec)
|
||||
{
|
||||
struct alc_spec *spec = codec->spec;
|
||||
|
||||
mutex_unlock(&spec->coef_mutex);
|
||||
snd_hda_power_down_pm(codec);
|
||||
}
|
||||
|
||||
DEFINE_GUARD(coef_mutex, struct hda_codec *, coef_mutex_lock(_T), coef_mutex_unlock(_T))
|
||||
|
||||
#endif /* __HDA_REALTEK_H */
|
||||
|
|
|
|||
Loading…
Reference in New Issue