From: Takashi Iwai <tiwai@suse.de>
To: linux-sound@vger.kernel.org
Cc: David Rhodes <david.rhodes@cirrus.com>,
Richard Fitzgerald <rf@opensource.cirrus.com>,
patches@opensource.cirrus.com,
Shenghao Ding <shenghao-ding@ti.com>, Kevin Lu <kevin-lu@ti.com>,
Baojun Xu <baojun.xu@ti.com>
Subject: [PATCH 12/25] ALSA: hda/cs35l41: Use guard() for mutex locks
Date: Mon, 11 Aug 2025 12:07:46 +0200 [thread overview]
Message-ID: <20250811100807.7962-13-tiwai@suse.de> (raw)
In-Reply-To: <20250811100807.7962-1-tiwai@suse.de>
Replace the manual mutex lock/unlock pairs with guard().
Only code refactoring, and no behavior change.
Signed-off-by: Takashi Iwai <tiwai@suse.de>
---
sound/hda/codecs/side-codecs/cs35l41_hda.c | 110 +++++++++------------
1 file changed, 47 insertions(+), 63 deletions(-)
diff --git a/sound/hda/codecs/side-codecs/cs35l41_hda.c b/sound/hda/codecs/side-codecs/cs35l41_hda.c
index 37f2cdc8ce82..c04208e685a0 100644
--- a/sound/hda/codecs/side-codecs/cs35l41_hda.c
+++ b/sound/hda/codecs/side-codecs/cs35l41_hda.c
@@ -624,11 +624,10 @@ static void cs35l41_remove_dsp(struct cs35l41_hda *cs35l41)
cancel_work_sync(&cs35l41->fw_load_work);
- mutex_lock(&cs35l41->fw_mutex);
+ guard(mutex)(&cs35l41->fw_mutex);
cs35l41_shutdown_dsp(cs35l41);
cs_dsp_remove(dsp);
cs35l41->halo_initialized = false;
- mutex_unlock(&cs35l41->fw_mutex);
}
/* Protection release cycle to get the speaker out of Safe-Mode */
@@ -790,9 +789,9 @@ static void cs35l41_hda_pre_playback_hook(struct device *dev, int action)
switch (action) {
case HDA_GEN_PCM_ACT_CLEANUP:
- mutex_lock(&cs35l41->fw_mutex);
- cs35l41_hda_pause_start(dev);
- mutex_unlock(&cs35l41->fw_mutex);
+ scoped_guard(mutex, &cs35l41->fw_mutex) {
+ cs35l41_hda_pause_start(dev);
+ }
break;
default:
break;
@@ -813,24 +812,24 @@ static void cs35l41_hda_playback_hook(struct device *dev, int action)
pm_runtime_get_sync(dev);
break;
case HDA_GEN_PCM_ACT_PREPARE:
- mutex_lock(&cs35l41->fw_mutex);
- cs35l41_hda_play_start(dev);
- mutex_unlock(&cs35l41->fw_mutex);
+ scoped_guard(mutex, &cs35l41->fw_mutex) {
+ cs35l41_hda_play_start(dev);
+ }
break;
case HDA_GEN_PCM_ACT_CLEANUP:
- mutex_lock(&cs35l41->fw_mutex);
- cs35l41_hda_pause_done(dev);
- mutex_unlock(&cs35l41->fw_mutex);
+ scoped_guard(mutex, &cs35l41->fw_mutex) {
+ cs35l41_hda_pause_done(dev);
+ }
break;
case HDA_GEN_PCM_ACT_CLOSE:
- mutex_lock(&cs35l41->fw_mutex);
- if (!cs35l41->cs_dsp.running && cs35l41->request_fw_load &&
- !cs35l41->fw_request_ongoing) {
- dev_info(dev, "Requesting Firmware Load after HDA_GEN_PCM_ACT_CLOSE\n");
- cs35l41->fw_request_ongoing = true;
- schedule_work(&cs35l41->fw_load_work);
+ scoped_guard(mutex, &cs35l41->fw_mutex) {
+ if (!cs35l41->cs_dsp.running && cs35l41->request_fw_load &&
+ !cs35l41->fw_request_ongoing) {
+ dev_info(dev, "Requesting Firmware Load after HDA_GEN_PCM_ACT_CLOSE\n");
+ cs35l41->fw_request_ongoing = true;
+ schedule_work(&cs35l41->fw_load_work);
+ }
}
- mutex_unlock(&cs35l41->fw_mutex);
/*
* Playback must be finished for all amps before we start runtime suspend.
@@ -849,9 +848,9 @@ static void cs35l41_hda_post_playback_hook(struct device *dev, int action)
switch (action) {
case HDA_GEN_PCM_ACT_PREPARE:
- mutex_lock(&cs35l41->fw_mutex);
- cs35l41_hda_play_done(dev);
- mutex_unlock(&cs35l41->fw_mutex);
+ scoped_guard(mutex, &cs35l41->fw_mutex) {
+ cs35l41_hda_play_done(dev);
+ }
break;
default:
break;
@@ -917,13 +916,12 @@ static int cs35l41_verify_id(struct cs35l41_hda *cs35l41, unsigned int *regid, u
static int cs35l41_ready_for_reset(struct cs35l41_hda *cs35l41)
{
- mutex_lock(&cs35l41->fw_mutex);
+ guard(mutex)(&cs35l41->fw_mutex);
if (cs35l41->cs_dsp.running) {
cs35l41->cs_dsp.running = false;
cs35l41->cs_dsp.booted = false;
}
regcache_mark_dirty(cs35l41->regmap);
- mutex_unlock(&cs35l41->fw_mutex);
return 0;
}
@@ -939,10 +937,9 @@ static int cs35l41_system_suspend_prep(struct device *dev)
return 0; /* don't block the whole system suspend */
}
- mutex_lock(&cs35l41->fw_mutex);
+ guard(mutex)(&cs35l41->fw_mutex);
if (cs35l41->playback_started)
cs35l41_hda_pause_start(dev);
- mutex_unlock(&cs35l41->fw_mutex);
return 0;
}
@@ -959,10 +956,10 @@ static int cs35l41_system_suspend(struct device *dev)
return 0; /* don't block the whole system suspend */
}
- mutex_lock(&cs35l41->fw_mutex);
- if (cs35l41->playback_started)
- cs35l41_hda_pause_done(dev);
- mutex_unlock(&cs35l41->fw_mutex);
+ scoped_guard(mutex, &cs35l41->fw_mutex) {
+ if (cs35l41->playback_started)
+ cs35l41_hda_pause_done(dev);
+ }
ret = pm_runtime_force_suspend(dev);
if (ret) {
@@ -1047,13 +1044,12 @@ static int cs35l41_system_resume(struct device *dev)
return ret;
}
- mutex_lock(&cs35l41->fw_mutex);
+ guard(mutex)(&cs35l41->fw_mutex);
if (cs35l41->request_fw_load && !cs35l41->fw_request_ongoing) {
cs35l41->fw_request_ongoing = true;
schedule_work(&cs35l41->fw_load_work);
}
- mutex_unlock(&cs35l41->fw_mutex);
return ret;
}
@@ -1070,7 +1066,7 @@ static int cs35l41_runtime_idle(struct device *dev)
static int cs35l41_runtime_suspend(struct device *dev)
{
struct cs35l41_hda *cs35l41 = dev_get_drvdata(dev);
- int ret = 0;
+ int ret;
dev_dbg(cs35l41->dev, "Runtime Suspend\n");
@@ -1079,13 +1075,13 @@ static int cs35l41_runtime_suspend(struct device *dev)
return 0;
}
- mutex_lock(&cs35l41->fw_mutex);
+ guard(mutex)(&cs35l41->fw_mutex);
if (cs35l41->cs_dsp.running) {
ret = cs35l41_enter_hibernate(cs35l41->dev, cs35l41->regmap,
cs35l41->hw_cfg.bst_type);
if (ret)
- goto err;
+ return ret;
} else {
cs35l41_safe_reset(cs35l41->regmap, cs35l41->hw_cfg.bst_type);
}
@@ -1093,17 +1089,14 @@ static int cs35l41_runtime_suspend(struct device *dev)
regcache_cache_only(cs35l41->regmap, true);
regcache_mark_dirty(cs35l41->regmap);
-err:
- mutex_unlock(&cs35l41->fw_mutex);
-
- return ret;
+ return 0;
}
static int cs35l41_runtime_resume(struct device *dev)
{
struct cs35l41_hda *cs35l41 = dev_get_drvdata(dev);
unsigned int regid, reg_revid;
- int ret = 0;
+ int ret;
dev_dbg(cs35l41->dev, "Runtime Resume\n");
@@ -1112,7 +1105,7 @@ static int cs35l41_runtime_resume(struct device *dev)
return 0;
}
- mutex_lock(&cs35l41->fw_mutex);
+ guard(mutex)(&cs35l41->fw_mutex);
regcache_cache_only(cs35l41->regmap, false);
@@ -1120,13 +1113,13 @@ static int cs35l41_runtime_resume(struct device *dev)
ret = cs35l41_exit_hibernate(cs35l41->dev, cs35l41->regmap);
if (ret) {
dev_warn(cs35l41->dev, "Unable to exit Hibernate.");
- goto err;
+ return ret;
}
}
ret = cs35l41_verify_id(cs35l41, ®id, ®_revid);
if (ret)
- goto err;
+ return ret;
/* Test key needs to be unlocked to allow the OTP settings to re-apply */
cs35l41_test_key_unlock(cs35l41->dev, cs35l41->regmap);
@@ -1134,7 +1127,7 @@ static int cs35l41_runtime_resume(struct device *dev)
cs35l41_test_key_lock(cs35l41->dev, cs35l41->regmap);
if (ret) {
dev_err(cs35l41->dev, "Failed to restore register cache: %d\n", ret);
- goto err;
+ return ret;
}
if (cs35l41->hw_cfg.bst_type == CS35L41_EXT_BOOST)
@@ -1142,22 +1135,14 @@ static int cs35l41_runtime_resume(struct device *dev)
dev_dbg(cs35l41->dev, "CS35L41 Resumed (%x), Revision: %02X\n", regid, reg_revid);
-err:
- mutex_unlock(&cs35l41->fw_mutex);
-
- return ret;
+ return 0;
}
static int cs35l41_hda_read_ctl(struct cs_dsp *dsp, const char *name, int type,
unsigned int alg, void *buf, size_t len)
{
- int ret;
-
- mutex_lock(&dsp->pwr_lock);
- ret = cs_dsp_coeff_read_ctrl(cs_dsp_get_ctl(dsp, name, type, alg), 0, buf, len);
- mutex_unlock(&dsp->pwr_lock);
-
- return ret;
+ guard(mutex)(&dsp->pwr_lock);
+ return cs_dsp_coeff_read_ctrl(cs_dsp_get_ctl(dsp, name, type, alg), 0, buf, len);
}
static int cs35l41_smart_amp(struct cs35l41_hda *cs35l41)
@@ -1272,16 +1257,15 @@ static void cs35l41_fw_load_work(struct work_struct *work)
pm_runtime_get_sync(cs35l41->dev);
- mutex_lock(&cs35l41->fw_mutex);
+ scoped_guard(mutex, &cs35l41->fw_mutex) {
+ /* Recheck if playback is ongoing, mutex will block playback during firmware loading */
+ if (cs35l41->playback_started)
+ dev_err(cs35l41->dev, "Cannot Load/Unload firmware during Playback. Retrying...\n");
+ else
+ cs35l41_load_firmware(cs35l41, cs35l41->request_fw_load);
- /* Recheck if playback is ongoing, mutex will block playback during firmware loading */
- if (cs35l41->playback_started)
- dev_err(cs35l41->dev, "Cannot Load/Unload firmware during Playback. Retrying...\n");
- else
- cs35l41_load_firmware(cs35l41, cs35l41->request_fw_load);
-
- cs35l41->fw_request_ongoing = false;
- mutex_unlock(&cs35l41->fw_mutex);
+ cs35l41->fw_request_ongoing = false;
+ }
pm_runtime_put_autosuspend(cs35l41->dev);
}
--
2.50.1
next prev parent reply other threads:[~2025-08-11 10:08 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-11 10:07 [PATCH 00/25] ALSA: hda: Use auto-cleanup macros Takashi Iwai
2025-08-11 10:07 ` [PATCH 01/25] ALSA: hda: Introduce auto cleanup macros for PM Takashi Iwai
2025-08-11 10:07 ` [PATCH 02/25] ALSA: hda/ca0132: Use cleanup macros for PM controls Takashi Iwai
2025-08-11 10:07 ` [PATCH 03/25] ALSA: hda/hdmi: " Takashi Iwai
2025-08-11 10:07 ` [PATCH 04/25] ALSA: hda/realtek: " Takashi Iwai
2025-08-11 10:07 ` [PATCH 05/25] ALSA: hda/common: " Takashi Iwai
2025-08-11 10:07 ` [PATCH 06/25] ALSA: hda: Use auto cleanup macros for DSP loader locks Takashi Iwai
2025-08-11 10:07 ` [PATCH 07/25] ALSA: hda/common: Use guard() for mutex locks Takashi Iwai
2025-08-11 10:07 ` [PATCH 08/25] ALSA: hda/core: " Takashi Iwai
2025-08-11 10:07 ` [PATCH 09/25] ALSA: hda/ca0132: " Takashi Iwai
2025-08-11 10:07 ` [PATCH 10/25] ALSA: hda/hdmi: " Takashi Iwai
2025-08-11 10:07 ` [PATCH 11/25] ALSA: hda/realtek: " Takashi Iwai
2025-08-11 10:07 ` Takashi Iwai [this message]
2025-08-11 10:07 ` [PATCH 13/25] ALSA: hda/tas2781: " Takashi Iwai
2025-08-11 10:07 ` [PATCH 14/25] ALSA: hda/cs8409: " Takashi Iwai
2025-08-11 10:07 ` [PATCH 15/25] ALSA: hda/component: " Takashi Iwai
2025-08-11 10:07 ` [PATCH 16/25] ALSA: hda/generic: " Takashi Iwai
2025-08-11 10:07 ` [PATCH 17/25] ALSA: hda/analog: " Takashi Iwai
2025-08-11 10:07 ` [PATCH 18/25] ALSA: hda/intel: " Takashi Iwai
2025-08-11 10:07 ` [PATCH 19/25] ALSA: hda/common: Use auto cleanup for temporary buffers Takashi Iwai
2025-08-11 10:07 ` [PATCH 20/25] ALSA: hda/realtek: " Takashi Iwai
2025-08-11 10:07 ` [PATCH 21/25] ALSA: hda/generic: " Takashi Iwai
2025-08-11 10:07 ` [PATCH 22/25] ALSA: hda/ext: Use guard() for spinlocks Takashi Iwai
2025-08-11 10:07 ` [PATCH 23/25] ALSA: hda/core: " Takashi Iwai
2025-08-13 14:07 ` Andy Shevchenko
2025-08-13 14:10 ` Andy Shevchenko
2025-08-13 14:19 ` Takashi Iwai
2025-08-11 10:07 ` [PATCH 24/25] ALSA: hda/common: " Takashi Iwai
2025-08-11 10:07 ` [PATCH 25/25] ALSA: hda/intel: " Takashi Iwai
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250811100807.7962-13-tiwai@suse.de \
--to=tiwai@suse.de \
--cc=baojun.xu@ti.com \
--cc=david.rhodes@cirrus.com \
--cc=kevin-lu@ti.com \
--cc=linux-sound@vger.kernel.org \
--cc=patches@opensource.cirrus.com \
--cc=rf@opensource.cirrus.com \
--cc=shenghao-ding@ti.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox