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 19/20] ASoC: Intel: atom: sst-mfld-platform-pcm: Use guard() for mutex & spin locks
Date: Thu, 11 Jun 2026 18:59:00 +0700 [thread overview]
Message-ID: <20260611115901.80438-20-phucduc.bui@gmail.com> (raw)
In-Reply-To: <20260611115901.80438-1-phucduc.bui@gmail.com>
From: bui duc phuc <phucduc.bui@gmail.com>
Convert mutex and spinlock protected sections to guard()/scoped_guard()
helpers and simplify the cleanup paths. Also use __free(kfree) for the
temporary stream pointer in sst_media_open().
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-mfld-platform-pcm.c | 51 ++++++++------------
1 file changed, 19 insertions(+), 32 deletions(-)
diff --git a/sound/soc/intel/atom/sst-mfld-platform-pcm.c b/sound/soc/intel/atom/sst-mfld-platform-pcm.c
index f074af2499c8..f9df5694f049 100644
--- a/sound/soc/intel/atom/sst-mfld-platform-pcm.c
+++ b/sound/soc/intel/atom/sst-mfld-platform-pcm.c
@@ -32,16 +32,15 @@ int sst_register_dsp(struct sst_device *dev)
return -EINVAL;
if (!try_module_get(dev->dev->driver->owner))
return -ENODEV;
- mutex_lock(&sst_lock);
+ guard(mutex)(&sst_lock);
if (sst) {
dev_err(dev->dev, "we already have a device %s\n", sst->name);
module_put(dev->dev->driver->owner);
- mutex_unlock(&sst_lock);
return -EEXIST;
}
dev_dbg(dev->dev, "registering device %s\n", dev->name);
sst = dev;
- mutex_unlock(&sst_lock);
+
return 0;
}
EXPORT_SYMBOL_GPL(sst_register_dsp);
@@ -53,17 +52,15 @@ int sst_unregister_dsp(struct sst_device *dev)
if (dev != sst)
return -EINVAL;
- mutex_lock(&sst_lock);
+ guard(mutex)(&sst_lock);
- if (!sst) {
- mutex_unlock(&sst_lock);
+ if (!sst)
return -EIO;
- }
module_put(sst->dev->driver->owner);
dev_dbg(dev->dev, "unreg %s\n", sst->name);
sst = NULL;
- mutex_unlock(&sst_lock);
+
return 0;
}
EXPORT_SYMBOL_GPL(sst_unregister_dsp);
@@ -103,21 +100,15 @@ static int sst_media_digital_mute(struct snd_soc_dai *dai, int mute, int stream)
void sst_set_stream_status(struct sst_runtime_stream *stream,
int state)
{
- unsigned long flags;
- spin_lock_irqsave(&stream->status_lock, flags);
+ guard(spinlock_irqsave)(&stream->status_lock);
stream->stream_status = state;
- spin_unlock_irqrestore(&stream->status_lock, flags);
}
static inline int sst_get_stream_status(struct sst_runtime_stream *stream)
{
- int state;
- unsigned long flags;
+ guard(spinlock_irqsave)(&stream->status_lock);
- spin_lock_irqsave(&stream->status_lock, flags);
- state = stream->stream_status;
- spin_unlock_irqrestore(&stream->status_lock, flags);
- return state;
+ return stream->stream_status;
}
static void sst_fill_alloc_params(struct snd_pcm_substream *substream,
@@ -304,7 +295,7 @@ static int sst_media_open(struct snd_pcm_substream *substream,
{
int ret_val = 0;
struct snd_pcm_runtime *runtime = substream->runtime;
- struct sst_runtime_stream *stream;
+ struct sst_runtime_stream *stream __free(kfree) = NULL;
stream = kzalloc_obj(*stream);
if (!stream)
@@ -312,15 +303,14 @@ static int sst_media_open(struct snd_pcm_substream *substream,
spin_lock_init(&stream->status_lock);
/* get the sst ops */
- mutex_lock(&sst_lock);
- if (!sst ||
- !try_module_get(sst->dev->driver->owner)) {
- dev_err(dai->dev, "no device available to run\n");
- ret_val = -ENODEV;
- goto out_ops;
+ scoped_guard(mutex, &sst_lock) {
+ if (!sst ||
+ !try_module_get(sst->dev->driver->owner)) {
+ dev_err(dai->dev, "no device available to run\n");
+ return -ENODEV;
+ }
+ stream->ops = sst->ops;
}
- stream->ops = sst->ops;
- mutex_unlock(&sst_lock);
stream->stream_info.str_id = 0;
@@ -330,7 +320,7 @@ static int sst_media_open(struct snd_pcm_substream *substream,
ret_val = power_up_sst(stream);
if (ret_val < 0)
- goto out_power_up;
+ return ret_val;
/*
* Make sure the period to be multiple of 1ms to align the
@@ -347,13 +337,10 @@ static int sst_media_open(struct snd_pcm_substream *substream,
snd_pcm_hw_constraint_step(substream->runtime, 0,
SNDRV_PCM_HW_PARAM_PERIODS, 2);
+ stream = NULL;
+
return snd_pcm_hw_constraint_integer(runtime,
SNDRV_PCM_HW_PARAM_PERIODS);
-out_ops:
- mutex_unlock(&sst_lock);
-out_power_up:
- kfree(stream);
- return ret_val;
}
static void sst_media_close(struct snd_pcm_substream *substream,
--
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 ` [PATCH 18/20] ASoC: Intel: atom: sst-atom-controls: Use guard() for mutex locks phucduc.bui
2026-06-11 11:59 ` phucduc.bui [this message]
2026-06-11 11:59 ` [PATCH 20/20] ASoC: Intel: atom: sst_ipc: Use guard() for spin locks 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-20-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