]> www.infradead.org Git - users/hch/misc.git/commitdiff
ALSA: hda/common: Use cleanup macros for PM controls
authorTakashi Iwai <tiwai@suse.de>
Wed, 27 Aug 2025 07:28:45 +0000 (09:28 +0200)
committerTakashi Iwai <tiwai@suse.de>
Fri, 29 Aug 2025 09:52:14 +0000 (11:52 +0200)
The new macro CLASS(snd_hda_power_pm) can replace the manual
snd_hda_power_up_pm() and _down() calls gracefully.

A part of the code in codec_exec_verb() is factored out to a function,
so that the auto-cleanup can be well scoped.

Merely cleanups and no functional changes.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
Link: https://patch.msgid.link/20250827072916.31933-6-tiwai@suse.de
sound/hda/common/codec.c
sound/hda/common/proc.c
sound/hda/common/sysfs.c

index 7a72d4c7ae914a25209207a10a03a5ae560eb1b0..3e692dd6725e17703813c8df14a6c3c1d043857f 100644 (file)
 #define codec_has_clkstop(codec) \
        ((codec)->core.power_caps & AC_PWRST_CLKSTOP)
 
+static int call_exec_verb(struct hda_bus *bus, struct hda_codec *codec,
+                         unsigned int cmd, unsigned int flags,
+                         unsigned int *res)
+{
+       int err;
+
+       CLASS(snd_hda_power_pm, pm)(codec);
+       mutex_lock(&bus->core.cmd_mutex);
+       if (flags & HDA_RW_NO_RESPONSE_FALLBACK)
+               bus->no_response_fallback = 1;
+       err = snd_hdac_bus_exec_verb_unlocked(&bus->core, codec->core.addr,
+                                             cmd, res);
+       bus->no_response_fallback = 0;
+       mutex_unlock(&bus->core.cmd_mutex);
+       return err;
+}
+
 /*
  * Send and receive a verb - passed to exec_verb override for hdac_device
  */
@@ -46,15 +63,7 @@ static int codec_exec_verb(struct hdac_device *dev, unsigned int cmd,
                return -1;
 
  again:
-       snd_hda_power_up_pm(codec);
-       mutex_lock(&bus->core.cmd_mutex);
-       if (flags & HDA_RW_NO_RESPONSE_FALLBACK)
-               bus->no_response_fallback = 1;
-       err = snd_hdac_bus_exec_verb_unlocked(&bus->core, codec->core.addr,
-                                             cmd, res);
-       bus->no_response_fallback = 0;
-       mutex_unlock(&bus->core.cmd_mutex);
-       snd_hda_power_down_pm(codec);
+       err = call_exec_verb(bus, codec, cmd, flags, res);
        if (!codec_in_pm(codec) && res && err == -EAGAIN) {
                if (bus->response_reset) {
                        codec_dbg(codec,
@@ -633,12 +642,11 @@ static void hda_jackpoll_work(struct work_struct *work)
                return;
 
        /* the power-up/down sequence triggers the runtime resume */
-       snd_hda_power_up(codec);
+       CLASS(snd_hda_power, pm)(codec);
        /* update jacks manually if polling is required, too */
        snd_hda_jack_set_dirty_all(codec);
        snd_hda_jack_poll_all(codec);
        schedule_delayed_work(&codec->jackpoll_work, codec->jackpoll_interval);
-       snd_hda_power_down(codec);
 }
 
 /* release all pincfg lists */
index d36195f73d45b3125e4f9ce083519156496da380..5f3f61519ba6462f674dac7b483508415a2ee43e 100644 (file)
@@ -781,7 +781,7 @@ static void print_codec_info(struct snd_info_entry *entry,
        fg = codec->core.afg;
        if (!fg)
                return;
-       snd_hda_power_up(codec);
+       CLASS(snd_hda_power, pm)(codec);
        snd_iprintf(buffer, "Default PCM:\n");
        print_pcm_caps(buffer, codec, fg);
        snd_iprintf(buffer, "Default Amp-In caps: ");
@@ -794,7 +794,6 @@ static void print_codec_info(struct snd_info_entry *entry,
        nodes = snd_hda_get_sub_nodes(codec, fg, &nid);
        if (! nid || nodes < 0) {
                snd_iprintf(buffer, "Invalid AFG subtree\n");
-               snd_hda_power_down(codec);
                return;
        }
 
@@ -931,7 +930,6 @@ static void print_codec_info(struct snd_info_entry *entry,
 
                kfree(conn);
        }
-       snd_hda_power_down(codec);
 }
 
 /*
index 140e24bf4d7fc5da40e9255d6def98a57ae4c2b7..0d464d4dd7c94c183d8b66627912fb8f853fea41 100644 (file)
@@ -129,21 +129,18 @@ static int reconfig_codec(struct hda_codec *codec)
 {
        int err;
 
-       snd_hda_power_up(codec);
+       CLASS(snd_hda_power, pm)(codec);
        codec_info(codec, "hda-codec: reconfiguring\n");
        err = snd_hda_codec_reset(codec);
        if (err < 0) {
                codec_err(codec,
                           "The codec is being used, can't reconfigure.\n");
-               goto error;
+               return err;
        }
        err = device_reprobe(hda_codec_dev(codec));
        if (err < 0)
-               goto error;
-       err = snd_card_register(codec->card);
- error:
-       snd_hda_power_down(codec);
-       return err;
+               return err;
+       return snd_card_register(codec->card);
 }
 
 /*