aboutsummaryrefslogtreecommitdiffstats
path: root/sound/hda/codecs
diff options
context:
space:
mode:
authorTakashi Iwai <tiwai@suse.de>2025-08-27 09:28:51 +0200
committerTakashi Iwai <tiwai@suse.de>2025-08-29 11:52:14 +0200
commitece590486b59d434544c809d4e176fa4056dfcbc (patch)
tree8092bc1a3add8e0e2737e065f452e9cfbd956856 /sound/hda/codecs
parentALSA: hda/hdmi: Use guard() for mutex locks (diff)
downloadlinux-ece590486b59d434544c809d4e176fa4056dfcbc.tar.gz
linux-ece590486b59d434544c809d4e176fa4056dfcbc.zip
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.de
Diffstat (limited to 'sound/hda/codecs')
-rw-r--r--sound/hda/codecs/realtek/alc268.c3
-rw-r--r--sound/hda/codecs/realtek/realtek.c37
-rw-r--r--sound/hda/codecs/realtek/realtek.h21
3 files changed, 27 insertions, 34 deletions
diff --git a/sound/hda/codecs/realtek/alc268.c b/sound/hda/codecs/realtek/alc268.c
index e489cdc98eb8..4b565fb7bd1c 100644
--- a/sound/hda/codecs/realtek/alc268.c
+++ b/sound/hda/codecs/realtek/alc268.c
@@ -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;
}
diff --git a/sound/hda/codecs/realtek/realtek.c b/sound/hda/codecs/realtek/realtek.c
index b6feccfd45a9..d40de0e8a9a3 100644
--- a/sound/hda/codecs/realtek/realtek.c
+++ b/sound/hda/codecs/realtek/realtek.c
@@ -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");
diff --git a/sound/hda/codecs/realtek/realtek.h b/sound/hda/codecs/realtek/realtek.h
index ee893da0c486..b2a919904c4c 100644
--- a/sound/hda/codecs/realtek/realtek.h
+++ b/sound/hda/codecs/realtek/realtek.h
@@ -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 */