From: Takashi Iwai <tiwai@suse.de>
To: linux-sound@vger.kernel.org
Cc: Takashi Sakamoto <o-takashi@sakamocchi.jp>,
Clemens Ladisch <clemens@ladisch.de>
Subject: [PATCH 03/19] ALSA: firewire: Use guard() for mutex locks
Date: Wed, 27 Aug 2025 11:19:57 +0200 [thread overview]
Message-ID: <20250827092017.29014-4-tiwai@suse.de> (raw)
In-Reply-To: <20250827092017.29014-1-tiwai@suse.de>
Replace the manual mutex lock/unlock pairs with guard() for code
simplification.
Only code refactoring, and no behavior change.
Signed-off-by: Takashi Iwai <tiwai@suse.de>
---
sound/firewire/digi00x/digi00x-midi.c | 24 ++++-----
sound/firewire/digi00x/digi00x-pcm.c | 72 +++++++++++----------------
sound/firewire/digi00x/digi00x.c | 3 +-
3 files changed, 42 insertions(+), 57 deletions(-)
diff --git a/sound/firewire/digi00x/digi00x-midi.c b/sound/firewire/digi00x/digi00x-midi.c
index 8f4bace16050..0f6ca58cc4a0 100644
--- a/sound/firewire/digi00x/digi00x-midi.c
+++ b/sound/firewire/digi00x/digi00x-midi.c
@@ -16,15 +16,15 @@ static int midi_open(struct snd_rawmidi_substream *substream)
if (err < 0)
return err;
- mutex_lock(&dg00x->mutex);
- err = snd_dg00x_stream_reserve_duplex(dg00x, 0, 0, 0);
- if (err >= 0) {
- ++dg00x->substreams_counter;
- err = snd_dg00x_stream_start_duplex(dg00x);
- if (err < 0)
- --dg00x->substreams_counter;
+ scoped_guard(mutex, &dg00x->mutex) {
+ err = snd_dg00x_stream_reserve_duplex(dg00x, 0, 0, 0);
+ if (err >= 0) {
+ ++dg00x->substreams_counter;
+ err = snd_dg00x_stream_start_duplex(dg00x);
+ if (err < 0)
+ --dg00x->substreams_counter;
+ }
}
- mutex_unlock(&dg00x->mutex);
if (err < 0)
snd_dg00x_stream_lock_release(dg00x);
@@ -35,10 +35,10 @@ static int midi_close(struct snd_rawmidi_substream *substream)
{
struct snd_dg00x *dg00x = substream->rmidi->private_data;
- mutex_lock(&dg00x->mutex);
- --dg00x->substreams_counter;
- snd_dg00x_stream_stop_duplex(dg00x);
- mutex_unlock(&dg00x->mutex);
+ scoped_guard(mutex, &dg00x->mutex) {
+ --dg00x->substreams_counter;
+ snd_dg00x_stream_stop_duplex(dg00x);
+ }
snd_dg00x_stream_lock_release(dg00x);
return 0;
diff --git a/sound/firewire/digi00x/digi00x-pcm.c b/sound/firewire/digi00x/digi00x-pcm.c
index 85e65cbc00c4..ee650f039a75 100644
--- a/sound/firewire/digi00x/digi00x-pcm.c
+++ b/sound/firewire/digi00x/digi00x-pcm.c
@@ -127,46 +127,39 @@ static int pcm_open(struct snd_pcm_substream *substream)
}
}
- mutex_lock(&dg00x->mutex);
+ scoped_guard(mutex, &dg00x->mutex) {
- // When source of clock is not internal or any stream is reserved for
- // transmission of PCM frames, the available sampling rate is limited
- // at current one.
- if ((clock != SND_DG00X_CLOCK_INTERNAL) ||
- (dg00x->substreams_counter > 0 && d->events_per_period > 0)) {
- unsigned int frames_per_period = d->events_per_period;
- unsigned int frames_per_buffer = d->events_per_buffer;
- unsigned int rate;
+ // When source of clock is not internal or any stream is reserved for
+ // transmission of PCM frames, the available sampling rate is limited
+ // at current one.
+ if ((clock != SND_DG00X_CLOCK_INTERNAL) ||
+ (dg00x->substreams_counter > 0 && d->events_per_period > 0)) {
+ unsigned int frames_per_period = d->events_per_period;
+ unsigned int frames_per_buffer = d->events_per_buffer;
+ unsigned int rate;
- err = snd_dg00x_stream_get_external_rate(dg00x, &rate);
- if (err < 0) {
- mutex_unlock(&dg00x->mutex);
- goto err_locked;
- }
- substream->runtime->hw.rate_min = rate;
- substream->runtime->hw.rate_max = rate;
-
- if (frames_per_period > 0) {
- err = snd_pcm_hw_constraint_minmax(substream->runtime,
- SNDRV_PCM_HW_PARAM_PERIOD_SIZE,
- frames_per_period, frames_per_period);
- if (err < 0) {
- mutex_unlock(&dg00x->mutex);
+ err = snd_dg00x_stream_get_external_rate(dg00x, &rate);
+ if (err < 0)
goto err_locked;
- }
+ substream->runtime->hw.rate_min = rate;
+ substream->runtime->hw.rate_max = rate;
- err = snd_pcm_hw_constraint_minmax(substream->runtime,
- SNDRV_PCM_HW_PARAM_BUFFER_SIZE,
- frames_per_buffer, frames_per_buffer);
- if (err < 0) {
- mutex_unlock(&dg00x->mutex);
- goto err_locked;
+ if (frames_per_period > 0) {
+ err = snd_pcm_hw_constraint_minmax(substream->runtime,
+ SNDRV_PCM_HW_PARAM_PERIOD_SIZE,
+ frames_per_period, frames_per_period);
+ if (err < 0)
+ goto err_locked;
+
+ err = snd_pcm_hw_constraint_minmax(substream->runtime,
+ SNDRV_PCM_HW_PARAM_BUFFER_SIZE,
+ frames_per_buffer, frames_per_buffer);
+ if (err < 0)
+ goto err_locked;
}
}
}
- mutex_unlock(&dg00x->mutex);
-
snd_pcm_set_sync(substream);
return 0;
@@ -195,12 +188,11 @@ static int pcm_hw_params(struct snd_pcm_substream *substream,
unsigned int frames_per_period = params_period_size(hw_params);
unsigned int frames_per_buffer = params_buffer_size(hw_params);
- mutex_lock(&dg00x->mutex);
+ guard(mutex)(&dg00x->mutex);
err = snd_dg00x_stream_reserve_duplex(dg00x, rate,
frames_per_period, frames_per_buffer);
if (err >= 0)
++dg00x->substreams_counter;
- mutex_unlock(&dg00x->mutex);
}
return err;
@@ -210,15 +202,13 @@ static int pcm_hw_free(struct snd_pcm_substream *substream)
{
struct snd_dg00x *dg00x = substream->private_data;
- mutex_lock(&dg00x->mutex);
+ guard(mutex)(&dg00x->mutex);
if (substream->runtime->state != SNDRV_PCM_STATE_OPEN)
--dg00x->substreams_counter;
snd_dg00x_stream_stop_duplex(dg00x);
- mutex_unlock(&dg00x->mutex);
-
return 0;
}
@@ -227,14 +217,12 @@ static int pcm_capture_prepare(struct snd_pcm_substream *substream)
struct snd_dg00x *dg00x = substream->private_data;
int err;
- mutex_lock(&dg00x->mutex);
+ guard(mutex)(&dg00x->mutex);
err = snd_dg00x_stream_start_duplex(dg00x);
if (err >= 0)
amdtp_stream_pcm_prepare(&dg00x->tx_stream);
- mutex_unlock(&dg00x->mutex);
-
return err;
}
@@ -243,7 +231,7 @@ static int pcm_playback_prepare(struct snd_pcm_substream *substream)
struct snd_dg00x *dg00x = substream->private_data;
int err;
- mutex_lock(&dg00x->mutex);
+ guard(mutex)(&dg00x->mutex);
err = snd_dg00x_stream_start_duplex(dg00x);
if (err >= 0) {
@@ -251,8 +239,6 @@ static int pcm_playback_prepare(struct snd_pcm_substream *substream)
amdtp_dot_reset(&dg00x->rx_stream);
}
- mutex_unlock(&dg00x->mutex);
-
return err;
}
diff --git a/sound/firewire/digi00x/digi00x.c b/sound/firewire/digi00x/digi00x.c
index cebc35dcf8cd..f73a9fc8adb1 100644
--- a/sound/firewire/digi00x/digi00x.c
+++ b/sound/firewire/digi00x/digi00x.c
@@ -116,9 +116,8 @@ static void snd_dg00x_update(struct fw_unit *unit)
snd_dg00x_transaction_reregister(dg00x);
- mutex_lock(&dg00x->mutex);
+ guard(mutex)(&dg00x->mutex);
snd_dg00x_stream_update_duplex(dg00x);
- mutex_unlock(&dg00x->mutex);
}
static void snd_dg00x_remove(struct fw_unit *unit)
--
2.50.1
next prev parent reply other threads:[~2025-08-27 9:20 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-27 9:19 [PATCH 00/19] ALSA: firewire: Use auto-cleanup macros Takashi Iwai
2025-08-27 9:19 ` [PATCH 01/19] ALSA: firewire: bebob: Use guard() for mutex locks Takashi Iwai
2025-08-27 9:19 ` [PATCH 02/19] ALSA: firewire: dice: " Takashi Iwai
2025-08-27 9:19 ` Takashi Iwai [this message]
2025-08-27 9:19 ` [PATCH 04/19] ALSA: firewire: fireworks: " Takashi Iwai
2025-08-27 9:19 ` [PATCH 05/19] ALSA: firewire: motu: " Takashi Iwai
2025-08-27 9:20 ` [PATCH 06/19] ALSA: firewire: oxfw: " Takashi Iwai
2025-08-27 9:20 ` [PATCH 07/19] ALSA: firewire: tascam: " Takashi Iwai
2025-08-27 9:20 ` [PATCH 08/19] ALSA: firewire: fireface: " Takashi Iwai
2025-08-27 9:20 ` [PATCH 09/19] ALSA: firewire: isight: " Takashi Iwai
2025-08-27 9:20 ` [PATCH 10/19] ALSA: firewire: lib: " Takashi Iwai
2025-08-27 9:20 ` [PATCH 11/19] ALSA: firewire: bebob: Use guard() for spin locks Takashi Iwai
2025-08-27 9:20 ` [PATCH 12/19] ALSA: firewire: dice: " Takashi Iwai
2025-08-27 9:20 ` [PATCH 13/19] ALSA: firewire: digi00x: " Takashi Iwai
2025-08-27 9:20 ` [PATCH 14/19] ALSA: firewire: fireface: " Takashi Iwai
2025-08-27 9:20 ` [PATCH 15/19] ALSA: firewire: fireworks: " Takashi Iwai
2025-08-27 9:20 ` [PATCH 16/19] ALSA: firewire: motu: " Takashi Iwai
2025-08-27 9:20 ` [PATCH 17/19] ALSA: firewire: oxfw: " Takashi Iwai
2025-08-27 9:20 ` [PATCH 18/19] ALSA: firewire: tascam: " Takashi Iwai
2025-08-27 9:20 ` [PATCH 19/19] ALSA: firewire: lib: " Takashi Iwai
2025-08-28 12:56 ` [PATCH 00/19] ALSA: firewire: Use auto-cleanup macros Takashi Sakamoto
2025-08-28 13:23 ` 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=20250827092017.29014-4-tiwai@suse.de \
--to=tiwai@suse.de \
--cc=clemens@ladisch.de \
--cc=linux-sound@vger.kernel.org \
--cc=o-takashi@sakamocchi.jp \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.