From: phucduc.bui@gmail.com
To: Mark Brown <broonie@kernel.org>,
Liam Girdwood <liam.r.girdwood@linux.intel.com>,
Cezary Rojewski <cezary.rojewski@intel.com>
Cc: Jaroslav Kysela <perex@perex.cz>, Takashi Iwai <tiwai@suse.com>,
Peter Ujfalusi <peter.ujfalusi@linux.intel.com>,
Bard Liao <yung-chuan.liao@linux.intel.com>,
Kai Vehmanen <kai.vehmanen@linux.intel.com>,
Pierre-Louis Bossart <pierre-louis.bossart@linux.dev>,
linux-sound@vger.kernel.org, linux-kernel@vger.kernel.org,
bui duc phuc <phucduc.bui@gmail.com>
Subject: [PATCH 18/20] ASoC: Intel: atom: sst-atom-controls: Use guard() for mutex locks
Date: Thu, 11 Jun 2026 18:58:59 +0700 [thread overview]
Message-ID: <20260611115901.80438-19-phucduc.bui@gmail.com> (raw)
In-Reply-To: <20260611115901.80438-1-phucduc.bui@gmail.com>
From: bui duc phuc <phucduc.bui@gmail.com>
Clean up the code using guard() for mutex locks.
In sst_algo_control_set() and sst_gain_put(), the mutex release point
moves from immediately before dev_err() to scope exit. However, the
affected path only emits a warning and immediately returns -EINVAL,
without any further processing, so the change does not affect behavior.
This is purely a code refactoring with no intended functional change.
Signed-off-by: bui duc phuc <phucduc.bui@gmail.com>
---
sound/soc/intel/atom/sst-atom-controls.c | 85 +++++++++++-------------
1 file changed, 37 insertions(+), 48 deletions(-)
diff --git a/sound/soc/intel/atom/sst-atom-controls.c b/sound/soc/intel/atom/sst-atom-controls.c
index 3629ceaaac17..54defde24397 100644
--- a/sound/soc/intel/atom/sst-atom-controls.c
+++ b/sound/soc/intel/atom/sst-atom-controls.c
@@ -75,10 +75,9 @@ static int sst_fill_and_send_cmd(struct sst_data *drv,
{
int ret;
- mutex_lock(&drv->lock);
+ guard(mutex)(&drv->lock);
ret = sst_fill_and_send_cmd_unlocked(drv, ipc_msg, block,
task_id, pipe_id, cmd_data, len);
- mutex_unlock(&drv->lock);
return ret;
}
@@ -167,15 +166,15 @@ static int sst_slot_get(struct snd_kcontrol *kcontrol,
unsigned int val, mux;
u8 *map = is_tx ? sst_ssp_rx_map : sst_ssp_tx_map;
- mutex_lock(&drv->lock);
- val = 1 << ctl_no;
- /* search which slot/channel has this bit set - there should be only one */
- for (mux = e->max; mux > 0; mux--)
- if (map[mux - 1] & val)
- break;
+ scoped_guard(mutex, &drv->lock) {
+ val = 1 << ctl_no;
+ /* search which slot/channel has this bit set - there should be only one */
+ for (mux = e->max; mux > 0; mux--)
+ if (map[mux - 1] & val)
+ break;
- ucontrol->value.enumerated.item[0] = mux;
- mutex_unlock(&drv->lock);
+ ucontrol->value.enumerated.item[0] = mux;
+ }
dev_dbg(c->dev, "%s - %s map = %#x\n",
is_tx ? "tx channel" : "rx slot",
@@ -235,7 +234,7 @@ static int sst_slot_put(struct snd_kcontrol *kcontrol,
if (mux > e->max - 1)
return -EINVAL;
- mutex_lock(&drv->lock);
+ guard(mutex)(&drv->lock);
/* first clear all registers of this bit */
for (i = 0; i < e->max; i++)
map[i] &= ~val;
@@ -244,7 +243,6 @@ static int sst_slot_put(struct snd_kcontrol *kcontrol,
/* kctl set to 'none' and we reset the bits so send IPC */
ret = sst_check_and_send_slot_map(drv, kcontrol);
- mutex_unlock(&drv->lock);
return ret;
}
@@ -258,7 +256,6 @@ static int sst_slot_put(struct snd_kcontrol *kcontrol,
ret = sst_check_and_send_slot_map(drv, kcontrol);
- mutex_unlock(&drv->lock);
return ret;
}
@@ -354,13 +351,12 @@ static int sst_algo_control_set(struct snd_kcontrol *kcontrol,
struct sst_algo_control *bc = (void *)kcontrol->private_value;
dev_dbg(cmpnt->dev, "control_name=%s\n", kcontrol->id.name);
- mutex_lock(&drv->lock);
+ guard(mutex)(&drv->lock);
switch (bc->type) {
case SST_ALGO_PARAMS:
memcpy(bc->params, ucontrol->value.bytes.data, bc->max);
break;
default:
- mutex_unlock(&drv->lock);
dev_err(cmpnt->dev, "Invalid Input- algo type:%d\n",
bc->type);
return -EINVAL;
@@ -368,7 +364,6 @@ static int sst_algo_control_set(struct snd_kcontrol *kcontrol,
/*if pipe is enabled, need to send the algo params from here*/
if (bc->w && bc->w->power)
ret = sst_send_algo_cmd(drv, bc);
- mutex_unlock(&drv->lock);
return ret;
}
@@ -475,7 +470,7 @@ static int sst_gain_put(struct snd_kcontrol *kcontrol,
struct sst_gain_mixer_control *mc = (void *)kcontrol->private_value;
struct sst_gain_value *gv = mc->gain_val;
- mutex_lock(&drv->lock);
+ guard(mutex)(&drv->lock);
switch (mc->type) {
case SST_GAIN_TLV:
@@ -497,7 +492,6 @@ static int sst_gain_put(struct snd_kcontrol *kcontrol,
break;
default:
- mutex_unlock(&drv->lock);
dev_err(cmpnt->dev, "Invalid Input- gain type:%d\n",
mc->type);
return -EINVAL;
@@ -506,7 +500,6 @@ static int sst_gain_put(struct snd_kcontrol *kcontrol,
if (mc->w && mc->w->power)
ret = sst_send_gain_cmd(drv, gv, mc->task_id,
mc->pipe_id | mc->instance_id, mc->module_id, 0);
- mutex_unlock(&drv->lock);
return ret;
}
@@ -521,10 +514,9 @@ static int sst_send_pipe_module_params(struct snd_soc_dapm_widget *w,
struct sst_data *drv = snd_soc_component_get_drvdata(c);
struct sst_ids *ids = w->priv;
- mutex_lock(&drv->lock);
+ guard(mutex)(&drv->lock);
sst_find_and_send_pipe_algo(drv, w->name, ids);
sst_set_pipe_gain(ids, drv, 0);
- mutex_unlock(&drv->lock);
return 0;
}
@@ -761,27 +753,27 @@ int sst_handle_vb_timer(struct snd_soc_dai *dai, bool enable)
return ret;
}
- mutex_lock(&drv->lock);
- if (enable)
- timer_usage++;
- else
- timer_usage--;
-
- /*
- * Send the command only if this call is the first enable or last
- * disable
- */
- if ((enable && (timer_usage == 1)) ||
- (!enable && (timer_usage == 0))) {
- ret = sst_fill_and_send_cmd_unlocked(drv, SST_IPC_IA_CMD,
- SST_FLAG_BLOCKED, SST_TASK_SBA, 0, &cmd,
- sizeof(cmd.header) + cmd.header.length);
- if (ret && enable) {
+ scoped_guard(mutex, &drv->lock) {
+ if (enable)
+ timer_usage++;
+ else
timer_usage--;
- enable = false;
+
+ /*
+ * Send the command only if this call is the first enable or last
+ * disable
+ */
+ if ((enable && (timer_usage == 1)) ||
+ (!enable && (timer_usage == 0))) {
+ ret = sst_fill_and_send_cmd_unlocked(drv, SST_IPC_IA_CMD,
+ SST_FLAG_BLOCKED, SST_TASK_SBA, 0, &cmd,
+ sizeof(cmd.header) + cmd.header.length);
+ if (ret && enable) {
+ timer_usage--;
+ enable = false;
+ }
}
}
- mutex_unlock(&drv->lock);
if (!enable)
sst->ops->power(sst->dev, false);
@@ -984,9 +976,8 @@ static int sst_set_be_modules(struct snd_soc_dapm_widget *w,
dev_dbg(c->dev, "Enter: widget=%s\n", w->name);
if (SND_SOC_DAPM_EVENT_ON(event)) {
- mutex_lock(&drv->lock);
- ret = sst_send_slot_map(drv);
- mutex_unlock(&drv->lock);
+ scoped_guard(mutex, &drv->lock)
+ ret = sst_send_slot_map(drv);
if (ret)
return ret;
ret = sst_send_pipe_module_params(w, k);
@@ -1344,9 +1335,8 @@ int sst_send_pipe_gains(struct snd_soc_dai *dai, int stream, int mute)
dev_dbg(dai->dev, "send gains for widget=%s\n",
p->sink->name);
- mutex_lock(&drv->lock);
- sst_set_pipe_gain(ids, drv, mute);
- mutex_unlock(&drv->lock);
+ scoped_guard(mutex, &drv->lock)
+ sst_set_pipe_gain(ids, drv, mute);
}
}
} else {
@@ -1360,9 +1350,8 @@ int sst_send_pipe_gains(struct snd_soc_dai *dai, int stream, int mute)
dev_dbg(dai->dev, "send gain for widget=%s\n",
p->source->name);
- mutex_lock(&drv->lock);
- sst_set_pipe_gain(ids, drv, mute);
- mutex_unlock(&drv->lock);
+ scoped_guard(mutex, &drv->lock)
+ sst_set_pipe_gain(ids, drv, mute);
}
}
}
--
2.43.0
next prev parent reply other threads:[~2026-06-11 12:00 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-11 11:58 [PATCH 00/20] ASoC: Intel: Use guard() for mutex & spin locks phucduc.bui
2026-06-11 11:58 ` [PATCH 01/20] ASoC: Intel: catpt: ipc: " phucduc.bui
2026-06-11 18:44 ` Cezary Rojewski
2026-06-11 11:58 ` [PATCH 02/20] ASoC: Intel: catpt: dsp: Use guard() for mutex locks phucduc.bui
2026-06-11 18:39 ` Cezary Rojewski
2026-06-11 11:58 ` [PATCH 03/20] ASoC: Intel: avs: utils: " phucduc.bui
2026-06-11 11:58 ` [PATCH 04/20] ASoC: Intel: avs: probes: Use guard() for spin locks phucduc.bui
2026-06-11 19:34 ` Cezary Rojewski
2026-06-11 11:58 ` [PATCH 05/20] ASoC: Intel: avs: pcm: Use guard() for mutex & " phucduc.bui
2026-06-11 11:58 ` [PATCH 06/20] ASoC: Intel: avs: path: " phucduc.bui
2026-06-11 11:58 ` [PATCH 07/20] ASoC: Intel: avs: loader: Use guard() for mutex locks phucduc.bui
2026-06-11 11:58 ` [PATCH 08/20] ASoC: Intel: avs: ipc: Use guard() for mutex & spin locks phucduc.bui
2026-06-11 11:58 ` [PATCH 09/20] ASoC: Intel: avs: icl: Use guard() for " phucduc.bui
2026-06-11 11:58 ` [PATCH 10/20] ASoC: Intel: avs: debugfs: " phucduc.bui
2026-06-11 11:58 ` [PATCH 11/20] ASoC: Intel: avs: debug: " phucduc.bui
2026-06-11 11:58 ` [PATCH 12/20] ASoC: Intel: avs: core: Use guard() for mutex & " phucduc.bui
2026-06-11 11:58 ` [PATCH 13/20] ASoC: Intel: avs: control: Use guard() for " phucduc.bui
2026-06-11 11:58 ` [PATCH 14/20] ASoC: Intel: avs: apl: " phucduc.bui
2026-06-11 11:58 ` [PATCH 15/20] ASoC: Intel: atom: sst_stream: Use guard() for mutex locks phucduc.bui
2026-06-11 11:58 ` [PATCH 16/20] ASoC: Intel: atom: sst_pvt: Use guard() for mutex & spin locks phucduc.bui
2026-06-11 11:58 ` [PATCH 17/20] ASoC: Intel: atom: sst: Use guard() for " phucduc.bui
2026-06-11 11:58 ` phucduc.bui [this message]
2026-06-11 11:59 ` [PATCH 19/20] ASoC: Intel: atom: sst-mfld-platform-pcm: Use guard() for mutex & " phucduc.bui
2026-06-11 11:59 ` [PATCH 20/20] ASoC: Intel: atom: sst_ipc: Use guard() for " phucduc.bui
2026-06-11 19:04 ` [PATCH 00/20] ASoC: Intel: Use guard() for mutex & " Cezary Rojewski
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=20260611115901.80438-19-phucduc.bui@gmail.com \
--to=phucduc.bui@gmail.com \
--cc=broonie@kernel.org \
--cc=cezary.rojewski@intel.com \
--cc=kai.vehmanen@linux.intel.com \
--cc=liam.r.girdwood@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-sound@vger.kernel.org \
--cc=perex@perex.cz \
--cc=peter.ujfalusi@linux.intel.com \
--cc=pierre-louis.bossart@linux.dev \
--cc=tiwai@suse.com \
--cc=yung-chuan.liao@linux.intel.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