From: Takashi Iwai <tiwai@suse.de>
To: linux-sound@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
Subject: [PATCH 3/5] ALSA: aloop: Avoid a bad mixure of guard() and goto
Date: Tue, 6 Oct 2026 19:39:55 +0200 [thread overview]
Message-ID: <20261006174002.703431-4-tiwai@suse.de> (raw)
In-Reply-To: <20261006174002.703431-1-tiwai@suse.de>
The rewrite of aloop driver code using guard() leaded to a mixture of
guard() and some goto; although it currently works, it isn't really a
good match.
For avoiding the bad match, rewrite with scoped_guard(), so that we
can replace goto with break gracefully.
Fixes: ebd9b6c91d4e ("ALSA: aloop: Use guard() for mutex locks")
Reported-by: Sashiko <sashiko-bot@kernel.org>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
---
sound/drivers/aloop.c | 154 +++++++++++++++++++++---------------------
1 file changed, 77 insertions(+), 77 deletions(-)
diff --git a/sound/drivers/aloop.c b/sound/drivers/aloop.c
index 5f0e2dc96769..f9659f436bfc 100644
--- a/sound/drivers/aloop.c
+++ b/sound/drivers/aloop.c
@@ -1384,94 +1384,94 @@ static int loopback_open(struct snd_pcm_substream *substream)
int err = 0;
int dev = get_cable_index(substream);
- guard(mutex)(&loopback->cable_lock);
- dpcm = kzalloc_obj(*dpcm);
- if (!dpcm)
- return -ENOMEM;
- dpcm->loopback = loopback;
- dpcm->substream = substream;
+ scoped_guard(mutex, &loopback->cable_lock) {
+ dpcm = kzalloc_obj(*dpcm);
+ if (!dpcm)
+ return -ENOMEM;
+ dpcm->loopback = loopback;
+ dpcm->substream = substream;
- cable = loopback->cables[substream->number][dev];
- if (!cable) {
- cable = kzalloc_obj(*cable);
+ cable = loopback->cables[substream->number][dev];
if (!cable) {
- err = -ENOMEM;
- goto unlock;
- }
- spin_lock_init(&cable->lock);
- snd_refcount_init(&cable->stop_count);
- cable->hw = loopback_pcm_hardware;
+ cable = kzalloc_obj(*cable);
+ if (!cable) {
+ err = -ENOMEM;
+ break;
+ }
+ spin_lock_init(&cable->lock);
+ snd_refcount_init(&cable->stop_count);
+ cable->hw = loopback_pcm_hardware;
#ifdef CONFIG_HIGH_RES_TIMERS
- if (loopback->timer_source && !strcmp(loopback->timer_source, "hrtimer"))
- cable->ops = &loopback_hrtimer_ops;
- else
+ if (loopback->timer_source && !strcmp(loopback->timer_source, "hrtimer"))
+ cable->ops = &loopback_hrtimer_ops;
+ else
#endif
- if (loopback->timer_source && loopback->timer_source[0])
- cable->ops = &loopback_snd_timer_ops;
- else
- cable->ops = &loopback_jiffies_timer_ops;
- loopback->cables[substream->number][dev] = cable;
- }
- dpcm->cable = cable;
- runtime->private_data = dpcm;
+ if (loopback->timer_source && loopback->timer_source[0])
+ cable->ops = &loopback_snd_timer_ops;
+ else
+ cable->ops = &loopback_jiffies_timer_ops;
+ loopback->cables[substream->number][dev] = cable;
+ }
+ dpcm->cable = cable;
+ runtime->private_data = dpcm;
- if (cable->ops->open) {
- err = cable->ops->open(dpcm);
- if (err < 0)
- goto unlock;
- }
+ if (cable->ops->open) {
+ err = cable->ops->open(dpcm);
+ if (err < 0)
+ break;
+ }
- snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIODS);
+ snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIODS);
- /* use dynamic rules based on actual runtime->hw values */
- /* note that the default rules created in the PCM midlevel code */
- /* are cached -> they do not reflect the actual state */
- err = snd_pcm_hw_rule_add(runtime, 0,
- SNDRV_PCM_HW_PARAM_FORMAT,
- rule_format, dpcm,
- SNDRV_PCM_HW_PARAM_FORMAT, -1);
- if (err < 0)
- goto unlock;
- err = snd_pcm_hw_rule_add(runtime, 0,
- SNDRV_PCM_HW_PARAM_RATE,
- rule_rate, dpcm,
- SNDRV_PCM_HW_PARAM_RATE, -1);
- if (err < 0)
- goto unlock;
- err = snd_pcm_hw_rule_add(runtime, 0,
- SNDRV_PCM_HW_PARAM_CHANNELS,
- rule_channels, dpcm,
- SNDRV_PCM_HW_PARAM_CHANNELS, -1);
- if (err < 0)
- goto unlock;
-
- /* In case of sound timer the period time of both devices of the same
- * loop has to be the same.
- * This rule only takes effect if a sound timer was chosen
- */
- if (cable->snd_timer.instance) {
+ /* use dynamic rules based on actual runtime->hw values */
+ /* note that the default rules created in the PCM midlevel code */
+ /* are cached -> they do not reflect the actual state */
err = snd_pcm_hw_rule_add(runtime, 0,
- SNDRV_PCM_HW_PARAM_PERIOD_BYTES,
- rule_period_bytes, dpcm,
- SNDRV_PCM_HW_PARAM_PERIOD_BYTES, -1);
+ SNDRV_PCM_HW_PARAM_FORMAT,
+ rule_format, dpcm,
+ SNDRV_PCM_HW_PARAM_FORMAT, -1);
if (err < 0)
- goto unlock;
+ break;
+ err = snd_pcm_hw_rule_add(runtime, 0,
+ SNDRV_PCM_HW_PARAM_RATE,
+ rule_rate, dpcm,
+ SNDRV_PCM_HW_PARAM_RATE, -1);
+ if (err < 0)
+ break;
+ err = snd_pcm_hw_rule_add(runtime, 0,
+ SNDRV_PCM_HW_PARAM_CHANNELS,
+ rule_channels, dpcm,
+ SNDRV_PCM_HW_PARAM_CHANNELS, -1);
+ if (err < 0)
+ break;
+
+ /* In case of sound timer the period time of both devices of the same
+ * loop has to be the same.
+ * This rule only takes effect if a sound timer was chosen
+ */
+ if (cable->snd_timer.instance) {
+ err = snd_pcm_hw_rule_add(runtime, 0,
+ SNDRV_PCM_HW_PARAM_PERIOD_BYTES,
+ rule_period_bytes, dpcm,
+ SNDRV_PCM_HW_PARAM_PERIOD_BYTES, -1);
+ if (err < 0)
+ break;
+ }
+
+ /* loopback_runtime_free() has not to be called if kfree(dpcm) was
+ * already called here. Otherwise it will end up with a double free.
+ */
+ runtime->private_free = loopback_runtime_free;
+ if (get_notify(dpcm))
+ runtime->hw = loopback_pcm_hardware;
+ else
+ runtime->hw = cable->hw;
+
+ scoped_guard(spinlock_irq, &cable->lock) {
+ cable->streams[substream->stream] = dpcm;
+ }
}
- /* loopback_runtime_free() has not to be called if kfree(dpcm) was
- * already called here. Otherwise it will end up with a double free.
- */
- runtime->private_free = loopback_runtime_free;
- if (get_notify(dpcm))
- runtime->hw = loopback_pcm_hardware;
- else
- runtime->hw = cable->hw;
-
- scoped_guard(spinlock_irq, &cable->lock) {
- cable->streams[substream->stream] = dpcm;
- }
-
- unlock:
if (err < 0) {
free_cable(substream);
kfree(dpcm);
--
2.55.0
next prev parent reply other threads:[~2026-10-06 17:40 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-06 17:39 [PATCH 0/5] ALSA: Fix yet more bugs reported by Sashiko Takashi Iwai
2026-10-06 17:39 ` [PATCH 1/5] ALSA: seq: Fix missing direction and ump_group handling in 32bit compat ioctl Takashi Iwai
2026-10-06 17:39 ` [PATCH 2/5] ALSA: pcmtest: Fix leak at probe error Takashi Iwai
2026-10-06 17:39 ` Takashi Iwai [this message]
2026-10-06 17:39 ` [PATCH 4/5] ALSA: core: Fix leaks at snd_card_init() error paths Takashi Iwai
2026-10-06 17:39 ` [PATCH 5/5] ALSA: seq: Don't lose partial read failure 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=20261006174002.703431-4-tiwai@suse.de \
--to=tiwai@suse.de \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-sound@vger.kernel.org \
/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
all inboxes | Powered by JetHome®