Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A91A9314A83 for ; Wed, 27 Aug 2025 07:30:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.130 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756279844; cv=none; b=RbBCRNw3s47zTP4hynYCGoTv8io/wPvS9761usveb7t0KzdMllaKB5lzqSajetHjtflBDTosWX6XWUKN9tWkXMrxdQK6rj67ourlw7jie+J6guY71X0tBVZodxQfsiuYVPFn5dG5b8CEUeP1AnWQvd+CG2dJrNY6Yq6YkyNWLhQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756279844; c=relaxed/simple; bh=4Ij3X7mnnbeGAYTIyU4/SeztDgXk5qBiP3CilCgFo2o=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=nC5PcuPrGtXM5YTiJTHpOuiKfJw/G2G2cd3Aj+fo38IBkMFCaz1sU9FMv5GvUgznr7Dk5+LL0xbA16OqA9yAxmSRuN5epy5F4VPWQ00CWy8fJF5sZ7VnGqcgfDzrR49cWePVdbpJo80EL1isLzIEofoj5HfIADIYuybF2GH5Ex8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de; spf=pass smtp.mailfrom=suse.de; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=tnXK+3uG; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=Oyiea6sz; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=tnXK+3uG; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=Oyiea6sz; arc=none smtp.client-ip=195.135.223.130 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="tnXK+3uG"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="Oyiea6sz"; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="tnXK+3uG"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="Oyiea6sz" Received: from imap1.dmz-prg2.suse.org (unknown [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 3FA3E22390; Wed, 27 Aug 2025 07:29:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1756279760; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=uk8Z3PFsKk9vRV2vy7oF7Zim4jYkhCd2cO3Gr+GuFj4=; b=tnXK+3uGCXw9PKdLGrrgN5spKyDMzNNHAyf2Nh0Q+wxH49SnDEcItmYE96vGdg/9zaEDUW yqI1y2bdphBmXlMEWMndnQ0GzSNsSuDMDspajy+vWG/mtZW9kPNq9f9ZzpFU9GJs8+7RfJ 2r9qM9t9rnEZqVqV7T4t36mlLTBvlZE= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1756279760; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=uk8Z3PFsKk9vRV2vy7oF7Zim4jYkhCd2cO3Gr+GuFj4=; b=Oyiea6szyogxyV5ZJB3N0pFnmQWuW7byhboiziEO6rJFLuS2mdD2aRUviZSa/W0JWKac6i s2wDJhA2iW4Hy3AQ== Authentication-Results: smtp-out1.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1756279760; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=uk8Z3PFsKk9vRV2vy7oF7Zim4jYkhCd2cO3Gr+GuFj4=; b=tnXK+3uGCXw9PKdLGrrgN5spKyDMzNNHAyf2Nh0Q+wxH49SnDEcItmYE96vGdg/9zaEDUW yqI1y2bdphBmXlMEWMndnQ0GzSNsSuDMDspajy+vWG/mtZW9kPNq9f9ZzpFU9GJs8+7RfJ 2r9qM9t9rnEZqVqV7T4t36mlLTBvlZE= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1756279760; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=uk8Z3PFsKk9vRV2vy7oF7Zim4jYkhCd2cO3Gr+GuFj4=; b=Oyiea6szyogxyV5ZJB3N0pFnmQWuW7byhboiziEO6rJFLuS2mdD2aRUviZSa/W0JWKac6i s2wDJhA2iW4Hy3AQ== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 2198A13A6A; Wed, 27 Aug 2025 07:29:20 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id uGnwBtCzrmjoagAAD6G6ig (envelope-from ); Wed, 27 Aug 2025 07:29:20 +0000 From: Takashi Iwai To: linux-sound@vger.kernel.org Subject: [PATCH v2 05/25] ALSA: hda/common: Use cleanup macros for PM controls Date: Wed, 27 Aug 2025 09:28:45 +0200 Message-ID: <20250827072916.31933-6-tiwai@suse.de> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20250827072916.31933-1-tiwai@suse.de> References: <20250827072916.31933-1-tiwai@suse.de> Precedence: bulk X-Mailing-List: linux-sound@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Level: X-Spamd-Result: default: False [-2.80 / 50.00]; BAYES_HAM(-3.00)[100.00%]; NEURAL_HAM_LONG(-1.00)[-1.000]; MID_CONTAINS_FROM(1.00)[]; R_MISSING_CHARSET(0.50)[]; NEURAL_HAM_SHORT(-0.20)[-0.999]; MIME_GOOD(-0.10)[text/plain]; FUZZY_RATELIMITED(0.00)[rspamd.com]; RCVD_VIA_SMTP_AUTH(0.00)[]; RCPT_COUNT_ONE(0.00)[1]; ARC_NA(0.00)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; DBL_BLOCKED_OPENRESOLVER(0.00)[imap1.dmz-prg2.suse.org:helo,suse.de:email,suse.de:mid]; FROM_EQ_ENVFROM(0.00)[]; FROM_HAS_DN(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_COUNT_TWO(0.00)[2]; TO_MATCH_ENVRCPT_ALL(0.00)[]; TO_DN_NONE(0.00)[]; RCVD_TLS_ALL(0.00)[] X-Spam-Flag: NO X-Spam-Score: -2.80 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 --- sound/hda/common/codec.c | 30 +++++++++++++++++++----------- sound/hda/common/proc.c | 4 +--- sound/hda/common/sysfs.c | 11 ++++------- 3 files changed, 24 insertions(+), 21 deletions(-) diff --git a/sound/hda/common/codec.c b/sound/hda/common/codec.c index 7a72d4c7ae91..3e692dd6725e 100644 --- a/sound/hda/common/codec.c +++ b/sound/hda/common/codec.c @@ -32,6 +32,23 @@ #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 */ diff --git a/sound/hda/common/proc.c b/sound/hda/common/proc.c index d36195f73d45..5f3f61519ba6 100644 --- a/sound/hda/common/proc.c +++ b/sound/hda/common/proc.c @@ -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); } /* diff --git a/sound/hda/common/sysfs.c b/sound/hda/common/sysfs.c index 140e24bf4d7f..0d464d4dd7c9 100644 --- a/sound/hda/common/sysfs.c +++ b/sound/hda/common/sysfs.c @@ -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); } /* -- 2.50.1