]> www.infradead.org Git - users/hch/misc.git/commitdiff
ALSA: hda/realtek: Use guard() for mutex locks and COEF locks
authorTakashi Iwai <tiwai@suse.de>
Wed, 27 Aug 2025 07:28:51 +0000 (09:28 +0200)
committerTakashi Iwai <tiwai@suse.de>
Fri, 29 Aug 2025 09:52:14 +0000 (11:52 +0200)
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
sound/hda/codecs/realtek/alc268.c
sound/hda/codecs/realtek/realtek.c
sound/hda/codecs/realtek/realtek.h

index e489cdc98eb88653a45385bb526562f625258d7a..4b565fb7bd1c6a2b8c86b06bbd01b1c1d4ff0cc6 100644 (file)
@@ -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;
 }
 
index b6feccfd45a9bfd81d438e759c5aeebf79097e1c..d40de0e8a9a398c529c6755c3fda7a92d31b22f6 100644 (file)
@@ -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");
 
index ee893da0c486a63dc975e625799e372e770512da..b2a919904c4c27c3abb6ed31ea58eef3db46ce32 100644 (file)
@@ -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 */