* [PATCH 00/19] ALSA: firewire: Use auto-cleanup macros
@ 2025-08-27 9:19 Takashi Iwai
2025-08-27 9:19 ` [PATCH 01/19] ALSA: firewire: bebob: Use guard() for mutex locks Takashi Iwai
` (19 more replies)
0 siblings, 20 replies; 22+ messages in thread
From: Takashi Iwai @ 2025-08-27 9:19 UTC (permalink / raw)
To: linux-sound; +Cc: Takashi Sakamoto, Clemens Ladisch
This is another patch set for cleaning up the code with the recent
auto-cleanup macros like guard() & co, applied to FireWire sound
drivers.
Only code refactoring, and no behavior changes intended.
Takashi
===
Takashi Iwai (19):
ALSA: firewire: bebob: Use guard() for mutex locks
ALSA: firewire: dice: Use guard() for mutex locks
ALSA: firewire: Use guard() for mutex locks
ALSA: firewire: fireworks: Use guard() for mutex locks
ALSA: firewire: motu: Use guard() for mutex locks
ALSA: firewire: oxfw: Use guard() for mutex locks
ALSA: firewire: tascam: Use guard() for mutex locks
ALSA: firewire: fireface: Use guard() for mutex locks
ALSA: firewire: isight: Use guard() for mutex locks
ALSA: firewire: lib: Use guard() for mutex locks
ALSA: firewire: bebob: Use guard() for spin locks
ALSA: firewire: dice: Use guard() for spin locks
ALSA: firewire: digi00x: Use guard() for spin locks
ALSA: firewire: fireface: Use guard() for spin locks
ALSA: firewire: fireworks: Use guard() for spin locks
ALSA: firewire: motu: Use guard() for spin locks
ALSA: firewire: oxfw: Use guard() for spin locks
ALSA: firewire: tascam: Use guard() for spin locks
ALSA: firewire: lib: Use guard() for spin locks
sound/firewire/amdtp-stream.c | 28 ++----
sound/firewire/bebob/bebob.c | 36 ++++---
sound/firewire/bebob/bebob_hwdep.c | 37 ++------
sound/firewire/bebob/bebob_maudio.c | 42 +++------
sound/firewire/bebob/bebob_midi.c | 34 +++----
sound/firewire/bebob/bebob_pcm.c | 67 ++++++-------
sound/firewire/bebob/bebob_stream.c | 21 ++---
sound/firewire/cmp.c | 37 ++------
sound/firewire/dice/dice-hwdep.c | 37 ++------
sound/firewire/dice/dice-midi.c | 38 +++-----
sound/firewire/dice/dice-pcm.c | 90 ++++++++----------
sound/firewire/dice/dice-stream.c | 21 ++---
sound/firewire/dice/dice-transaction.c | 7 +-
sound/firewire/dice/dice.c | 3 +-
sound/firewire/digi00x/digi00x-hwdep.c | 37 ++------
sound/firewire/digi00x/digi00x-midi.c | 34 +++----
sound/firewire/digi00x/digi00x-pcm.c | 72 ++++++--------
sound/firewire/digi00x/digi00x-stream.c | 21 ++---
sound/firewire/digi00x/digi00x-transaction.c | 8 +-
sound/firewire/digi00x/digi00x.c | 3 +-
sound/firewire/fcp.c | 19 ++--
sound/firewire/fireface/ff-hwdep.c | 37 ++------
sound/firewire/fireface/ff-midi.c | 10 +-
sound/firewire/fireface/ff-pcm.c | 91 ++++++++----------
sound/firewire/fireface/ff-stream.c | 21 ++---
sound/firewire/fireface/ff-transaction.c | 4 +-
sound/firewire/fireworks/fireworks.c | 39 ++++----
sound/firewire/fireworks/fireworks_command.c | 16 ++--
sound/firewire/fireworks/fireworks_hwdep.c | 41 +++-----
sound/firewire/fireworks/fireworks_midi.c | 37 +++-----
sound/firewire/fireworks/fireworks_pcm.c | 64 ++++++-------
sound/firewire/fireworks/fireworks_stream.c | 21 ++---
.../fireworks/fireworks_transaction.c | 39 +++-----
sound/firewire/isight.c | 20 ++--
sound/firewire/iso-resources.c | 66 ++++++-------
.../motu/motu-command-dsp-message-parser.c | 9 +-
sound/firewire/motu/motu-hwdep.c | 30 ++----
sound/firewire/motu/motu-midi.c | 38 +++-----
sound/firewire/motu/motu-pcm.c | 93 +++++++++----------
.../motu/motu-register-dsp-message-parser.c | 18 +---
sound/firewire/motu/motu-stream.c | 21 ++---
sound/firewire/motu/motu-transaction.c | 7 +-
sound/firewire/oxfw/oxfw-hwdep.c | 37 ++------
sound/firewire/oxfw/oxfw-midi.c | 62 +++++--------
sound/firewire/oxfw/oxfw-pcm.c | 89 ++++++++----------
sound/firewire/oxfw/oxfw-stream.c | 21 ++---
sound/firewire/oxfw/oxfw.c | 3 +-
sound/firewire/tascam/amdtp-tascam.c | 15 ++-
sound/firewire/tascam/tascam-hwdep.c | 37 ++------
sound/firewire/tascam/tascam-midi.c | 10 +-
sound/firewire/tascam/tascam-pcm.c | 68 ++++++--------
sound/firewire/tascam/tascam-stream.c | 21 ++---
sound/firewire/tascam/tascam.c | 3 +-
53 files changed, 657 insertions(+), 1123 deletions(-)
--
2.50.1
^ permalink raw reply [flat|nested] 22+ messages in thread
* [PATCH 01/19] ALSA: firewire: bebob: Use guard() for mutex locks
2025-08-27 9:19 [PATCH 00/19] ALSA: firewire: Use auto-cleanup macros Takashi Iwai
@ 2025-08-27 9:19 ` Takashi Iwai
2025-08-27 9:19 ` [PATCH 02/19] ALSA: firewire: dice: " Takashi Iwai
` (18 subsequent siblings)
19 siblings, 0 replies; 22+ messages in thread
From: Takashi Iwai @ 2025-08-27 9:19 UTC (permalink / raw)
To: linux-sound; +Cc: Takashi Sakamoto, Clemens Ladisch
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/bebob/bebob.c | 36 +++++++---------
sound/firewire/bebob/bebob_maudio.c | 42 +++++++-----------
sound/firewire/bebob/bebob_midi.c | 24 +++++------
sound/firewire/bebob/bebob_pcm.c | 67 +++++++++++++----------------
4 files changed, 72 insertions(+), 97 deletions(-)
diff --git a/sound/firewire/bebob/bebob.c b/sound/firewire/bebob/bebob.c
index 4ebaeff16455..01e2c4cc03d4 100644
--- a/sound/firewire/bebob/bebob.c
+++ b/sound/firewire/bebob/bebob.c
@@ -122,9 +122,9 @@ bebob_card_free(struct snd_card *card)
{
struct snd_bebob *bebob = card->private_data;
- mutex_lock(&devices_mutex);
- clear_bit(bebob->card_index, devices_used);
- mutex_unlock(&devices_mutex);
+ scoped_guard(mutex, &devices_mutex) {
+ clear_bit(bebob->card_index, devices_used);
+ }
snd_bebob_stream_destroy_duplex(bebob);
@@ -207,25 +207,21 @@ static int bebob_probe(struct fw_unit *unit, const struct ieee1394_device_id *en
return -ENODEV;
}
- mutex_lock(&devices_mutex);
- for (card_index = 0; card_index < SNDRV_CARDS; card_index++) {
- if (!test_bit(card_index, devices_used) && enable[card_index])
- break;
- }
- if (card_index >= SNDRV_CARDS) {
- mutex_unlock(&devices_mutex);
- return -ENOENT;
- }
+ scoped_guard(mutex, &devices_mutex) {
+ for (card_index = 0; card_index < SNDRV_CARDS; card_index++) {
+ if (!test_bit(card_index, devices_used) && enable[card_index])
+ break;
+ }
+ if (card_index >= SNDRV_CARDS)
+ return -ENOENT;
- err = snd_card_new(&unit->device, index[card_index], id[card_index], THIS_MODULE,
- sizeof(*bebob), &card);
- if (err < 0) {
- mutex_unlock(&devices_mutex);
- return err;
+ err = snd_card_new(&unit->device, index[card_index], id[card_index], THIS_MODULE,
+ sizeof(*bebob), &card);
+ if (err < 0)
+ return err;
+ card->private_free = bebob_card_free;
+ set_bit(card_index, devices_used);
}
- card->private_free = bebob_card_free;
- set_bit(card_index, devices_used);
- mutex_unlock(&devices_mutex);
bebob = card->private_data;
bebob->unit = fw_unit_get(unit);
diff --git a/sound/firewire/bebob/bebob_maudio.c b/sound/firewire/bebob/bebob_maudio.c
index 177699e1be11..376a9a175479 100644
--- a/sound/firewire/bebob/bebob_maudio.c
+++ b/sound/firewire/bebob/bebob_maudio.c
@@ -265,7 +265,7 @@ snd_bebob_maudio_special_discover(struct snd_bebob *bebob, bool is1814)
if (!params)
return -ENOMEM;
- mutex_lock(&bebob->mutex);
+ guard(mutex)(&bebob->mutex);
bebob->maudio_special_quirk = (void *)params;
params->is1814 = is1814;
@@ -277,12 +277,12 @@ snd_bebob_maudio_special_discover(struct snd_bebob *bebob, bool is1814)
if (err < 0) {
dev_err(&bebob->unit->device,
"fail to initialize clock params: %d\n", err);
- goto end;
+ return err;
}
err = add_special_controls(bebob);
if (err < 0)
- goto end;
+ return err;
special_stream_formation_set(bebob);
@@ -293,8 +293,6 @@ snd_bebob_maudio_special_discover(struct snd_bebob *bebob, bool is1814)
bebob->midi_input_ports = 2;
bebob->midi_output_ports = 2;
}
-end:
- mutex_unlock(&bebob->mutex);
return err;
}
@@ -383,14 +381,12 @@ static int special_clk_ctl_put(struct snd_kcontrol *kctl,
if (id >= ARRAY_SIZE(special_clk_types))
return -EINVAL;
- mutex_lock(&bebob->mutex);
+ guard(mutex)(&bebob->mutex);
err = avc_maudio_set_special_clk(bebob, id,
params->dig_in_fmt,
params->dig_out_fmt,
params->clk_lock);
- mutex_unlock(&bebob->mutex);
-
if (err >= 0)
err = 1;
@@ -456,14 +452,14 @@ static int special_dig_in_iface_ctl_get(struct snd_kcontrol *kctl,
unsigned int dig_in_iface;
int err, val;
- mutex_lock(&bebob->mutex);
+ guard(mutex)(&bebob->mutex);
err = avc_audio_get_selector(bebob->unit, 0x00, 0x04,
&dig_in_iface);
if (err < 0) {
dev_err(&bebob->unit->device,
"fail to get digital input interface: %d\n", err);
- goto end;
+ return err;
}
/* encoded id for user value */
@@ -474,9 +470,7 @@ static int special_dig_in_iface_ctl_get(struct snd_kcontrol *kctl,
val = 2;
uval->value.enumerated.item[0] = val;
-end:
- mutex_unlock(&bebob->mutex);
- return err;
+ return 0;
}
static int special_dig_in_iface_ctl_set(struct snd_kcontrol *kctl,
struct snd_ctl_elem_value *uval)
@@ -494,7 +488,7 @@ static int special_dig_in_iface_ctl_set(struct snd_kcontrol *kctl,
dig_in_fmt = (id >> 1) & 0x01;
dig_in_iface = id & 0x01;
- mutex_lock(&bebob->mutex);
+ guard(mutex)(&bebob->mutex);
err = avc_maudio_set_special_clk(bebob,
params->clk_src,
@@ -502,24 +496,19 @@ static int special_dig_in_iface_ctl_set(struct snd_kcontrol *kctl,
params->dig_out_fmt,
params->clk_lock);
if (err < 0)
- goto end;
+ return err;
/* For ADAT, optical interface is only available. */
- if (params->dig_in_fmt > 0) {
- err = 1;
- goto end;
- }
+ if (params->dig_in_fmt > 0)
+ return 1;
/* For S/PDIF, optical/coaxial interfaces are selectable. */
err = avc_audio_set_selector(bebob->unit, 0x00, 0x04, dig_in_iface);
if (err < 0)
dev_err(&bebob->unit->device,
"fail to set digital input interface: %d\n", err);
- err = 1;
-end:
special_stream_formation_set(bebob);
- mutex_unlock(&bebob->mutex);
- return err;
+ return 1;
}
static const struct snd_kcontrol_new special_dig_in_iface_ctl = {
.name = "Digital Input Interface",
@@ -546,9 +535,9 @@ static int special_dig_out_iface_ctl_get(struct snd_kcontrol *kctl,
{
struct snd_bebob *bebob = snd_kcontrol_chip(kctl);
struct special_params *params = bebob->maudio_special_quirk;
- mutex_lock(&bebob->mutex);
+
+ guard(mutex)(&bebob->mutex);
uval->value.enumerated.item[0] = params->dig_out_fmt;
- mutex_unlock(&bebob->mutex);
return 0;
}
static int special_dig_out_iface_ctl_set(struct snd_kcontrol *kctl,
@@ -563,7 +552,7 @@ static int special_dig_out_iface_ctl_set(struct snd_kcontrol *kctl,
if (id >= ARRAY_SIZE(special_dig_out_iface_labels))
return -EINVAL;
- mutex_lock(&bebob->mutex);
+ guard(mutex)(&bebob->mutex);
err = avc_maudio_set_special_clk(bebob,
params->clk_src,
@@ -574,7 +563,6 @@ static int special_dig_out_iface_ctl_set(struct snd_kcontrol *kctl,
err = 1;
}
- mutex_unlock(&bebob->mutex);
return err;
}
static const struct snd_kcontrol_new special_dig_out_iface_ctl = {
diff --git a/sound/firewire/bebob/bebob_midi.c b/sound/firewire/bebob/bebob_midi.c
index b1425bf98c3b..5fd2d363de52 100644
--- a/sound/firewire/bebob/bebob_midi.c
+++ b/sound/firewire/bebob/bebob_midi.c
@@ -16,15 +16,15 @@ static int midi_open(struct snd_rawmidi_substream *substream)
if (err < 0)
return err;
- mutex_lock(&bebob->mutex);
- err = snd_bebob_stream_reserve_duplex(bebob, 0, 0, 0);
- if (err >= 0) {
- ++bebob->substreams_counter;
- err = snd_bebob_stream_start_duplex(bebob);
- if (err < 0)
- --bebob->substreams_counter;
+ scoped_guard(mutex, &bebob->mutex) {
+ err = snd_bebob_stream_reserve_duplex(bebob, 0, 0, 0);
+ if (err >= 0) {
+ ++bebob->substreams_counter;
+ err = snd_bebob_stream_start_duplex(bebob);
+ if (err < 0)
+ --bebob->substreams_counter;
+ }
}
- mutex_unlock(&bebob->mutex);
if (err < 0)
snd_bebob_stream_lock_release(bebob);
@@ -35,10 +35,10 @@ static int midi_close(struct snd_rawmidi_substream *substream)
{
struct snd_bebob *bebob = substream->rmidi->private_data;
- mutex_lock(&bebob->mutex);
- bebob->substreams_counter--;
- snd_bebob_stream_stop_duplex(bebob);
- mutex_unlock(&bebob->mutex);
+ scoped_guard(mutex, &bebob->mutex) {
+ bebob->substreams_counter--;
+ snd_bebob_stream_stop_duplex(bebob);
+ }
snd_bebob_stream_lock_release(bebob);
return 0;
diff --git a/sound/firewire/bebob/bebob_pcm.c b/sound/firewire/bebob/bebob_pcm.c
index 360ebf3c4ca2..573d3efb42cc 100644
--- a/sound/firewire/bebob/bebob_pcm.c
+++ b/sound/firewire/bebob/bebob_pcm.c
@@ -149,49 +149,43 @@ static int pcm_open(struct snd_pcm_substream *substream)
if (err < 0)
goto err_locked;
- mutex_lock(&bebob->mutex);
+ scoped_guard(mutex, &bebob->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 (src == SND_BEBOB_CLOCK_TYPE_EXTERNAL ||
- (bebob->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 sampling_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 (src == SND_BEBOB_CLOCK_TYPE_EXTERNAL ||
+ (bebob->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 sampling_rate;
- err = spec->get(bebob, &sampling_rate);
- if (err < 0) {
- mutex_unlock(&bebob->mutex);
- dev_err(&bebob->unit->device,
- "fail to get sampling rate: %d\n", err);
- goto err_locked;
- }
-
- substream->runtime->hw.rate_min = sampling_rate;
- substream->runtime->hw.rate_max = sampling_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);
+ err = spec->get(bebob, &sampling_rate);
if (err < 0) {
- mutex_unlock(&bebob->mutex);
+ dev_err(&bebob->unit->device,
+ "fail to get sampling rate: %d\n", err);
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) {
- mutex_unlock(&bebob->mutex);
- goto err_locked;
+ substream->runtime->hw.rate_min = sampling_rate;
+ substream->runtime->hw.rate_max = sampling_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)
+ 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(&bebob->mutex);
-
snd_pcm_set_sync(substream);
return 0;
@@ -219,12 +213,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(&bebob->mutex);
+ guard(mutex)(&bebob->mutex);
err = snd_bebob_stream_reserve_duplex(bebob, rate,
frames_per_period, frames_per_buffer);
if (err >= 0)
++bebob->substreams_counter;
- mutex_unlock(&bebob->mutex);
}
return err;
@@ -234,15 +227,13 @@ static int pcm_hw_free(struct snd_pcm_substream *substream)
{
struct snd_bebob *bebob = substream->private_data;
- mutex_lock(&bebob->mutex);
+ guard(mutex)(&bebob->mutex);
if (substream->runtime->state != SNDRV_PCM_STATE_OPEN)
bebob->substreams_counter--;
snd_bebob_stream_stop_duplex(bebob);
- mutex_unlock(&bebob->mutex);
-
return 0;
}
--
2.50.1
^ permalink raw reply related [flat|nested] 22+ messages in thread
* [PATCH 02/19] ALSA: firewire: dice: Use guard() for mutex locks
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 ` Takashi Iwai
2025-08-27 9:19 ` [PATCH 03/19] ALSA: firewire: " Takashi Iwai
` (17 subsequent siblings)
19 siblings, 0 replies; 22+ messages in thread
From: Takashi Iwai @ 2025-08-27 9:19 UTC (permalink / raw)
To: linux-sound; +Cc: Takashi Sakamoto, Clemens Ladisch
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/dice/dice-midi.c | 28 +++++-----
sound/firewire/dice/dice-pcm.c | 90 +++++++++++++++------------------
sound/firewire/dice/dice.c | 3 +-
3 files changed, 53 insertions(+), 68 deletions(-)
diff --git a/sound/firewire/dice/dice-midi.c b/sound/firewire/dice/dice-midi.c
index 78988e44b8bc..9ca975c556ca 100644
--- a/sound/firewire/dice/dice-midi.c
+++ b/sound/firewire/dice/dice-midi.c
@@ -15,18 +15,16 @@ static int midi_open(struct snd_rawmidi_substream *substream)
if (err < 0)
return err;
- mutex_lock(&dice->mutex);
-
- err = snd_dice_stream_reserve_duplex(dice, 0, 0, 0);
- if (err >= 0) {
- ++dice->substreams_counter;
- err = snd_dice_stream_start_duplex(dice);
- if (err < 0)
- --dice->substreams_counter;
+ scoped_guard(mutex, &dice->mutex) {
+ err = snd_dice_stream_reserve_duplex(dice, 0, 0, 0);
+ if (err >= 0) {
+ ++dice->substreams_counter;
+ err = snd_dice_stream_start_duplex(dice);
+ if (err < 0)
+ --dice->substreams_counter;
+ }
}
- mutex_unlock(&dice->mutex);
-
if (err < 0)
snd_dice_stream_lock_release(dice);
@@ -37,12 +35,10 @@ static int midi_close(struct snd_rawmidi_substream *substream)
{
struct snd_dice *dice = substream->rmidi->private_data;
- mutex_lock(&dice->mutex);
-
- --dice->substreams_counter;
- snd_dice_stream_stop_duplex(dice);
-
- mutex_unlock(&dice->mutex);
+ scoped_guard(mutex, &dice->mutex) {
+ --dice->substreams_counter;
+ snd_dice_stream_stop_duplex(dice);
+ }
snd_dice_stream_lock_release(dice);
return 0;
diff --git a/sound/firewire/dice/dice-pcm.c b/sound/firewire/dice/dice-pcm.c
index cfc19bd0d5dd..7411581dd663 100644
--- a/sound/firewire/dice/dice-pcm.c
+++ b/sound/firewire/dice/dice-pcm.c
@@ -196,53 +196,46 @@ static int pcm_open(struct snd_pcm_substream *substream)
break;
}
- mutex_lock(&dice->mutex);
+ scoped_guard(mutex, &dice->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 (!internal ||
- (dice->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 (!internal ||
+ (dice->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_dice_transaction_get_rate(dice, &rate);
- if (err < 0) {
- mutex_unlock(&dice->mutex);
- goto err_locked;
- }
-
- substream->runtime->hw.rate_min = rate;
- substream->runtime->hw.rate_max = rate;
-
- if (frames_per_period > 0) {
- // For double_pcm_frame quirk.
- if (rate > 96000 && !dice->disable_double_pcm_frames) {
- frames_per_period *= 2;
- frames_per_buffer *= 2;
- }
-
- 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(&dice->mutex);
+ err = snd_dice_transaction_get_rate(dice, &rate);
+ 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) {
- mutex_unlock(&dice->mutex);
- goto err_locked;
+ substream->runtime->hw.rate_min = rate;
+ substream->runtime->hw.rate_max = rate;
+
+ if (frames_per_period > 0) {
+ // For double_pcm_frame quirk.
+ if (rate > 96000 && !dice->disable_double_pcm_frames) {
+ frames_per_period *= 2;
+ frames_per_buffer *= 2;
+ }
+
+ 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(&dice->mutex);
-
snd_pcm_set_sync(substream);
return 0;
@@ -271,7 +264,7 @@ static int pcm_hw_params(struct snd_pcm_substream *substream,
unsigned int events_per_period = params_period_size(hw_params);
unsigned int events_per_buffer = params_buffer_size(hw_params);
- mutex_lock(&dice->mutex);
+ guard(mutex)(&dice->mutex);
// For double_pcm_frame quirk.
if (rate > 96000 && !dice->disable_double_pcm_frames) {
events_per_period /= 2;
@@ -281,7 +274,6 @@ static int pcm_hw_params(struct snd_pcm_substream *substream,
events_per_period, events_per_buffer);
if (err >= 0)
++dice->substreams_counter;
- mutex_unlock(&dice->mutex);
}
return err;
@@ -291,15 +283,13 @@ static int pcm_hw_free(struct snd_pcm_substream *substream)
{
struct snd_dice *dice = substream->private_data;
- mutex_lock(&dice->mutex);
+ guard(mutex)(&dice->mutex);
if (substream->runtime->state != SNDRV_PCM_STATE_OPEN)
--dice->substreams_counter;
snd_dice_stream_stop_duplex(dice);
- mutex_unlock(&dice->mutex);
-
return 0;
}
@@ -309,9 +299,9 @@ static int capture_prepare(struct snd_pcm_substream *substream)
struct amdtp_stream *stream = &dice->tx_stream[substream->pcm->device];
int err;
- mutex_lock(&dice->mutex);
- err = snd_dice_stream_start_duplex(dice);
- mutex_unlock(&dice->mutex);
+ scoped_guard(mutex, &dice->mutex) {
+ err = snd_dice_stream_start_duplex(dice);
+ }
if (err >= 0)
amdtp_stream_pcm_prepare(stream);
@@ -323,9 +313,9 @@ static int playback_prepare(struct snd_pcm_substream *substream)
struct amdtp_stream *stream = &dice->rx_stream[substream->pcm->device];
int err;
- mutex_lock(&dice->mutex);
- err = snd_dice_stream_start_duplex(dice);
- mutex_unlock(&dice->mutex);
+ scoped_guard(mutex, &dice->mutex) {
+ err = snd_dice_stream_start_duplex(dice);
+ }
if (err >= 0)
amdtp_stream_pcm_prepare(stream);
diff --git a/sound/firewire/dice/dice.c b/sound/firewire/dice/dice.c
index 9675ec14271d..bcbe80344328 100644
--- a/sound/firewire/dice/dice.c
+++ b/sound/firewire/dice/dice.c
@@ -238,9 +238,8 @@ static void dice_bus_reset(struct fw_unit *unit)
/* The handler address register becomes initialized. */
snd_dice_transaction_reinit(dice);
- mutex_lock(&dice->mutex);
+ guard(mutex)(&dice->mutex);
snd_dice_stream_update_duplex(dice);
- mutex_unlock(&dice->mutex);
}
#define DICE_INTERFACE 0x000001
--
2.50.1
^ permalink raw reply related [flat|nested] 22+ messages in thread
* [PATCH 03/19] ALSA: firewire: Use guard() for mutex locks
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
2025-08-27 9:19 ` [PATCH 04/19] ALSA: firewire: fireworks: " Takashi Iwai
` (16 subsequent siblings)
19 siblings, 0 replies; 22+ messages in thread
From: Takashi Iwai @ 2025-08-27 9:19 UTC (permalink / raw)
To: linux-sound; +Cc: Takashi Sakamoto, Clemens Ladisch
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
^ permalink raw reply related [flat|nested] 22+ messages in thread
* [PATCH 04/19] ALSA: firewire: fireworks: Use guard() for mutex locks
2025-08-27 9:19 [PATCH 00/19] ALSA: firewire: Use auto-cleanup macros Takashi Iwai
` (2 preceding siblings ...)
2025-08-27 9:19 ` [PATCH 03/19] ALSA: firewire: " Takashi Iwai
@ 2025-08-27 9:19 ` Takashi Iwai
2025-08-27 9:19 ` [PATCH 05/19] ALSA: firewire: motu: " Takashi Iwai
` (15 subsequent siblings)
19 siblings, 0 replies; 22+ messages in thread
From: Takashi Iwai @ 2025-08-27 9:19 UTC (permalink / raw)
To: linux-sound; +Cc: Takashi Sakamoto, Clemens Ladisch
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/fireworks/fireworks.c | 39 ++++++--------
sound/firewire/fireworks/fireworks_midi.c | 27 +++++-----
sound/firewire/fireworks/fireworks_pcm.c | 64 ++++++++++-------------
3 files changed, 57 insertions(+), 73 deletions(-)
diff --git a/sound/firewire/fireworks/fireworks.c b/sound/firewire/fireworks/fireworks.c
index 69f722244362..3378c7dce88a 100644
--- a/sound/firewire/fireworks/fireworks.c
+++ b/sound/firewire/fireworks/fireworks.c
@@ -188,9 +188,9 @@ efw_card_free(struct snd_card *card)
{
struct snd_efw *efw = card->private_data;
- mutex_lock(&devices_mutex);
- clear_bit(efw->card_index, devices_used);
- mutex_unlock(&devices_mutex);
+ scoped_guard(mutex, &devices_mutex) {
+ clear_bit(efw->card_index, devices_used);
+ }
snd_efw_stream_destroy_duplex(efw);
snd_efw_transaction_remove_instance(efw);
@@ -207,25 +207,21 @@ static int efw_probe(struct fw_unit *unit, const struct ieee1394_device_id *entr
int err;
// check registered cards.
- mutex_lock(&devices_mutex);
- for (card_index = 0; card_index < SNDRV_CARDS; ++card_index) {
- if (!test_bit(card_index, devices_used) && enable[card_index])
- break;
- }
- if (card_index >= SNDRV_CARDS) {
- mutex_unlock(&devices_mutex);
- return -ENOENT;
- }
+ scoped_guard(mutex, &devices_mutex) {
+ for (card_index = 0; card_index < SNDRV_CARDS; ++card_index) {
+ if (!test_bit(card_index, devices_used) && enable[card_index])
+ break;
+ }
+ if (card_index >= SNDRV_CARDS)
+ return -ENOENT;
- err = snd_card_new(&unit->device, index[card_index], id[card_index], THIS_MODULE,
- sizeof(*efw), &card);
- if (err < 0) {
- mutex_unlock(&devices_mutex);
- return err;
+ err = snd_card_new(&unit->device, index[card_index], id[card_index], THIS_MODULE,
+ sizeof(*efw), &card);
+ if (err < 0)
+ return err;
+ card->private_free = efw_card_free;
+ set_bit(card_index, devices_used);
}
- card->private_free = efw_card_free;
- set_bit(card_index, devices_used);
- mutex_unlock(&devices_mutex);
efw = card->private_data;
efw->unit = fw_unit_get(unit);
@@ -287,9 +283,8 @@ static void efw_update(struct fw_unit *unit)
snd_efw_transaction_bus_reset(efw->unit);
- mutex_lock(&efw->mutex);
+ guard(mutex)(&efw->mutex);
snd_efw_stream_update_duplex(efw);
- mutex_unlock(&efw->mutex);
}
static void efw_remove(struct fw_unit *unit)
diff --git a/sound/firewire/fireworks/fireworks_midi.c b/sound/firewire/fireworks/fireworks_midi.c
index 350bf4d299c2..90fe809a26c0 100644
--- a/sound/firewire/fireworks/fireworks_midi.c
+++ b/sound/firewire/fireworks/fireworks_midi.c
@@ -14,20 +14,19 @@ static int midi_open(struct snd_rawmidi_substream *substream)
err = snd_efw_stream_lock_try(efw);
if (err < 0)
- goto end;
+ return err;
- mutex_lock(&efw->mutex);
- err = snd_efw_stream_reserve_duplex(efw, 0, 0, 0);
- if (err >= 0) {
- ++efw->substreams_counter;
- err = snd_efw_stream_start_duplex(efw);
- if (err < 0)
- --efw->substreams_counter;
+ scoped_guard(mutex, &efw->mutex) {
+ err = snd_efw_stream_reserve_duplex(efw, 0, 0, 0);
+ if (err >= 0) {
+ ++efw->substreams_counter;
+ err = snd_efw_stream_start_duplex(efw);
+ if (err < 0)
+ --efw->substreams_counter;
+ }
}
- mutex_unlock(&efw->mutex);
if (err < 0)
snd_efw_stream_lock_release(efw);
-end:
return err;
}
@@ -35,10 +34,10 @@ static int midi_close(struct snd_rawmidi_substream *substream)
{
struct snd_efw *efw = substream->rmidi->private_data;
- mutex_lock(&efw->mutex);
- --efw->substreams_counter;
- snd_efw_stream_stop_duplex(efw);
- mutex_unlock(&efw->mutex);
+ scoped_guard(mutex, &efw->mutex) {
+ --efw->substreams_counter;
+ snd_efw_stream_stop_duplex(efw);
+ }
snd_efw_stream_lock_release(efw);
return 0;
diff --git a/sound/firewire/fireworks/fireworks_pcm.c b/sound/firewire/fireworks/fireworks_pcm.c
index eaf7778211de..e7b6425dc5c4 100644
--- a/sound/firewire/fireworks/fireworks_pcm.c
+++ b/sound/firewire/fireworks/fireworks_pcm.c
@@ -189,46 +189,39 @@ static int pcm_open(struct snd_pcm_substream *substream)
if (err < 0)
goto err_locked;
- mutex_lock(&efw->mutex);
+ scoped_guard(mutex, &efw->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_source != SND_EFW_CLOCK_SOURCE_INTERNAL) ||
- (efw->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 sampling_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_source != SND_EFW_CLOCK_SOURCE_INTERNAL) ||
+ (efw->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 sampling_rate;
- err = snd_efw_command_get_sampling_rate(efw, &sampling_rate);
- if (err < 0) {
- mutex_unlock(&efw->mutex);
- goto err_locked;
- }
- substream->runtime->hw.rate_min = sampling_rate;
- substream->runtime->hw.rate_max = sampling_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(&efw->mutex);
+ err = snd_efw_command_get_sampling_rate(efw, &sampling_rate);
+ if (err < 0)
goto err_locked;
- }
+ substream->runtime->hw.rate_min = sampling_rate;
+ substream->runtime->hw.rate_max = sampling_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(&efw->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(&efw->mutex);
-
snd_pcm_set_sync(substream);
return 0;
@@ -255,12 +248,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(&efw->mutex);
+ guard(mutex)(&efw->mutex);
err = snd_efw_stream_reserve_duplex(efw, rate,
frames_per_period, frames_per_buffer);
if (err >= 0)
++efw->substreams_counter;
- mutex_unlock(&efw->mutex);
}
return err;
@@ -270,15 +262,13 @@ static int pcm_hw_free(struct snd_pcm_substream *substream)
{
struct snd_efw *efw = substream->private_data;
- mutex_lock(&efw->mutex);
+ guard(mutex)(&efw->mutex);
if (substream->runtime->state != SNDRV_PCM_STATE_OPEN)
--efw->substreams_counter;
snd_efw_stream_stop_duplex(efw);
- mutex_unlock(&efw->mutex);
-
return 0;
}
--
2.50.1
^ permalink raw reply related [flat|nested] 22+ messages in thread
* [PATCH 05/19] ALSA: firewire: motu: Use guard() for mutex locks
2025-08-27 9:19 [PATCH 00/19] ALSA: firewire: Use auto-cleanup macros Takashi Iwai
` (3 preceding siblings ...)
2025-08-27 9:19 ` [PATCH 04/19] ALSA: firewire: fireworks: " Takashi Iwai
@ 2025-08-27 9:19 ` Takashi Iwai
2025-08-27 9:20 ` [PATCH 06/19] ALSA: firewire: oxfw: " Takashi Iwai
` (14 subsequent siblings)
19 siblings, 0 replies; 22+ messages in thread
From: Takashi Iwai @ 2025-08-27 9:19 UTC (permalink / raw)
To: linux-sound; +Cc: Takashi Sakamoto, Clemens Ladisch
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/motu/motu-midi.c | 28 +++++-----
sound/firewire/motu/motu-pcm.c | 93 ++++++++++++++++-----------------
2 files changed, 56 insertions(+), 65 deletions(-)
diff --git a/sound/firewire/motu/motu-midi.c b/sound/firewire/motu/motu-midi.c
index eebc7e790ee2..18c5734e999f 100644
--- a/sound/firewire/motu/motu-midi.c
+++ b/sound/firewire/motu/motu-midi.c
@@ -15,18 +15,16 @@ static int midi_open(struct snd_rawmidi_substream *substream)
if (err < 0)
return err;
- mutex_lock(&motu->mutex);
-
- err = snd_motu_stream_reserve_duplex(motu, 0, 0, 0);
- if (err >= 0) {
- ++motu->substreams_counter;
- err = snd_motu_stream_start_duplex(motu);
- if (err < 0)
- --motu->substreams_counter;
+ scoped_guard(mutex, &motu->mutex) {
+ err = snd_motu_stream_reserve_duplex(motu, 0, 0, 0);
+ if (err >= 0) {
+ ++motu->substreams_counter;
+ err = snd_motu_stream_start_duplex(motu);
+ if (err < 0)
+ --motu->substreams_counter;
+ }
}
- mutex_unlock(&motu->mutex);
-
if (err < 0)
snd_motu_stream_lock_release(motu);
@@ -37,12 +35,10 @@ static int midi_close(struct snd_rawmidi_substream *substream)
{
struct snd_motu *motu = substream->rmidi->private_data;
- mutex_lock(&motu->mutex);
-
- --motu->substreams_counter;
- snd_motu_stream_stop_duplex(motu);
-
- mutex_unlock(&motu->mutex);
+ scoped_guard(mutex, &motu->mutex) {
+ --motu->substreams_counter;
+ snd_motu_stream_stop_duplex(motu);
+ }
snd_motu_stream_lock_release(motu);
return 0;
diff --git a/sound/firewire/motu/motu-pcm.c b/sound/firewire/motu/motu-pcm.c
index 7b4d476af348..2302a96909b8 100644
--- a/sound/firewire/motu/motu-pcm.c
+++ b/sound/firewire/motu/motu-pcm.c
@@ -138,59 +138,57 @@ static int pcm_open(struct snd_pcm_substream *substream)
if (err < 0)
return err;
- mutex_lock(&motu->mutex);
+ scoped_guard(mutex, &motu->mutex) {
- err = snd_motu_stream_cache_packet_formats(motu);
- if (err < 0)
- goto err_locked;
-
- err = init_hw_info(motu, substream);
- if (err < 0)
- goto err_locked;
-
- err = snd_motu_protocol_get_clock_source(motu, &src);
- if (err < 0)
- goto err_locked;
-
- // 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 ((src != SND_MOTU_CLOCK_SOURCE_INTERNAL &&
- src != SND_MOTU_CLOCK_SOURCE_SPH) ||
- (motu->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_motu_protocol_get_clock_rate(motu, &rate);
+ err = snd_motu_stream_cache_packet_formats(motu);
if (err < 0)
goto err_locked;
- substream->runtime->hw.rate_min = rate;
- substream->runtime->hw.rate_max = rate;
+ err = init_hw_info(motu, substream);
+ if (err < 0)
+ 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);
+ err = snd_motu_protocol_get_clock_source(motu, &src);
+ if (err < 0)
+ goto err_locked;
+
+ // 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 ((src != SND_MOTU_CLOCK_SOURCE_INTERNAL &&
+ src != SND_MOTU_CLOCK_SOURCE_SPH) ||
+ (motu->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_motu_protocol_get_clock_rate(motu, &rate);
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;
+ 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)
+ 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;
+ }
}
}
snd_pcm_set_sync(substream);
- mutex_unlock(&motu->mutex);
-
return 0;
err_locked:
- mutex_unlock(&motu->mutex);
snd_motu_stream_lock_release(motu);
return err;
}
@@ -215,12 +213,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(&motu->mutex);
+ guard(mutex)(&motu->mutex);
err = snd_motu_stream_reserve_duplex(motu, rate,
frames_per_period, frames_per_buffer);
if (err >= 0)
++motu->substreams_counter;
- mutex_unlock(&motu->mutex);
}
return err;
@@ -230,15 +227,13 @@ static int pcm_hw_free(struct snd_pcm_substream *substream)
{
struct snd_motu *motu = substream->private_data;
- mutex_lock(&motu->mutex);
+ guard(mutex)(&motu->mutex);
if (substream->runtime->state != SNDRV_PCM_STATE_OPEN)
--motu->substreams_counter;
snd_motu_stream_stop_duplex(motu);
- mutex_unlock(&motu->mutex);
-
return 0;
}
@@ -247,9 +242,9 @@ static int capture_prepare(struct snd_pcm_substream *substream)
struct snd_motu *motu = substream->private_data;
int err;
- mutex_lock(&motu->mutex);
- err = snd_motu_stream_start_duplex(motu);
- mutex_unlock(&motu->mutex);
+ scoped_guard(mutex, &motu->mutex) {
+ err = snd_motu_stream_start_duplex(motu);
+ }
if (err >= 0)
amdtp_stream_pcm_prepare(&motu->tx_stream);
@@ -260,9 +255,9 @@ static int playback_prepare(struct snd_pcm_substream *substream)
struct snd_motu *motu = substream->private_data;
int err;
- mutex_lock(&motu->mutex);
- err = snd_motu_stream_start_duplex(motu);
- mutex_unlock(&motu->mutex);
+ scoped_guard(mutex, &motu->mutex) {
+ err = snd_motu_stream_start_duplex(motu);
+ }
if (err >= 0)
amdtp_stream_pcm_prepare(&motu->rx_stream);
--
2.50.1
^ permalink raw reply related [flat|nested] 22+ messages in thread
* [PATCH 06/19] ALSA: firewire: oxfw: Use guard() for mutex locks
2025-08-27 9:19 [PATCH 00/19] ALSA: firewire: Use auto-cleanup macros Takashi Iwai
` (4 preceding siblings ...)
2025-08-27 9:19 ` [PATCH 05/19] ALSA: firewire: motu: " Takashi Iwai
@ 2025-08-27 9:20 ` Takashi Iwai
2025-08-27 9:20 ` [PATCH 07/19] ALSA: firewire: tascam: " Takashi Iwai
` (13 subsequent siblings)
19 siblings, 0 replies; 22+ messages in thread
From: Takashi Iwai @ 2025-08-27 9:20 UTC (permalink / raw)
To: linux-sound; +Cc: Takashi Sakamoto, Clemens Ladisch
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/oxfw/oxfw-midi.c | 52 ++++++++-----------
sound/firewire/oxfw/oxfw-pcm.c | 89 ++++++++++++++-------------------
sound/firewire/oxfw/oxfw.c | 3 +-
3 files changed, 60 insertions(+), 84 deletions(-)
diff --git a/sound/firewire/oxfw/oxfw-midi.c b/sound/firewire/oxfw/oxfw-midi.c
index c215fa6f7a03..7f757f02a877 100644
--- a/sound/firewire/oxfw/oxfw-midi.c
+++ b/sound/firewire/oxfw/oxfw-midi.c
@@ -16,18 +16,16 @@ static int midi_capture_open(struct snd_rawmidi_substream *substream)
if (err < 0)
return err;
- mutex_lock(&oxfw->mutex);
-
- err = snd_oxfw_stream_reserve_duplex(oxfw, &oxfw->tx_stream, 0, 0, 0, 0);
- if (err >= 0) {
- ++oxfw->substreams_count;
- err = snd_oxfw_stream_start_duplex(oxfw);
- if (err < 0)
- --oxfw->substreams_count;
+ scoped_guard(mutex, &oxfw->mutex) {
+ err = snd_oxfw_stream_reserve_duplex(oxfw, &oxfw->tx_stream, 0, 0, 0, 0);
+ if (err >= 0) {
+ ++oxfw->substreams_count;
+ err = snd_oxfw_stream_start_duplex(oxfw);
+ if (err < 0)
+ --oxfw->substreams_count;
+ }
}
- mutex_unlock(&oxfw->mutex);
-
if (err < 0)
snd_oxfw_stream_lock_release(oxfw);
@@ -43,16 +41,14 @@ static int midi_playback_open(struct snd_rawmidi_substream *substream)
if (err < 0)
return err;
- mutex_lock(&oxfw->mutex);
-
- err = snd_oxfw_stream_reserve_duplex(oxfw, &oxfw->rx_stream, 0, 0, 0, 0);
- if (err >= 0) {
- ++oxfw->substreams_count;
- err = snd_oxfw_stream_start_duplex(oxfw);
+ scoped_guard(mutex, &oxfw->mutex) {
+ err = snd_oxfw_stream_reserve_duplex(oxfw, &oxfw->rx_stream, 0, 0, 0, 0);
+ if (err >= 0) {
+ ++oxfw->substreams_count;
+ err = snd_oxfw_stream_start_duplex(oxfw);
+ }
}
- mutex_unlock(&oxfw->mutex);
-
if (err < 0)
snd_oxfw_stream_lock_release(oxfw);
@@ -63,12 +59,10 @@ static int midi_capture_close(struct snd_rawmidi_substream *substream)
{
struct snd_oxfw *oxfw = substream->rmidi->private_data;
- mutex_lock(&oxfw->mutex);
-
- --oxfw->substreams_count;
- snd_oxfw_stream_stop_duplex(oxfw);
-
- mutex_unlock(&oxfw->mutex);
+ scoped_guard(mutex, &oxfw->mutex) {
+ --oxfw->substreams_count;
+ snd_oxfw_stream_stop_duplex(oxfw);
+ }
snd_oxfw_stream_lock_release(oxfw);
return 0;
@@ -78,12 +72,10 @@ static int midi_playback_close(struct snd_rawmidi_substream *substream)
{
struct snd_oxfw *oxfw = substream->rmidi->private_data;
- mutex_lock(&oxfw->mutex);
-
- --oxfw->substreams_count;
- snd_oxfw_stream_stop_duplex(oxfw);
-
- mutex_unlock(&oxfw->mutex);
+ scoped_guard(mutex, &oxfw->mutex) {
+ --oxfw->substreams_count;
+ snd_oxfw_stream_stop_duplex(oxfw);
+ }
snd_oxfw_stream_lock_release(oxfw);
return 0;
diff --git a/sound/firewire/oxfw/oxfw-pcm.c b/sound/firewire/oxfw/oxfw-pcm.c
index e13dc817fc28..7fd1984fac78 100644
--- a/sound/firewire/oxfw/oxfw-pcm.c
+++ b/sound/firewire/oxfw/oxfw-pcm.c
@@ -181,42 +181,35 @@ static int pcm_open(struct snd_pcm_substream *substream)
if (err < 0)
goto err_locked;
- mutex_lock(&oxfw->mutex);
+ scoped_guard(mutex, &oxfw->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 (oxfw->substreams_count > 0 && d->events_per_period > 0) {
- unsigned int frames_per_period = d->events_per_period;
- unsigned int frames_per_buffer = d->events_per_buffer;
+ // 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 (oxfw->substreams_count > 0 && d->events_per_period > 0) {
+ unsigned int frames_per_period = d->events_per_period;
+ unsigned int frames_per_buffer = d->events_per_buffer;
- err = limit_to_current_params(substream);
- if (err < 0) {
- mutex_unlock(&oxfw->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) {
- mutex_unlock(&oxfw->mutex);
+ err = limit_to_current_params(substream);
+ 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) {
- mutex_unlock(&oxfw->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(&oxfw->mutex);
-
snd_pcm_set_sync(substream);
return 0;
@@ -245,13 +238,12 @@ static int pcm_capture_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(&oxfw->mutex);
+ guard(mutex)(&oxfw->mutex);
err = snd_oxfw_stream_reserve_duplex(oxfw, &oxfw->tx_stream,
rate, channels, frames_per_period,
frames_per_buffer);
if (err >= 0)
++oxfw->substreams_count;
- mutex_unlock(&oxfw->mutex);
}
return err;
@@ -268,13 +260,12 @@ static int pcm_playback_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(&oxfw->mutex);
+ guard(mutex)(&oxfw->mutex);
err = snd_oxfw_stream_reserve_duplex(oxfw, &oxfw->rx_stream,
rate, channels, frames_per_period,
frames_per_buffer);
if (err >= 0)
++oxfw->substreams_count;
- mutex_unlock(&oxfw->mutex);
}
return err;
@@ -284,30 +275,26 @@ static int pcm_capture_hw_free(struct snd_pcm_substream *substream)
{
struct snd_oxfw *oxfw = substream->private_data;
- mutex_lock(&oxfw->mutex);
+ guard(mutex)(&oxfw->mutex);
if (substream->runtime->state != SNDRV_PCM_STATE_OPEN)
--oxfw->substreams_count;
snd_oxfw_stream_stop_duplex(oxfw);
- mutex_unlock(&oxfw->mutex);
-
return 0;
}
static int pcm_playback_hw_free(struct snd_pcm_substream *substream)
{
struct snd_oxfw *oxfw = substream->private_data;
- mutex_lock(&oxfw->mutex);
+ guard(mutex)(&oxfw->mutex);
if (substream->runtime->state != SNDRV_PCM_STATE_OPEN)
--oxfw->substreams_count;
snd_oxfw_stream_stop_duplex(oxfw);
- mutex_unlock(&oxfw->mutex);
-
return 0;
}
@@ -316,30 +303,28 @@ static int pcm_capture_prepare(struct snd_pcm_substream *substream)
struct snd_oxfw *oxfw = substream->private_data;
int err;
- mutex_lock(&oxfw->mutex);
- err = snd_oxfw_stream_start_duplex(oxfw);
- mutex_unlock(&oxfw->mutex);
- if (err < 0)
- goto end;
+ scoped_guard(mutex, &oxfw->mutex) {
+ err = snd_oxfw_stream_start_duplex(oxfw);
+ if (err < 0)
+ return err;
+ }
amdtp_stream_pcm_prepare(&oxfw->tx_stream);
-end:
- return err;
+ return 0;
}
static int pcm_playback_prepare(struct snd_pcm_substream *substream)
{
struct snd_oxfw *oxfw = substream->private_data;
int err;
- mutex_lock(&oxfw->mutex);
- err = snd_oxfw_stream_start_duplex(oxfw);
- mutex_unlock(&oxfw->mutex);
- if (err < 0)
- goto end;
+ scoped_guard(mutex, &oxfw->mutex) {
+ err = snd_oxfw_stream_start_duplex(oxfw);
+ if (err < 0)
+ return err;
+ }
amdtp_stream_pcm_prepare(&oxfw->rx_stream);
-end:
- return err;
+ return 0;
}
static int pcm_capture_trigger(struct snd_pcm_substream *substream, int cmd)
diff --git a/sound/firewire/oxfw/oxfw.c b/sound/firewire/oxfw/oxfw.c
index 7a985f3cb8f6..5039bd79b18e 100644
--- a/sound/firewire/oxfw/oxfw.c
+++ b/sound/firewire/oxfw/oxfw.c
@@ -283,9 +283,8 @@ static void oxfw_bus_reset(struct fw_unit *unit)
fcp_bus_reset(oxfw->unit);
if (oxfw->has_output || oxfw->has_input) {
- mutex_lock(&oxfw->mutex);
+ guard(mutex)(&oxfw->mutex);
snd_oxfw_stream_update_duplex(oxfw);
- mutex_unlock(&oxfw->mutex);
}
if (oxfw->quirks & SND_OXFW_QUIRK_SCS_TRANSACTION)
--
2.50.1
^ permalink raw reply related [flat|nested] 22+ messages in thread
* [PATCH 07/19] ALSA: firewire: tascam: Use guard() for mutex locks
2025-08-27 9:19 [PATCH 00/19] ALSA: firewire: Use auto-cleanup macros Takashi Iwai
` (5 preceding siblings ...)
2025-08-27 9:20 ` [PATCH 06/19] ALSA: firewire: oxfw: " Takashi Iwai
@ 2025-08-27 9:20 ` Takashi Iwai
2025-08-27 9:20 ` [PATCH 08/19] ALSA: firewire: fireface: " Takashi Iwai
` (12 subsequent siblings)
19 siblings, 0 replies; 22+ messages in thread
From: Takashi Iwai @ 2025-08-27 9:20 UTC (permalink / raw)
To: linux-sound; +Cc: Takashi Sakamoto, Clemens Ladisch
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/tascam/tascam-pcm.c | 68 ++++++++++++------------------
sound/firewire/tascam/tascam.c | 3 +-
2 files changed, 28 insertions(+), 43 deletions(-)
diff --git a/sound/firewire/tascam/tascam-pcm.c b/sound/firewire/tascam/tascam-pcm.c
index a73003ac11e6..a437efcecae3 100644
--- a/sound/firewire/tascam/tascam-pcm.c
+++ b/sound/firewire/tascam/tascam-pcm.c
@@ -59,43 +59,36 @@ static int pcm_open(struct snd_pcm_substream *substream)
if (err < 0)
goto err_locked;
- mutex_lock(&tscm->mutex);
+ scoped_guard(mutex, &tscm->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_TSCM_CLOCK_INTERNAL || tscm->substreams_counter > 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_TSCM_CLOCK_INTERNAL || tscm->substreams_counter > 0) {
+ unsigned int frames_per_period = d->events_per_period;
+ unsigned int frames_per_buffer = d->events_per_buffer;
+ unsigned int rate;
- err = snd_tscm_stream_get_rate(tscm, &rate);
- if (err < 0) {
- mutex_unlock(&tscm->mutex);
- goto err_locked;
- }
- substream->runtime->hw.rate_min = rate;
- substream->runtime->hw.rate_max = rate;
+ err = snd_tscm_stream_get_rate(tscm, &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_PERIOD_SIZE,
- frames_per_period, frames_per_period);
- if (err < 0) {
- mutex_unlock(&tscm->mutex);
- goto err_locked;
- }
+ 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) {
- mutex_unlock(&tscm->mutex);
- 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(&tscm->mutex);
-
snd_pcm_set_sync(substream);
return 0;
@@ -124,12 +117,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(&tscm->mutex);
+ guard(mutex)(&tscm->mutex);
err = snd_tscm_stream_reserve_duplex(tscm, rate,
frames_per_period, frames_per_buffer);
if (err >= 0)
++tscm->substreams_counter;
- mutex_unlock(&tscm->mutex);
}
return err;
@@ -139,15 +131,13 @@ static int pcm_hw_free(struct snd_pcm_substream *substream)
{
struct snd_tscm *tscm = substream->private_data;
- mutex_lock(&tscm->mutex);
+ guard(mutex)(&tscm->mutex);
if (substream->runtime->state != SNDRV_PCM_STATE_OPEN)
--tscm->substreams_counter;
snd_tscm_stream_stop_duplex(tscm);
- mutex_unlock(&tscm->mutex);
-
return 0;
}
@@ -157,14 +147,12 @@ static int pcm_capture_prepare(struct snd_pcm_substream *substream)
struct snd_pcm_runtime *runtime = substream->runtime;
int err;
- mutex_lock(&tscm->mutex);
+ guard(mutex)(&tscm->mutex);
err = snd_tscm_stream_start_duplex(tscm, runtime->rate);
if (err >= 0)
amdtp_stream_pcm_prepare(&tscm->tx_stream);
- mutex_unlock(&tscm->mutex);
-
return err;
}
@@ -174,14 +162,12 @@ static int pcm_playback_prepare(struct snd_pcm_substream *substream)
struct snd_pcm_runtime *runtime = substream->runtime;
int err;
- mutex_lock(&tscm->mutex);
+ guard(mutex)(&tscm->mutex);
err = snd_tscm_stream_start_duplex(tscm, runtime->rate);
if (err >= 0)
amdtp_stream_pcm_prepare(&tscm->rx_stream);
- mutex_unlock(&tscm->mutex);
-
return err;
}
diff --git a/sound/firewire/tascam/tascam.c b/sound/firewire/tascam/tascam.c
index 4f68bb4c58bc..f4092df8650c 100644
--- a/sound/firewire/tascam/tascam.c
+++ b/sound/firewire/tascam/tascam.c
@@ -158,9 +158,8 @@ static void snd_tscm_update(struct fw_unit *unit)
snd_tscm_transaction_reregister(tscm);
- mutex_lock(&tscm->mutex);
+ guard(mutex)(&tscm->mutex);
snd_tscm_stream_update_duplex(tscm);
- mutex_unlock(&tscm->mutex);
}
static void snd_tscm_remove(struct fw_unit *unit)
--
2.50.1
^ permalink raw reply related [flat|nested] 22+ messages in thread
* [PATCH 08/19] ALSA: firewire: fireface: Use guard() for mutex locks
2025-08-27 9:19 [PATCH 00/19] ALSA: firewire: Use auto-cleanup macros Takashi Iwai
` (6 preceding siblings ...)
2025-08-27 9:20 ` [PATCH 07/19] ALSA: firewire: tascam: " Takashi Iwai
@ 2025-08-27 9:20 ` Takashi Iwai
2025-08-27 9:20 ` [PATCH 09/19] ALSA: firewire: isight: " Takashi Iwai
` (11 subsequent siblings)
19 siblings, 0 replies; 22+ messages in thread
From: Takashi Iwai @ 2025-08-27 9:20 UTC (permalink / raw)
To: linux-sound; +Cc: Takashi Sakamoto, Clemens Ladisch
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/fireface/ff-pcm.c | 91 ++++++++++++++------------------
1 file changed, 39 insertions(+), 52 deletions(-)
diff --git a/sound/firewire/fireface/ff-pcm.c b/sound/firewire/fireface/ff-pcm.c
index 63457d24a288..2c301cff9616 100644
--- a/sound/firewire/fireface/ff-pcm.c
+++ b/sound/firewire/fireface/ff-pcm.c
@@ -156,56 +156,50 @@ static int pcm_open(struct snd_pcm_substream *substream)
if (err < 0)
goto release_lock;
- mutex_lock(&ff->mutex);
+ scoped_guard(mutex, &ff->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 (src != SND_FF_CLOCK_SRC_INTERNAL) {
- for (i = 0; i < CIP_SFC_COUNT; ++i) {
- if (amdtp_rate_table[i] == rate)
- break;
- }
+ // 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 (src != SND_FF_CLOCK_SRC_INTERNAL) {
+ for (i = 0; i < CIP_SFC_COUNT; ++i) {
+ if (amdtp_rate_table[i] == rate)
+ break;
+ }
- // The unit is configured at sampling frequency which packet
- // streaming engine can't support.
- if (i >= CIP_SFC_COUNT) {
- mutex_unlock(&ff->mutex);
- err = -EIO;
- goto release_lock;
- }
-
- substream->runtime->hw.rate_min = rate;
- substream->runtime->hw.rate_max = rate;
- } else {
- if (ff->substreams_counter > 0) {
- unsigned int frames_per_period = d->events_per_period;
- unsigned int frames_per_buffer = d->events_per_buffer;
-
- rate = amdtp_rate_table[ff->rx_stream.sfc];
- substream->runtime->hw.rate_min = rate;
- substream->runtime->hw.rate_max = rate;
-
- 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(&ff->mutex);
+ // The unit is configured at sampling frequency which packet
+ // streaming engine can't support.
+ if (i >= CIP_SFC_COUNT) {
+ err = -EIO;
goto release_lock;
}
- 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(&ff->mutex);
- goto release_lock;
+ substream->runtime->hw.rate_min = rate;
+ substream->runtime->hw.rate_max = rate;
+ } else {
+ if (ff->substreams_counter > 0) {
+ unsigned int frames_per_period = d->events_per_period;
+ unsigned int frames_per_buffer = d->events_per_buffer;
+
+ rate = amdtp_rate_table[ff->rx_stream.sfc];
+ substream->runtime->hw.rate_min = rate;
+ substream->runtime->hw.rate_max = rate;
+
+ err = snd_pcm_hw_constraint_minmax(substream->runtime,
+ SNDRV_PCM_HW_PARAM_PERIOD_SIZE,
+ frames_per_period, frames_per_period);
+ if (err < 0)
+ goto release_lock;
+
+ err = snd_pcm_hw_constraint_minmax(substream->runtime,
+ SNDRV_PCM_HW_PARAM_BUFFER_SIZE,
+ frames_per_buffer, frames_per_buffer);
+ if (err < 0)
+ goto release_lock;
}
}
}
- mutex_unlock(&ff->mutex);
-
snd_pcm_set_sync(substream);
return 0;
@@ -235,12 +229,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(&ff->mutex);
+ guard(mutex)(&ff->mutex);
err = snd_ff_stream_reserve_duplex(ff, rate, frames_per_period,
frames_per_buffer);
if (err >= 0)
++ff->substreams_counter;
- mutex_unlock(&ff->mutex);
}
return err;
@@ -250,15 +243,13 @@ static int pcm_hw_free(struct snd_pcm_substream *substream)
{
struct snd_ff *ff = substream->private_data;
- mutex_lock(&ff->mutex);
+ guard(mutex)(&ff->mutex);
if (substream->runtime->state != SNDRV_PCM_STATE_OPEN)
--ff->substreams_counter;
snd_ff_stream_stop_duplex(ff);
- mutex_unlock(&ff->mutex);
-
return 0;
}
@@ -268,14 +259,12 @@ static int pcm_capture_prepare(struct snd_pcm_substream *substream)
struct snd_pcm_runtime *runtime = substream->runtime;
int err;
- mutex_lock(&ff->mutex);
+ guard(mutex)(&ff->mutex);
err = snd_ff_stream_start_duplex(ff, runtime->rate);
if (err >= 0)
amdtp_stream_pcm_prepare(&ff->tx_stream);
- mutex_unlock(&ff->mutex);
-
return err;
}
@@ -285,14 +274,12 @@ static int pcm_playback_prepare(struct snd_pcm_substream *substream)
struct snd_pcm_runtime *runtime = substream->runtime;
int err;
- mutex_lock(&ff->mutex);
+ guard(mutex)(&ff->mutex);
err = snd_ff_stream_start_duplex(ff, runtime->rate);
if (err >= 0)
amdtp_stream_pcm_prepare(&ff->rx_stream);
- mutex_unlock(&ff->mutex);
-
return err;
}
--
2.50.1
^ permalink raw reply related [flat|nested] 22+ messages in thread
* [PATCH 09/19] ALSA: firewire: isight: Use guard() for mutex locks
2025-08-27 9:19 [PATCH 00/19] ALSA: firewire: Use auto-cleanup macros Takashi Iwai
` (7 preceding siblings ...)
2025-08-27 9:20 ` [PATCH 08/19] ALSA: firewire: fireface: " Takashi Iwai
@ 2025-08-27 9:20 ` Takashi Iwai
2025-08-27 9:20 ` [PATCH 10/19] ALSA: firewire: lib: " Takashi Iwai
` (10 subsequent siblings)
19 siblings, 0 replies; 22+ messages in thread
From: Takashi Iwai @ 2025-08-27 9:20 UTC (permalink / raw)
To: linux-sound; +Cc: Takashi Sakamoto, Clemens Ladisch
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/isight.c | 20 +++++++-------------
1 file changed, 7 insertions(+), 13 deletions(-)
diff --git a/sound/firewire/isight.c b/sound/firewire/isight.c
index ee574b5d7406..2b7f071d593b 100644
--- a/sound/firewire/isight.c
+++ b/sound/firewire/isight.c
@@ -327,9 +327,8 @@ static int isight_hw_free(struct snd_pcm_substream *substream)
WRITE_ONCE(isight->pcm_active, false);
- mutex_lock(&isight->mutex);
+ guard(mutex)(&isight->mutex);
isight_stop_streaming(isight);
- mutex_unlock(&isight->mutex);
return 0;
}
@@ -400,16 +399,12 @@ static int isight_start_streaming(struct isight *isight)
static int isight_prepare(struct snd_pcm_substream *substream)
{
struct isight *isight = substream->private_data;
- int err;
isight->buffer_pointer = 0;
isight->period_counter = 0;
- mutex_lock(&isight->mutex);
- err = isight_start_streaming(isight);
- mutex_unlock(&isight->mutex);
-
- return err;
+ guard(mutex)(&isight->mutex);
+ return isight_start_streaming(isight);
}
static int isight_trigger(struct snd_pcm_substream *substream, int cmd)
@@ -677,9 +672,8 @@ static void isight_bus_reset(struct fw_unit *unit)
if (fw_iso_resources_update(&isight->resources) < 0) {
isight_pcm_abort(isight);
- mutex_lock(&isight->mutex);
+ guard(mutex)(&isight->mutex);
isight_stop_streaming(isight);
- mutex_unlock(&isight->mutex);
}
}
@@ -691,9 +685,9 @@ static void isight_remove(struct fw_unit *unit)
snd_card_disconnect(isight->card);
- mutex_lock(&isight->mutex);
- isight_stop_streaming(isight);
- mutex_unlock(&isight->mutex);
+ scoped_guard(mutex, &isight->mutex) {
+ isight_stop_streaming(isight);
+ }
// Block till all of ALSA character devices are released.
snd_card_free(isight->card);
--
2.50.1
^ permalink raw reply related [flat|nested] 22+ messages in thread
* [PATCH 10/19] ALSA: firewire: lib: Use guard() for mutex locks
2025-08-27 9:19 [PATCH 00/19] ALSA: firewire: Use auto-cleanup macros Takashi Iwai
` (8 preceding siblings ...)
2025-08-27 9:20 ` [PATCH 09/19] ALSA: firewire: isight: " Takashi Iwai
@ 2025-08-27 9:20 ` Takashi Iwai
2025-08-27 9:20 ` [PATCH 11/19] ALSA: firewire: bebob: Use guard() for spin locks Takashi Iwai
` (9 subsequent siblings)
19 siblings, 0 replies; 22+ messages in thread
From: Takashi Iwai @ 2025-08-27 9:20 UTC (permalink / raw)
To: linux-sound; +Cc: Takashi Sakamoto, Clemens Ladisch
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/amdtp-stream.c | 28 ++++++-------------
sound/firewire/cmp.c | 37 +++++++------------------
sound/firewire/iso-resources.c | 50 ++++++++++++++--------------------
3 files changed, 38 insertions(+), 77 deletions(-)
diff --git a/sound/firewire/amdtp-stream.c b/sound/firewire/amdtp-stream.c
index 7fc51f829ecc..5cdc34877fc1 100644
--- a/sound/firewire/amdtp-stream.c
+++ b/sound/firewire/amdtp-stream.c
@@ -1688,20 +1688,16 @@ static int amdtp_stream_start(struct amdtp_stream *s, int channel, int speed,
struct pkt_desc *descs;
int i, type, tag, err;
- mutex_lock(&s->mutex);
+ guard(mutex)(&s->mutex);
if (WARN_ON(amdtp_stream_running(s) ||
- (s->data_block_quadlets < 1))) {
- err = -EBADFD;
- goto err_unlock;
- }
+ (s->data_block_quadlets < 1)))
+ return -EBADFD;
if (s->direction == AMDTP_IN_STREAM) {
// NOTE: IT context should be used for constant IRQ.
- if (is_irq_target) {
- err = -EINVAL;
- goto err_unlock;
- }
+ if (is_irq_target)
+ return -EINVAL;
s->data_block_counter = UINT_MAX;
} else {
@@ -1725,7 +1721,7 @@ static int amdtp_stream_start(struct amdtp_stream *s, int channel, int speed,
err = iso_packets_buffer_init(&s->buffer, s->unit, queue_size, max_ctx_payload_size, dir);
if (err < 0)
- goto err_unlock;
+ return err;
s->queue_size = queue_size;
s->context = fw_iso_context_create(fw_parent_device(s->unit)->card,
@@ -1846,8 +1842,6 @@ static int amdtp_stream_start(struct amdtp_stream *s, int channel, int speed,
if (err < 0)
goto err_pkt_descs;
- mutex_unlock(&s->mutex);
-
return 0;
err_pkt_descs:
kfree(s->packet_descs);
@@ -1863,8 +1857,6 @@ static int amdtp_stream_start(struct amdtp_stream *s, int channel, int speed,
s->context = ERR_PTR(-1);
err_buffer:
iso_packets_buffer_destroy(&s->buffer, s->unit);
-err_unlock:
- mutex_unlock(&s->mutex);
return err;
}
@@ -1934,12 +1926,10 @@ EXPORT_SYMBOL(amdtp_stream_update);
*/
static void amdtp_stream_stop(struct amdtp_stream *s)
{
- mutex_lock(&s->mutex);
+ guard(mutex)(&s->mutex);
- if (!amdtp_stream_running(s)) {
- mutex_unlock(&s->mutex);
+ if (!amdtp_stream_running(s))
return;
- }
cancel_work_sync(&s->period_work);
fw_iso_context_stop(s->context);
@@ -1955,8 +1945,6 @@ static void amdtp_stream_stop(struct amdtp_stream *s)
if (s->domain->replay.enable)
kfree(s->ctx_data.tx.cache.descs);
}
-
- mutex_unlock(&s->mutex);
}
/**
diff --git a/sound/firewire/cmp.c b/sound/firewire/cmp.c
index f5028a061a91..b2b76c7c71b3 100644
--- a/sound/firewire/cmp.c
+++ b/sound/firewire/cmp.c
@@ -188,32 +188,23 @@ EXPORT_SYMBOL(cmp_connection_destroy);
int cmp_connection_reserve(struct cmp_connection *c,
unsigned int max_payload_bytes)
{
- int err;
+ guard(mutex)(&c->mutex);
- mutex_lock(&c->mutex);
-
- if (WARN_ON(c->resources.allocated)) {
- err = -EBUSY;
- goto end;
- }
+ if (WARN_ON(c->resources.allocated))
+ return -EBUSY;
c->speed = min(c->max_speed,
fw_parent_device(c->resources.unit)->max_speed);
- err = fw_iso_resources_allocate(&c->resources, max_payload_bytes,
- c->speed);
-end:
- mutex_unlock(&c->mutex);
-
- return err;
+ return fw_iso_resources_allocate(&c->resources, max_payload_bytes,
+ c->speed);
}
EXPORT_SYMBOL(cmp_connection_reserve);
void cmp_connection_release(struct cmp_connection *c)
{
- mutex_lock(&c->mutex);
+ guard(mutex)(&c->mutex);
fw_iso_resources_free(&c->resources);
- mutex_unlock(&c->mutex);
}
EXPORT_SYMBOL(cmp_connection_release);
@@ -304,12 +295,10 @@ int cmp_connection_establish(struct cmp_connection *c)
{
int err;
- mutex_lock(&c->mutex);
+ guard(mutex)(&c->mutex);
- if (WARN_ON(c->connected)) {
- mutex_unlock(&c->mutex);
+ if (WARN_ON(c->connected))
return -EISCONN;
- }
retry_after_bus_reset:
if (c->direction == CMP_OUTPUT)
@@ -327,8 +316,6 @@ int cmp_connection_establish(struct cmp_connection *c)
if (err >= 0)
c->connected = true;
- mutex_unlock(&c->mutex);
-
return err;
}
EXPORT_SYMBOL(cmp_connection_establish);
@@ -350,19 +337,15 @@ void cmp_connection_break(struct cmp_connection *c)
{
int err;
- mutex_lock(&c->mutex);
+ guard(mutex)(&c->mutex);
- if (!c->connected) {
- mutex_unlock(&c->mutex);
+ if (!c->connected)
return;
- }
err = pcr_modify(c, pcr_break_modify, NULL, SUCCEED_ON_BUS_RESET);
if (err < 0)
cmp_error(c, "plug is still connected\n");
c->connected = false;
-
- mutex_unlock(&c->mutex);
}
EXPORT_SYMBOL(cmp_connection_break);
diff --git a/sound/firewire/iso-resources.c b/sound/firewire/iso-resources.c
index 84f71b2eaa82..b47ee029d688 100644
--- a/sound/firewire/iso-resources.c
+++ b/sound/firewire/iso-resources.c
@@ -123,28 +123,24 @@ int fw_iso_resources_allocate(struct fw_iso_resources *r,
if (err < 0)
return err;
- mutex_lock(&r->mutex);
-
- bandwidth = r->bandwidth + r->bandwidth_overhead;
- fw_iso_resource_manage(card, r->generation, r->channels_mask,
- &channel, &bandwidth, true);
- if (channel == -EAGAIN) {
- mutex_unlock(&r->mutex);
- goto retry_after_bus_reset;
+ scoped_guard(mutex, &r->mutex) {
+ bandwidth = r->bandwidth + r->bandwidth_overhead;
+ fw_iso_resource_manage(card, r->generation, r->channels_mask,
+ &channel, &bandwidth, true);
+ if (channel == -EAGAIN)
+ goto retry_after_bus_reset;
+ if (channel >= 0) {
+ r->channel = channel;
+ r->allocated = true;
+ } else {
+ if (channel == -EBUSY)
+ dev_err(&r->unit->device,
+ "isochronous resources exhausted\n");
+ else
+ dev_err(&r->unit->device,
+ "isochronous resource allocation failed\n");
+ }
}
- if (channel >= 0) {
- r->channel = channel;
- r->allocated = true;
- } else {
- if (channel == -EBUSY)
- dev_err(&r->unit->device,
- "isochronous resources exhausted\n");
- else
- dev_err(&r->unit->device,
- "isochronous resource allocation failed\n");
- }
-
- mutex_unlock(&r->mutex);
return channel;
}
@@ -166,12 +162,10 @@ int fw_iso_resources_update(struct fw_iso_resources *r)
struct fw_card *card = fw_parent_device(r->unit)->card;
int bandwidth, channel;
- mutex_lock(&r->mutex);
+ guard(mutex)(&r->mutex);
- if (!r->allocated) {
- mutex_unlock(&r->mutex);
+ if (!r->allocated)
return 0;
- }
spin_lock_irq(&card->lock);
r->generation = card->generation;
@@ -196,8 +190,6 @@ int fw_iso_resources_update(struct fw_iso_resources *r)
"isochronous resource allocation failed\n");
}
- mutex_unlock(&r->mutex);
-
return channel;
}
EXPORT_SYMBOL(fw_iso_resources_update);
@@ -218,7 +210,7 @@ void fw_iso_resources_free(struct fw_iso_resources *r)
return;
card = fw_parent_device(r->unit)->card;
- mutex_lock(&r->mutex);
+ guard(mutex)(&r->mutex);
if (r->allocated) {
bandwidth = r->bandwidth + r->bandwidth_overhead;
@@ -230,7 +222,5 @@ void fw_iso_resources_free(struct fw_iso_resources *r)
r->allocated = false;
}
-
- mutex_unlock(&r->mutex);
}
EXPORT_SYMBOL(fw_iso_resources_free);
--
2.50.1
^ permalink raw reply related [flat|nested] 22+ messages in thread
* [PATCH 11/19] ALSA: firewire: bebob: Use guard() for spin locks
2025-08-27 9:19 [PATCH 00/19] ALSA: firewire: Use auto-cleanup macros Takashi Iwai
` (9 preceding siblings ...)
2025-08-27 9:20 ` [PATCH 10/19] ALSA: firewire: lib: " Takashi Iwai
@ 2025-08-27 9:20 ` Takashi Iwai
2025-08-27 9:20 ` [PATCH 12/19] ALSA: firewire: dice: " Takashi Iwai
` (8 subsequent siblings)
19 siblings, 0 replies; 22+ messages in thread
From: Takashi Iwai @ 2025-08-27 9:20 UTC (permalink / raw)
To: linux-sound; +Cc: Takashi Sakamoto, Clemens Ladisch
Clean up the code using guard() for spin locks.
Merely code refactoring, and no behavior change.
Signed-off-by: Takashi Iwai <tiwai@suse.de>
---
sound/firewire/bebob/bebob_hwdep.c | 37 ++++++++---------------------
sound/firewire/bebob/bebob_midi.c | 10 ++------
sound/firewire/bebob/bebob_stream.c | 21 +++++-----------
3 files changed, 18 insertions(+), 50 deletions(-)
diff --git a/sound/firewire/bebob/bebob_hwdep.c b/sound/firewire/bebob/bebob_hwdep.c
index 5779e99a6bb2..216d1fceb6e7 100644
--- a/sound/firewire/bebob/bebob_hwdep.c
+++ b/sound/firewire/bebob/bebob_hwdep.c
@@ -53,18 +53,14 @@ static __poll_t
hwdep_poll(struct snd_hwdep *hwdep, struct file *file, poll_table *wait)
{
struct snd_bebob *bebob = hwdep->private_data;
- __poll_t events;
poll_wait(file, &bebob->hwdep_wait, wait);
- spin_lock_irq(&bebob->lock);
+ guard(spinlock_irq)(&bebob->lock);
if (bebob->dev_lock_changed)
- events = EPOLLIN | EPOLLRDNORM;
+ return EPOLLIN | EPOLLRDNORM;
else
- events = 0;
- spin_unlock_irq(&bebob->lock);
-
- return events;
+ return 0;
}
static int
@@ -90,39 +86,27 @@ hwdep_get_info(struct snd_bebob *bebob, void __user *arg)
static int
hwdep_lock(struct snd_bebob *bebob)
{
- int err;
-
- spin_lock_irq(&bebob->lock);
+ guard(spinlock_irq)(&bebob->lock);
if (bebob->dev_lock_count == 0) {
bebob->dev_lock_count = -1;
- err = 0;
+ return 0;
} else {
- err = -EBUSY;
+ return -EBUSY;
}
-
- spin_unlock_irq(&bebob->lock);
-
- return err;
}
static int
hwdep_unlock(struct snd_bebob *bebob)
{
- int err;
-
- spin_lock_irq(&bebob->lock);
+ guard(spinlock_irq)(&bebob->lock);
if (bebob->dev_lock_count == -1) {
bebob->dev_lock_count = 0;
- err = 0;
+ return 0;
} else {
- err = -EBADFD;
+ return -EBADFD;
}
-
- spin_unlock_irq(&bebob->lock);
-
- return err;
}
static int
@@ -130,10 +114,9 @@ hwdep_release(struct snd_hwdep *hwdep, struct file *file)
{
struct snd_bebob *bebob = hwdep->private_data;
- spin_lock_irq(&bebob->lock);
+ guard(spinlock_irq)(&bebob->lock);
if (bebob->dev_lock_count == -1)
bebob->dev_lock_count = 0;
- spin_unlock_irq(&bebob->lock);
return 0;
}
diff --git a/sound/firewire/bebob/bebob_midi.c b/sound/firewire/bebob/bebob_midi.c
index 5fd2d363de52..678631f31d3c 100644
--- a/sound/firewire/bebob/bebob_midi.c
+++ b/sound/firewire/bebob/bebob_midi.c
@@ -47,9 +47,8 @@ static int midi_close(struct snd_rawmidi_substream *substream)
static void midi_capture_trigger(struct snd_rawmidi_substream *substrm, int up)
{
struct snd_bebob *bebob = substrm->rmidi->private_data;
- unsigned long flags;
- spin_lock_irqsave(&bebob->lock, flags);
+ guard(spinlock_irqsave)(&bebob->lock);
if (up)
amdtp_am824_midi_trigger(&bebob->tx_stream,
@@ -57,16 +56,13 @@ static void midi_capture_trigger(struct snd_rawmidi_substream *substrm, int up)
else
amdtp_am824_midi_trigger(&bebob->tx_stream,
substrm->number, NULL);
-
- spin_unlock_irqrestore(&bebob->lock, flags);
}
static void midi_playback_trigger(struct snd_rawmidi_substream *substrm, int up)
{
struct snd_bebob *bebob = substrm->rmidi->private_data;
- unsigned long flags;
- spin_lock_irqsave(&bebob->lock, flags);
+ guard(spinlock_irqsave)(&bebob->lock);
if (up)
amdtp_am824_midi_trigger(&bebob->rx_stream,
@@ -74,8 +70,6 @@ static void midi_playback_trigger(struct snd_rawmidi_substream *substrm, int up)
else
amdtp_am824_midi_trigger(&bebob->rx_stream,
substrm->number, NULL);
-
- spin_unlock_irqrestore(&bebob->lock, flags);
}
static void set_midi_substream_names(struct snd_bebob *bebob,
diff --git a/sound/firewire/bebob/bebob_stream.c b/sound/firewire/bebob/bebob_stream.c
index 8629b14ded76..449cb17717f0 100644
--- a/sound/firewire/bebob/bebob_stream.c
+++ b/sound/firewire/bebob/bebob_stream.c
@@ -964,33 +964,24 @@ void snd_bebob_stream_lock_changed(struct snd_bebob *bebob)
int snd_bebob_stream_lock_try(struct snd_bebob *bebob)
{
- int err;
-
- spin_lock_irq(&bebob->lock);
+ guard(spinlock_irq)(&bebob->lock);
/* user land lock this */
- if (bebob->dev_lock_count < 0) {
- err = -EBUSY;
- goto end;
- }
+ if (bebob->dev_lock_count < 0)
+ return -EBUSY;
/* this is the first time */
if (bebob->dev_lock_count++ == 0)
snd_bebob_stream_lock_changed(bebob);
- err = 0;
-end:
- spin_unlock_irq(&bebob->lock);
- return err;
+ return 0;
}
void snd_bebob_stream_lock_release(struct snd_bebob *bebob)
{
- spin_lock_irq(&bebob->lock);
+ guard(spinlock_irq)(&bebob->lock);
if (WARN_ON(bebob->dev_lock_count <= 0))
- goto end;
+ return;
if (--bebob->dev_lock_count == 0)
snd_bebob_stream_lock_changed(bebob);
-end:
- spin_unlock_irq(&bebob->lock);
}
--
2.50.1
^ permalink raw reply related [flat|nested] 22+ messages in thread
* [PATCH 12/19] ALSA: firewire: dice: Use guard() for spin locks
2025-08-27 9:19 [PATCH 00/19] ALSA: firewire: Use auto-cleanup macros Takashi Iwai
` (10 preceding siblings ...)
2025-08-27 9:20 ` [PATCH 11/19] ALSA: firewire: bebob: Use guard() for spin locks Takashi Iwai
@ 2025-08-27 9:20 ` Takashi Iwai
2025-08-27 9:20 ` [PATCH 13/19] ALSA: firewire: digi00x: " Takashi Iwai
` (7 subsequent siblings)
19 siblings, 0 replies; 22+ messages in thread
From: Takashi Iwai @ 2025-08-27 9:20 UTC (permalink / raw)
To: linux-sound; +Cc: Takashi Sakamoto, Clemens Ladisch
Clean up the code using guard() for spin locks.
Merely code refactoring, and no behavior change.
Signed-off-by: Takashi Iwai <tiwai@suse.de>
---
sound/firewire/dice/dice-hwdep.c | 37 +++++++-------------------
sound/firewire/dice/dice-midi.c | 10 ++-----
sound/firewire/dice/dice-stream.c | 21 +++++----------
sound/firewire/dice/dice-transaction.c | 7 +++--
4 files changed, 21 insertions(+), 54 deletions(-)
diff --git a/sound/firewire/dice/dice-hwdep.c b/sound/firewire/dice/dice-hwdep.c
index d165dd427bd3..747ff0952483 100644
--- a/sound/firewire/dice/dice-hwdep.c
+++ b/sound/firewire/dice/dice-hwdep.c
@@ -55,18 +55,14 @@ static __poll_t hwdep_poll(struct snd_hwdep *hwdep, struct file *file,
poll_table *wait)
{
struct snd_dice *dice = hwdep->private_data;
- __poll_t events;
poll_wait(file, &dice->hwdep_wait, wait);
- spin_lock_irq(&dice->lock);
+ guard(spinlock_irq)(&dice->lock);
if (dice->dev_lock_changed || dice->notification_bits != 0)
- events = EPOLLIN | EPOLLRDNORM;
+ return EPOLLIN | EPOLLRDNORM;
else
- events = 0;
- spin_unlock_irq(&dice->lock);
-
- return events;
+ return 0;
}
static int hwdep_get_info(struct snd_dice *dice, void __user *arg)
@@ -90,48 +86,35 @@ static int hwdep_get_info(struct snd_dice *dice, void __user *arg)
static int hwdep_lock(struct snd_dice *dice)
{
- int err;
-
- spin_lock_irq(&dice->lock);
+ guard(spinlock_irq)(&dice->lock);
if (dice->dev_lock_count == 0) {
dice->dev_lock_count = -1;
- err = 0;
+ return 0;
} else {
- err = -EBUSY;
+ return -EBUSY;
}
-
- spin_unlock_irq(&dice->lock);
-
- return err;
}
static int hwdep_unlock(struct snd_dice *dice)
{
- int err;
-
- spin_lock_irq(&dice->lock);
+ guard(spinlock_irq)(&dice->lock);
if (dice->dev_lock_count == -1) {
dice->dev_lock_count = 0;
- err = 0;
+ return 0;
} else {
- err = -EBADFD;
+ return -EBADFD;
}
-
- spin_unlock_irq(&dice->lock);
-
- return err;
}
static int hwdep_release(struct snd_hwdep *hwdep, struct file *file)
{
struct snd_dice *dice = hwdep->private_data;
- spin_lock_irq(&dice->lock);
+ guard(spinlock_irq)(&dice->lock);
if (dice->dev_lock_count == -1)
dice->dev_lock_count = 0;
- spin_unlock_irq(&dice->lock);
return 0;
}
diff --git a/sound/firewire/dice/dice-midi.c b/sound/firewire/dice/dice-midi.c
index 9ca975c556ca..722bce379345 100644
--- a/sound/firewire/dice/dice-midi.c
+++ b/sound/firewire/dice/dice-midi.c
@@ -47,9 +47,8 @@ static int midi_close(struct snd_rawmidi_substream *substream)
static void midi_capture_trigger(struct snd_rawmidi_substream *substrm, int up)
{
struct snd_dice *dice = substrm->rmidi->private_data;
- unsigned long flags;
- spin_lock_irqsave(&dice->lock, flags);
+ guard(spinlock_irqsave)(&dice->lock);
if (up)
amdtp_am824_midi_trigger(&dice->tx_stream[0],
@@ -57,16 +56,13 @@ static void midi_capture_trigger(struct snd_rawmidi_substream *substrm, int up)
else
amdtp_am824_midi_trigger(&dice->tx_stream[0],
substrm->number, NULL);
-
- spin_unlock_irqrestore(&dice->lock, flags);
}
static void midi_playback_trigger(struct snd_rawmidi_substream *substrm, int up)
{
struct snd_dice *dice = substrm->rmidi->private_data;
- unsigned long flags;
- spin_lock_irqsave(&dice->lock, flags);
+ guard(spinlock_irqsave)(&dice->lock);
if (up)
amdtp_am824_midi_trigger(&dice->rx_stream[0],
@@ -74,8 +70,6 @@ static void midi_playback_trigger(struct snd_rawmidi_substream *substrm, int up)
else
amdtp_am824_midi_trigger(&dice->rx_stream[0],
substrm->number, NULL);
-
- spin_unlock_irqrestore(&dice->lock, flags);
}
static void set_midi_substream_names(struct snd_dice *dice,
diff --git a/sound/firewire/dice/dice-stream.c b/sound/firewire/dice/dice-stream.c
index 4c677c8546c7..d5ffe7c82993 100644
--- a/sound/firewire/dice/dice-stream.c
+++ b/sound/firewire/dice/dice-stream.c
@@ -677,32 +677,23 @@ static void dice_lock_changed(struct snd_dice *dice)
int snd_dice_stream_lock_try(struct snd_dice *dice)
{
- int err;
+ guard(spinlock_irq)(&dice->lock);
- spin_lock_irq(&dice->lock);
-
- if (dice->dev_lock_count < 0) {
- err = -EBUSY;
- goto out;
- }
+ if (dice->dev_lock_count < 0)
+ return -EBUSY;
if (dice->dev_lock_count++ == 0)
dice_lock_changed(dice);
- err = 0;
-out:
- spin_unlock_irq(&dice->lock);
- return err;
+ return 0;
}
void snd_dice_stream_lock_release(struct snd_dice *dice)
{
- spin_lock_irq(&dice->lock);
+ guard(spinlock_irq)(&dice->lock);
if (WARN_ON(dice->dev_lock_count <= 0))
- goto out;
+ return;
if (--dice->dev_lock_count == 0)
dice_lock_changed(dice);
-out:
- spin_unlock_irq(&dice->lock);
}
diff --git a/sound/firewire/dice/dice-transaction.c b/sound/firewire/dice/dice-transaction.c
index 92941ef83cd5..a3f7dfa990a4 100644
--- a/sound/firewire/dice/dice-transaction.c
+++ b/sound/firewire/dice/dice-transaction.c
@@ -136,7 +136,6 @@ static void dice_notification(struct fw_card *card, struct fw_request *request,
{
struct snd_dice *dice = callback_data;
u32 bits;
- unsigned long flags;
if (tcode != TCODE_WRITE_QUADLET_REQUEST) {
fw_send_response(card, request, RCODE_TYPE_ERROR);
@@ -149,9 +148,9 @@ static void dice_notification(struct fw_card *card, struct fw_request *request,
bits = be32_to_cpup(data);
- spin_lock_irqsave(&dice->lock, flags);
- dice->notification_bits |= bits;
- spin_unlock_irqrestore(&dice->lock, flags);
+ scoped_guard(spinlock_irqsave, &dice->lock) {
+ dice->notification_bits |= bits;
+ }
fw_send_response(card, request, RCODE_COMPLETE);
--
2.50.1
^ permalink raw reply related [flat|nested] 22+ messages in thread
* [PATCH 13/19] ALSA: firewire: digi00x: Use guard() for spin locks
2025-08-27 9:19 [PATCH 00/19] ALSA: firewire: Use auto-cleanup macros Takashi Iwai
` (11 preceding siblings ...)
2025-08-27 9:20 ` [PATCH 12/19] ALSA: firewire: dice: " Takashi Iwai
@ 2025-08-27 9:20 ` Takashi Iwai
2025-08-27 9:20 ` [PATCH 14/19] ALSA: firewire: fireface: " Takashi Iwai
` (6 subsequent siblings)
19 siblings, 0 replies; 22+ messages in thread
From: Takashi Iwai @ 2025-08-27 9:20 UTC (permalink / raw)
To: linux-sound; +Cc: Takashi Sakamoto, Clemens Ladisch
Clean up the code using guard() for spin locks.
Merely code refactoring, and no behavior change.
Signed-off-by: Takashi Iwai <tiwai@suse.de>
---
sound/firewire/digi00x/digi00x-hwdep.c | 37 ++++++--------------
sound/firewire/digi00x/digi00x-midi.c | 10 ++----
sound/firewire/digi00x/digi00x-stream.c | 21 ++++-------
sound/firewire/digi00x/digi00x-transaction.c | 8 ++---
4 files changed, 21 insertions(+), 55 deletions(-)
diff --git a/sound/firewire/digi00x/digi00x-hwdep.c b/sound/firewire/digi00x/digi00x-hwdep.c
index b150607c0a0d..435d18417cf0 100644
--- a/sound/firewire/digi00x/digi00x-hwdep.c
+++ b/sound/firewire/digi00x/digi00x-hwdep.c
@@ -63,18 +63,14 @@ static __poll_t hwdep_poll(struct snd_hwdep *hwdep, struct file *file,
poll_table *wait)
{
struct snd_dg00x *dg00x = hwdep->private_data;
- __poll_t events;
poll_wait(file, &dg00x->hwdep_wait, wait);
- spin_lock_irq(&dg00x->lock);
+ guard(spinlock_irq)(&dg00x->lock);
if (dg00x->dev_lock_changed || dg00x->msg)
- events = EPOLLIN | EPOLLRDNORM;
+ return EPOLLIN | EPOLLRDNORM;
else
- events = 0;
- spin_unlock_irq(&dg00x->lock);
-
- return events;
+ return 0;
}
static int hwdep_get_info(struct snd_dg00x *dg00x, void __user *arg)
@@ -98,48 +94,35 @@ static int hwdep_get_info(struct snd_dg00x *dg00x, void __user *arg)
static int hwdep_lock(struct snd_dg00x *dg00x)
{
- int err;
-
- spin_lock_irq(&dg00x->lock);
+ guard(spinlock_irq)(&dg00x->lock);
if (dg00x->dev_lock_count == 0) {
dg00x->dev_lock_count = -1;
- err = 0;
+ return 0;
} else {
- err = -EBUSY;
+ return -EBUSY;
}
-
- spin_unlock_irq(&dg00x->lock);
-
- return err;
}
static int hwdep_unlock(struct snd_dg00x *dg00x)
{
- int err;
-
- spin_lock_irq(&dg00x->lock);
+ guard(spinlock_irq)(&dg00x->lock);
if (dg00x->dev_lock_count == -1) {
dg00x->dev_lock_count = 0;
- err = 0;
+ return 0;
} else {
- err = -EBADFD;
+ return -EBADFD;
}
-
- spin_unlock_irq(&dg00x->lock);
-
- return err;
}
static int hwdep_release(struct snd_hwdep *hwdep, struct file *file)
{
struct snd_dg00x *dg00x = hwdep->private_data;
- spin_lock_irq(&dg00x->lock);
+ guard(spinlock_irq)(&dg00x->lock);
if (dg00x->dev_lock_count == -1)
dg00x->dev_lock_count = 0;
- spin_unlock_irq(&dg00x->lock);
return 0;
}
diff --git a/sound/firewire/digi00x/digi00x-midi.c b/sound/firewire/digi00x/digi00x-midi.c
index 0f6ca58cc4a0..bcdaf003514b 100644
--- a/sound/firewire/digi00x/digi00x-midi.c
+++ b/sound/firewire/digi00x/digi00x-midi.c
@@ -49,21 +49,18 @@ static void midi_capture_trigger(struct snd_rawmidi_substream *substream,
{
struct snd_dg00x *dg00x = substream->rmidi->private_data;
unsigned int port;
- unsigned long flags;
if (substream->rmidi->device == 0)
port = substream->number;
else
port = 2;
- spin_lock_irqsave(&dg00x->lock, flags);
+ guard(spinlock_irqsave)(&dg00x->lock);
if (up)
amdtp_dot_midi_trigger(&dg00x->tx_stream, port, substream);
else
amdtp_dot_midi_trigger(&dg00x->tx_stream, port, NULL);
-
- spin_unlock_irqrestore(&dg00x->lock, flags);
}
static void midi_playback_trigger(struct snd_rawmidi_substream *substream,
@@ -71,21 +68,18 @@ static void midi_playback_trigger(struct snd_rawmidi_substream *substream,
{
struct snd_dg00x *dg00x = substream->rmidi->private_data;
unsigned int port;
- unsigned long flags;
if (substream->rmidi->device == 0)
port = substream->number;
else
port = 2;
- spin_lock_irqsave(&dg00x->lock, flags);
+ guard(spinlock_irqsave)(&dg00x->lock);
if (up)
amdtp_dot_midi_trigger(&dg00x->rx_stream, port, substream);
else
amdtp_dot_midi_trigger(&dg00x->rx_stream, port, NULL);
-
- spin_unlock_irqrestore(&dg00x->lock, flags);
}
static void set_substream_names(struct snd_dg00x *dg00x,
diff --git a/sound/firewire/digi00x/digi00x-stream.c b/sound/firewire/digi00x/digi00x-stream.c
index 295163bb8abb..250ffdb26ebd 100644
--- a/sound/firewire/digi00x/digi00x-stream.c
+++ b/sound/firewire/digi00x/digi00x-stream.c
@@ -427,33 +427,24 @@ void snd_dg00x_stream_lock_changed(struct snd_dg00x *dg00x)
int snd_dg00x_stream_lock_try(struct snd_dg00x *dg00x)
{
- int err;
-
- spin_lock_irq(&dg00x->lock);
+ guard(spinlock_irq)(&dg00x->lock);
/* user land lock this */
- if (dg00x->dev_lock_count < 0) {
- err = -EBUSY;
- goto end;
- }
+ if (dg00x->dev_lock_count < 0)
+ return -EBUSY;
/* this is the first time */
if (dg00x->dev_lock_count++ == 0)
snd_dg00x_stream_lock_changed(dg00x);
- err = 0;
-end:
- spin_unlock_irq(&dg00x->lock);
- return err;
+ return 0;
}
void snd_dg00x_stream_lock_release(struct snd_dg00x *dg00x)
{
- spin_lock_irq(&dg00x->lock);
+ guard(spinlock_irq)(&dg00x->lock);
if (WARN_ON(dg00x->dev_lock_count <= 0))
- goto end;
+ return;
if (--dg00x->dev_lock_count == 0)
snd_dg00x_stream_lock_changed(dg00x);
-end:
- spin_unlock_irq(&dg00x->lock);
}
diff --git a/sound/firewire/digi00x/digi00x-transaction.c b/sound/firewire/digi00x/digi00x-transaction.c
index cf0bcf1c5956..8a1667159930 100644
--- a/sound/firewire/digi00x/digi00x-transaction.c
+++ b/sound/firewire/digi00x/digi00x-transaction.c
@@ -11,11 +11,9 @@
static void handle_unknown_message(struct snd_dg00x *dg00x,
unsigned long long offset, __be32 *buf)
{
- unsigned long flags;
-
- spin_lock_irqsave(&dg00x->lock, flags);
- dg00x->msg = be32_to_cpu(*buf);
- spin_unlock_irqrestore(&dg00x->lock, flags);
+ scoped_guard(spinlock_irqsave, &dg00x->lock) {
+ dg00x->msg = be32_to_cpu(*buf);
+ }
wake_up(&dg00x->hwdep_wait);
}
--
2.50.1
^ permalink raw reply related [flat|nested] 22+ messages in thread
* [PATCH 14/19] ALSA: firewire: fireface: Use guard() for spin locks
2025-08-27 9:19 [PATCH 00/19] ALSA: firewire: Use auto-cleanup macros Takashi Iwai
` (12 preceding siblings ...)
2025-08-27 9:20 ` [PATCH 13/19] ALSA: firewire: digi00x: " Takashi Iwai
@ 2025-08-27 9:20 ` Takashi Iwai
2025-08-27 9:20 ` [PATCH 15/19] ALSA: firewire: fireworks: " Takashi Iwai
` (5 subsequent siblings)
19 siblings, 0 replies; 22+ messages in thread
From: Takashi Iwai @ 2025-08-27 9:20 UTC (permalink / raw)
To: linux-sound; +Cc: Takashi Sakamoto, Clemens Ladisch
Clean up the code using guard() for spin locks.
Merely code refactoring, and no behavior change.
Signed-off-by: Takashi Iwai <tiwai@suse.de>
---
sound/firewire/fireface/ff-hwdep.c | 37 +++++++-----------------
sound/firewire/fireface/ff-midi.c | 10 ++-----
sound/firewire/fireface/ff-stream.c | 21 ++++----------
sound/firewire/fireface/ff-transaction.c | 4 +--
4 files changed, 19 insertions(+), 53 deletions(-)
diff --git a/sound/firewire/fireface/ff-hwdep.c b/sound/firewire/fireface/ff-hwdep.c
index ca5c5dee71f2..5976abf2e1ab 100644
--- a/sound/firewire/fireface/ff-hwdep.c
+++ b/sound/firewire/fireface/ff-hwdep.c
@@ -72,18 +72,14 @@ static __poll_t hwdep_poll(struct snd_hwdep *hwdep, struct file *file,
poll_table *wait)
{
struct snd_ff *ff = hwdep->private_data;
- __poll_t events;
poll_wait(file, &ff->hwdep_wait, wait);
- spin_lock_irq(&ff->lock);
+ guard(spinlock_irq)(&ff->lock);
if (ff->dev_lock_changed || has_msg(ff))
- events = EPOLLIN | EPOLLRDNORM;
+ return EPOLLIN | EPOLLRDNORM;
else
- events = 0;
- spin_unlock_irq(&ff->lock);
-
- return events;
+ return 0;
}
static int hwdep_get_info(struct snd_ff *ff, void __user *arg)
@@ -107,48 +103,35 @@ static int hwdep_get_info(struct snd_ff *ff, void __user *arg)
static int hwdep_lock(struct snd_ff *ff)
{
- int err;
-
- spin_lock_irq(&ff->lock);
+ guard(spinlock_irq)(&ff->lock);
if (ff->dev_lock_count == 0) {
ff->dev_lock_count = -1;
- err = 0;
+ return 0;
} else {
- err = -EBUSY;
+ return -EBUSY;
}
-
- spin_unlock_irq(&ff->lock);
-
- return err;
}
static int hwdep_unlock(struct snd_ff *ff)
{
- int err;
-
- spin_lock_irq(&ff->lock);
+ guard(spinlock_irq)(&ff->lock);
if (ff->dev_lock_count == -1) {
ff->dev_lock_count = 0;
- err = 0;
+ return 0;
} else {
- err = -EBADFD;
+ return -EBADFD;
}
-
- spin_unlock_irq(&ff->lock);
-
- return err;
}
static int hwdep_release(struct snd_hwdep *hwdep, struct file *file)
{
struct snd_ff *ff = hwdep->private_data;
- spin_lock_irq(&ff->lock);
+ guard(spinlock_irq)(&ff->lock);
if (ff->dev_lock_count == -1)
ff->dev_lock_count = 0;
- spin_unlock_irq(&ff->lock);
return 0;
}
diff --git a/sound/firewire/fireface/ff-midi.c b/sound/firewire/fireface/ff-midi.c
index da3054fdcc7d..9f6aa490e5bf 100644
--- a/sound/firewire/fireface/ff-midi.c
+++ b/sound/firewire/fireface/ff-midi.c
@@ -46,31 +46,25 @@ static void midi_capture_trigger(struct snd_rawmidi_substream *substream,
int up)
{
struct snd_ff *ff = substream->rmidi->private_data;
- unsigned long flags;
- spin_lock_irqsave(&ff->lock, flags);
+ guard(spinlock_irqsave)(&ff->lock);
if (up)
WRITE_ONCE(ff->tx_midi_substreams[substream->number],
substream);
else
WRITE_ONCE(ff->tx_midi_substreams[substream->number], NULL);
-
- spin_unlock_irqrestore(&ff->lock, flags);
}
static void midi_playback_trigger(struct snd_rawmidi_substream *substream,
int up)
{
struct snd_ff *ff = substream->rmidi->private_data;
- unsigned long flags;
- spin_lock_irqsave(&ff->lock, flags);
+ guard(spinlock_irqsave)(&ff->lock);
if (up || !ff->rx_midi_error[substream->number])
schedule_work(&ff->rx_midi_work[substream->number]);
-
- spin_unlock_irqrestore(&ff->lock, flags);
}
static void set_midi_substream_names(struct snd_rawmidi_str *stream,
diff --git a/sound/firewire/fireface/ff-stream.c b/sound/firewire/fireface/ff-stream.c
index 95bf405adb3d..ba42490f2b0e 100644
--- a/sound/firewire/fireface/ff-stream.c
+++ b/sound/firewire/fireface/ff-stream.c
@@ -253,33 +253,24 @@ void snd_ff_stream_lock_changed(struct snd_ff *ff)
int snd_ff_stream_lock_try(struct snd_ff *ff)
{
- int err;
-
- spin_lock_irq(&ff->lock);
+ guard(spinlock_irq)(&ff->lock);
/* user land lock this */
- if (ff->dev_lock_count < 0) {
- err = -EBUSY;
- goto end;
- }
+ if (ff->dev_lock_count < 0)
+ return -EBUSY;
/* this is the first time */
if (ff->dev_lock_count++ == 0)
snd_ff_stream_lock_changed(ff);
- err = 0;
-end:
- spin_unlock_irq(&ff->lock);
- return err;
+ return 0;
}
void snd_ff_stream_lock_release(struct snd_ff *ff)
{
- spin_lock_irq(&ff->lock);
+ guard(spinlock_irq)(&ff->lock);
if (WARN_ON(ff->dev_lock_count <= 0))
- goto end;
+ return;
if (--ff->dev_lock_count == 0)
snd_ff_stream_lock_changed(ff);
-end:
- spin_unlock_irq(&ff->lock);
}
diff --git a/sound/firewire/fireface/ff-transaction.c b/sound/firewire/fireface/ff-transaction.c
index 6b89e39f4a43..436da0a3bdcc 100644
--- a/sound/firewire/fireface/ff-transaction.c
+++ b/sound/firewire/fireface/ff-transaction.c
@@ -132,15 +132,13 @@ static void handle_msg(struct fw_card *card, struct fw_request *request, int tco
struct snd_ff *ff = callback_data;
__le32 *buf = data;
u32 tstamp = fw_request_get_timestamp(request);
- unsigned long flag;
fw_send_response(card, request, RCODE_COMPLETE);
offset -= ff->async_handler.offset;
- spin_lock_irqsave(&ff->lock, flag);
+ guard(spinlock_irqsave)(&ff->lock);
ff->spec->protocol->handle_msg(ff, (unsigned int)offset, buf, length, tstamp);
- spin_unlock_irqrestore(&ff->lock, flag);
}
static int allocate_own_address(struct snd_ff *ff, int i)
--
2.50.1
^ permalink raw reply related [flat|nested] 22+ messages in thread
* [PATCH 15/19] ALSA: firewire: fireworks: Use guard() for spin locks
2025-08-27 9:19 [PATCH 00/19] ALSA: firewire: Use auto-cleanup macros Takashi Iwai
` (13 preceding siblings ...)
2025-08-27 9:20 ` [PATCH 14/19] ALSA: firewire: fireface: " Takashi Iwai
@ 2025-08-27 9:20 ` Takashi Iwai
2025-08-27 9:20 ` [PATCH 16/19] ALSA: firewire: motu: " Takashi Iwai
` (4 subsequent siblings)
19 siblings, 0 replies; 22+ messages in thread
From: Takashi Iwai @ 2025-08-27 9:20 UTC (permalink / raw)
To: linux-sound; +Cc: Takashi Sakamoto, Clemens Ladisch
Clean up the code using guard() for spin locks.
Merely code refactoring, and no behavior change.
Signed-off-by: Takashi Iwai <tiwai@suse.de>
---
sound/firewire/fireworks/fireworks_command.c | 16 ++++----
sound/firewire/fireworks/fireworks_hwdep.c | 41 ++++++-------------
sound/firewire/fireworks/fireworks_midi.c | 10 +----
sound/firewire/fireworks/fireworks_stream.c | 21 +++-------
.../fireworks/fireworks_transaction.c | 39 +++++++-----------
5 files changed, 42 insertions(+), 85 deletions(-)
diff --git a/sound/firewire/fireworks/fireworks_command.c b/sound/firewire/fireworks/fireworks_command.c
index 7e255fc2c6e4..2b595ee0bc35 100644
--- a/sound/firewire/fireworks/fireworks_command.c
+++ b/sound/firewire/fireworks/fireworks_command.c
@@ -119,14 +119,14 @@ efw_transaction(struct snd_efw *efw, unsigned int category,
return -ENOMEM;
/* to keep consistency of sequence number */
- spin_lock(&efw->lock);
- if ((efw->seqnum < KERNEL_SEQNUM_MIN) ||
- (efw->seqnum >= KERNEL_SEQNUM_MAX - 2))
- efw->seqnum = KERNEL_SEQNUM_MIN;
- else
- efw->seqnum += 2;
- seqnum = efw->seqnum;
- spin_unlock(&efw->lock);
+ scoped_guard(spinlock, &efw->lock) {
+ if ((efw->seqnum < KERNEL_SEQNUM_MIN) ||
+ (efw->seqnum >= KERNEL_SEQNUM_MAX - 2))
+ efw->seqnum = KERNEL_SEQNUM_MIN;
+ else
+ efw->seqnum += 2;
+ seqnum = efw->seqnum;
+ }
/* fill transaction header fields */
cmd_bytes = sizeof(struct snd_efw_transaction) + param_bytes;
diff --git a/sound/firewire/fireworks/fireworks_hwdep.c b/sound/firewire/fireworks/fireworks_hwdep.c
index 037833cd066e..7d6bd8ceeab3 100644
--- a/sound/firewire/fireworks/fireworks_hwdep.c
+++ b/sound/firewire/fireworks/fireworks_hwdep.c
@@ -103,12 +103,10 @@ hwdep_read_locked(struct snd_efw *efw, char __user *buf, long count,
.lock_status.type = SNDRV_FIREWIRE_EVENT_LOCK_STATUS,
};
- spin_lock_irq(&efw->lock);
-
- event.lock_status.status = (efw->dev_lock_count > 0);
- efw->dev_lock_changed = false;
-
- spin_unlock_irq(&efw->lock);
+ scoped_guard(spinlock_irq, &efw->lock) {
+ event.lock_status.status = (efw->dev_lock_count > 0);
+ efw->dev_lock_changed = false;
+ }
count = min_t(long, count, sizeof(event.lock_status));
@@ -192,13 +190,11 @@ hwdep_poll(struct snd_hwdep *hwdep, struct file *file, poll_table *wait)
poll_wait(file, &efw->hwdep_wait, wait);
- spin_lock_irq(&efw->lock);
+ guard(spinlock_irq)(&efw->lock);
if (efw->dev_lock_changed || efw->pull_ptr != efw->push_ptr)
events = EPOLLIN | EPOLLRDNORM;
else
events = 0;
- spin_unlock_irq(&efw->lock);
-
return events | EPOLLOUT;
}
@@ -225,39 +221,27 @@ hwdep_get_info(struct snd_efw *efw, void __user *arg)
static int
hwdep_lock(struct snd_efw *efw)
{
- int err;
-
- spin_lock_irq(&efw->lock);
+ guard(spinlock_irq)(&efw->lock);
if (efw->dev_lock_count == 0) {
efw->dev_lock_count = -1;
- err = 0;
+ return 0;
} else {
- err = -EBUSY;
+ return -EBUSY;
}
-
- spin_unlock_irq(&efw->lock);
-
- return err;
}
static int
hwdep_unlock(struct snd_efw *efw)
{
- int err;
-
- spin_lock_irq(&efw->lock);
+ guard(spinlock_irq)(&efw->lock);
if (efw->dev_lock_count == -1) {
efw->dev_lock_count = 0;
- err = 0;
+ return 0;
} else {
- err = -EBADFD;
+ return -EBADFD;
}
-
- spin_unlock_irq(&efw->lock);
-
- return err;
}
static int
@@ -265,10 +249,9 @@ hwdep_release(struct snd_hwdep *hwdep, struct file *file)
{
struct snd_efw *efw = hwdep->private_data;
- spin_lock_irq(&efw->lock);
+ guard(spinlock_irq)(&efw->lock);
if (efw->dev_lock_count == -1)
efw->dev_lock_count = 0;
- spin_unlock_irq(&efw->lock);
return 0;
}
diff --git a/sound/firewire/fireworks/fireworks_midi.c b/sound/firewire/fireworks/fireworks_midi.c
index 90fe809a26c0..405106a6aef9 100644
--- a/sound/firewire/fireworks/fireworks_midi.c
+++ b/sound/firewire/fireworks/fireworks_midi.c
@@ -46,9 +46,8 @@ static int midi_close(struct snd_rawmidi_substream *substream)
static void midi_capture_trigger(struct snd_rawmidi_substream *substrm, int up)
{
struct snd_efw *efw = substrm->rmidi->private_data;
- unsigned long flags;
- spin_lock_irqsave(&efw->lock, flags);
+ guard(spinlock_irqsave)(&efw->lock);
if (up)
amdtp_am824_midi_trigger(&efw->tx_stream,
@@ -56,16 +55,13 @@ static void midi_capture_trigger(struct snd_rawmidi_substream *substrm, int up)
else
amdtp_am824_midi_trigger(&efw->tx_stream,
substrm->number, NULL);
-
- spin_unlock_irqrestore(&efw->lock, flags);
}
static void midi_playback_trigger(struct snd_rawmidi_substream *substrm, int up)
{
struct snd_efw *efw = substrm->rmidi->private_data;
- unsigned long flags;
- spin_lock_irqsave(&efw->lock, flags);
+ guard(spinlock_irqsave)(&efw->lock);
if (up)
amdtp_am824_midi_trigger(&efw->rx_stream,
@@ -73,8 +69,6 @@ static void midi_playback_trigger(struct snd_rawmidi_substream *substrm, int up)
else
amdtp_am824_midi_trigger(&efw->rx_stream,
substrm->number, NULL);
-
- spin_unlock_irqrestore(&efw->lock, flags);
}
static void set_midi_substream_names(struct snd_efw *efw,
diff --git a/sound/firewire/fireworks/fireworks_stream.c b/sound/firewire/fireworks/fireworks_stream.c
index 53dbd4d4b0d0..974084e1c083 100644
--- a/sound/firewire/fireworks/fireworks_stream.c
+++ b/sound/firewire/fireworks/fireworks_stream.c
@@ -345,33 +345,24 @@ void snd_efw_stream_lock_changed(struct snd_efw *efw)
int snd_efw_stream_lock_try(struct snd_efw *efw)
{
- int err;
-
- spin_lock_irq(&efw->lock);
+ guard(spinlock_irq)(&efw->lock);
/* user land lock this */
- if (efw->dev_lock_count < 0) {
- err = -EBUSY;
- goto end;
- }
+ if (efw->dev_lock_count < 0)
+ return -EBUSY;
/* this is the first time */
if (efw->dev_lock_count++ == 0)
snd_efw_stream_lock_changed(efw);
- err = 0;
-end:
- spin_unlock_irq(&efw->lock);
- return err;
+ return 0;
}
void snd_efw_stream_lock_release(struct snd_efw *efw)
{
- spin_lock_irq(&efw->lock);
+ guard(spinlock_irq)(&efw->lock);
if (WARN_ON(efw->dev_lock_count <= 0))
- goto end;
+ return;
if (--efw->dev_lock_count == 0)
snd_efw_stream_lock_changed(efw);
-end:
- spin_unlock_irq(&efw->lock);
}
diff --git a/sound/firewire/fireworks/fireworks_transaction.c b/sound/firewire/fireworks/fireworks_transaction.c
index 9f8c53b39f95..5c859773fe06 100644
--- a/sound/firewire/fireworks/fireworks_transaction.c
+++ b/sound/firewire/fireworks/fireworks_transaction.c
@@ -82,9 +82,9 @@ int snd_efw_transaction_run(struct fw_unit *unit,
t.state = STATE_PENDING;
init_waitqueue_head(&t.wait);
- spin_lock_irq(&transaction_queues_lock);
- list_add_tail(&t.list, &transaction_queues);
- spin_unlock_irq(&transaction_queues_lock);
+ scoped_guard(spinlock_irq, &transaction_queues_lock) {
+ list_add_tail(&t.list, &transaction_queues);
+ }
tries = 0;
do {
@@ -107,9 +107,9 @@ int snd_efw_transaction_run(struct fw_unit *unit,
}
} while (1);
- spin_lock_irq(&transaction_queues_lock);
- list_del(&t.list);
- spin_unlock_irq(&transaction_queues_lock);
+ scoped_guard(spinlock_irq, &transaction_queues_lock) {
+ list_del(&t.list);
+ }
return ret;
}
@@ -123,7 +123,7 @@ copy_resp_to_buf(struct snd_efw *efw, void *data, size_t length, int *rcode)
t = (struct snd_efw_transaction *)data;
length = min_t(size_t, be32_to_cpu(t->length) * sizeof(u32), length);
- spin_lock(&efw->lock);
+ guard(spinlock)(&efw->lock);
if (efw->push_ptr < efw->pull_ptr)
capacity = (unsigned int)(efw->pull_ptr - efw->push_ptr);
@@ -134,7 +134,7 @@ copy_resp_to_buf(struct snd_efw *efw, void *data, size_t length, int *rcode)
/* confirm enough space for this response */
if (capacity < length) {
*rcode = RCODE_CONFLICT_ERROR;
- goto end;
+ return;
}
/* copy to ring buffer */
@@ -157,8 +157,6 @@ copy_resp_to_buf(struct snd_efw *efw, void *data, size_t length, int *rcode)
wake_up(&efw->hwdep_wait);
*rcode = RCODE_COMPLETE;
-end:
- spin_unlock_irq(&efw->lock);
}
static void
@@ -169,7 +167,7 @@ handle_resp_for_user(struct fw_card *card, int generation, int source,
struct snd_efw *efw;
unsigned int i;
- spin_lock_irq(&instances_lock);
+ guard(spinlock_irq)(&instances_lock);
for (i = 0; i < SNDRV_CARDS; i++) {
efw = instances[i];
@@ -186,11 +184,9 @@ handle_resp_for_user(struct fw_card *card, int generation, int source,
break;
}
if (i == SNDRV_CARDS)
- goto end;
+ return;
copy_resp_to_buf(efw, data, length, rcode);
-end:
- spin_unlock(&instances_lock);
}
static void
@@ -199,9 +195,8 @@ handle_resp_for_kernel(struct fw_card *card, int generation, int source,
{
struct fw_device *device;
struct transaction_queue *t;
- unsigned long flags;
- spin_lock_irqsave(&transaction_queues_lock, flags);
+ guard(spinlock_irqsave)(&transaction_queues_lock);
list_for_each_entry(t, &transaction_queues, list) {
device = fw_parent_device(t->unit);
if ((device->card != card) ||
@@ -219,7 +214,6 @@ handle_resp_for_kernel(struct fw_card *card, int generation, int source,
*rcode = RCODE_COMPLETE;
}
}
- spin_unlock_irqrestore(&transaction_queues_lock, flags);
}
static void
@@ -259,7 +253,7 @@ void snd_efw_transaction_add_instance(struct snd_efw *efw)
{
unsigned int i;
- spin_lock_irq(&instances_lock);
+ guard(spinlock_irq)(&instances_lock);
for (i = 0; i < SNDRV_CARDS; i++) {
if (instances[i] != NULL)
@@ -267,30 +261,26 @@ void snd_efw_transaction_add_instance(struct snd_efw *efw)
instances[i] = efw;
break;
}
-
- spin_unlock_irq(&instances_lock);
}
void snd_efw_transaction_remove_instance(struct snd_efw *efw)
{
unsigned int i;
- spin_lock_irq(&instances_lock);
+ guard(spinlock_irq)(&instances_lock);
for (i = 0; i < SNDRV_CARDS; i++) {
if (instances[i] != efw)
continue;
instances[i] = NULL;
}
-
- spin_unlock_irq(&instances_lock);
}
void snd_efw_transaction_bus_reset(struct fw_unit *unit)
{
struct transaction_queue *t;
- spin_lock_irq(&transaction_queues_lock);
+ guard(spinlock_irq)(&transaction_queues_lock);
list_for_each_entry(t, &transaction_queues, list) {
if ((t->unit == unit) &&
(t->state == STATE_PENDING)) {
@@ -298,7 +288,6 @@ void snd_efw_transaction_bus_reset(struct fw_unit *unit)
wake_up(&t->wait);
}
}
- spin_unlock_irq(&transaction_queues_lock);
}
static struct fw_address_handler resp_register_handler = {
--
2.50.1
^ permalink raw reply related [flat|nested] 22+ messages in thread
* [PATCH 16/19] ALSA: firewire: motu: Use guard() for spin locks
2025-08-27 9:19 [PATCH 00/19] ALSA: firewire: Use auto-cleanup macros Takashi Iwai
` (14 preceding siblings ...)
2025-08-27 9:20 ` [PATCH 15/19] ALSA: firewire: fireworks: " Takashi Iwai
@ 2025-08-27 9:20 ` Takashi Iwai
2025-08-27 9:20 ` [PATCH 17/19] ALSA: firewire: oxfw: " Takashi Iwai
` (3 subsequent siblings)
19 siblings, 0 replies; 22+ messages in thread
From: Takashi Iwai @ 2025-08-27 9:20 UTC (permalink / raw)
To: linux-sound; +Cc: Takashi Sakamoto, Clemens Ladisch
Clean up the code using guard() for spin locks.
Merely code refactoring, and no behavior change.
Signed-off-by: Takashi Iwai <tiwai@suse.de>
---
.../motu/motu-command-dsp-message-parser.c | 9 ++----
sound/firewire/motu/motu-hwdep.c | 30 +++++--------------
sound/firewire/motu/motu-midi.c | 10 ++-----
.../motu/motu-register-dsp-message-parser.c | 18 +++--------
sound/firewire/motu/motu-stream.c | 21 ++++---------
sound/firewire/motu/motu-transaction.c | 7 ++---
6 files changed, 25 insertions(+), 70 deletions(-)
diff --git a/sound/firewire/motu/motu-command-dsp-message-parser.c b/sound/firewire/motu/motu-command-dsp-message-parser.c
index 5d8a86a12f1f..c6440e6e360b 100644
--- a/sound/firewire/motu/motu-command-dsp-message-parser.c
+++ b/sound/firewire/motu/motu-command-dsp-message-parser.c
@@ -87,10 +87,9 @@ void snd_motu_command_dsp_message_parser_parse(const struct amdtp_stream *s,
unsigned int data_block_quadlets = s->data_block_quadlets;
struct msg_parser *parser = motu->message_parser;
unsigned int interval = parser->interval;
- unsigned long flags;
int i;
- spin_lock_irqsave(&parser->lock, flags);
+ guard(spinlock_irqsave)(&parser->lock);
for (i = 0; i < count; ++i) {
__be32 *buffer = desc->ctx_payload;
@@ -168,17 +167,13 @@ void snd_motu_command_dsp_message_parser_parse(const struct amdtp_stream *s,
}
}
}
-
- spin_unlock_irqrestore(&parser->lock, flags);
}
void snd_motu_command_dsp_message_parser_copy_meter(struct snd_motu *motu,
struct snd_firewire_motu_command_dsp_meter *meter)
{
struct msg_parser *parser = motu->message_parser;
- unsigned long flags;
- spin_lock_irqsave(&parser->lock, flags);
+ guard(spinlock_irqsave)(&parser->lock);
memcpy(meter, &parser->meter, sizeof(*meter));
- spin_unlock_irqrestore(&parser->lock, flags);
}
diff --git a/sound/firewire/motu/motu-hwdep.c b/sound/firewire/motu/motu-hwdep.c
index 1ed60618220d..e0ce1e8703f5 100644
--- a/sound/firewire/motu/motu-hwdep.c
+++ b/sound/firewire/motu/motu-hwdep.c
@@ -104,12 +104,11 @@ static __poll_t hwdep_poll(struct snd_hwdep *hwdep, struct file *file,
poll_wait(file, &motu->hwdep_wait, wait);
- spin_lock_irq(&motu->lock);
+ guard(spinlock_irq)(&motu->lock);
if (motu->dev_lock_changed || motu->msg || has_dsp_event(motu))
events = EPOLLIN | EPOLLRDNORM;
else
events = 0;
- spin_unlock_irq(&motu->lock);
return events | EPOLLOUT;
}
@@ -135,48 +134,35 @@ static int hwdep_get_info(struct snd_motu *motu, void __user *arg)
static int hwdep_lock(struct snd_motu *motu)
{
- int err;
-
- spin_lock_irq(&motu->lock);
+ guard(spinlock_irq)(&motu->lock);
if (motu->dev_lock_count == 0) {
motu->dev_lock_count = -1;
- err = 0;
+ return 0;
} else {
- err = -EBUSY;
+ return -EBUSY;
}
-
- spin_unlock_irq(&motu->lock);
-
- return err;
}
static int hwdep_unlock(struct snd_motu *motu)
{
- int err;
-
- spin_lock_irq(&motu->lock);
+ guard(spinlock_irq)(&motu->lock);
if (motu->dev_lock_count == -1) {
motu->dev_lock_count = 0;
- err = 0;
+ return 0;
} else {
- err = -EBADFD;
+ return -EBADFD;
}
-
- spin_unlock_irq(&motu->lock);
-
- return err;
}
static int hwdep_release(struct snd_hwdep *hwdep, struct file *file)
{
struct snd_motu *motu = hwdep->private_data;
- spin_lock_irq(&motu->lock);
+ guard(spinlock_irq)(&motu->lock);
if (motu->dev_lock_count == -1)
motu->dev_lock_count = 0;
- spin_unlock_irq(&motu->lock);
return 0;
}
diff --git a/sound/firewire/motu/motu-midi.c b/sound/firewire/motu/motu-midi.c
index 18c5734e999f..85e3260f9349 100644
--- a/sound/firewire/motu/motu-midi.c
+++ b/sound/firewire/motu/motu-midi.c
@@ -47,9 +47,8 @@ static int midi_close(struct snd_rawmidi_substream *substream)
static void midi_capture_trigger(struct snd_rawmidi_substream *substrm, int up)
{
struct snd_motu *motu = substrm->rmidi->private_data;
- unsigned long flags;
- spin_lock_irqsave(&motu->lock, flags);
+ guard(spinlock_irqsave)(&motu->lock);
if (up)
amdtp_motu_midi_trigger(&motu->tx_stream, substrm->number,
@@ -57,16 +56,13 @@ static void midi_capture_trigger(struct snd_rawmidi_substream *substrm, int up)
else
amdtp_motu_midi_trigger(&motu->tx_stream, substrm->number,
NULL);
-
- spin_unlock_irqrestore(&motu->lock, flags);
}
static void midi_playback_trigger(struct snd_rawmidi_substream *substrm, int up)
{
struct snd_motu *motu = substrm->rmidi->private_data;
- unsigned long flags;
- spin_lock_irqsave(&motu->lock, flags);
+ guard(spinlock_irqsave)(&motu->lock);
if (up)
amdtp_motu_midi_trigger(&motu->rx_stream, substrm->number,
@@ -74,8 +70,6 @@ static void midi_playback_trigger(struct snd_rawmidi_substream *substrm, int up)
else
amdtp_motu_midi_trigger(&motu->rx_stream, substrm->number,
NULL);
-
- spin_unlock_irqrestore(&motu->lock, flags);
}
static void set_midi_substream_names(struct snd_motu *motu,
diff --git a/sound/firewire/motu/motu-register-dsp-message-parser.c b/sound/firewire/motu/motu-register-dsp-message-parser.c
index ef3b0b0f0dab..a8053e3ef065 100644
--- a/sound/firewire/motu/motu-register-dsp-message-parser.c
+++ b/sound/firewire/motu/motu-register-dsp-message-parser.c
@@ -150,10 +150,9 @@ void snd_motu_register_dsp_message_parser_parse(const struct amdtp_stream *s,
struct msg_parser *parser = motu->message_parser;
bool meter_pos_quirk = parser->meter_pos_quirk;
unsigned int pos = parser->push_pos;
- unsigned long flags;
int i;
- spin_lock_irqsave(&parser->lock, flags);
+ guard(spinlock_irqsave)(&parser->lock);
for (i = 0; i < count; ++i) {
__be32 *buffer = desc->ctx_payload;
@@ -363,30 +362,24 @@ void snd_motu_register_dsp_message_parser_parse(const struct amdtp_stream *s,
if (pos != parser->push_pos)
wake_up(&motu->hwdep_wait);
-
- spin_unlock_irqrestore(&parser->lock, flags);
}
void snd_motu_register_dsp_message_parser_copy_meter(struct snd_motu *motu,
struct snd_firewire_motu_register_dsp_meter *meter)
{
struct msg_parser *parser = motu->message_parser;
- unsigned long flags;
- spin_lock_irqsave(&parser->lock, flags);
+ guard(spinlock_irqsave)(&parser->lock);
memcpy(meter, &parser->meter, sizeof(*meter));
- spin_unlock_irqrestore(&parser->lock, flags);
}
void snd_motu_register_dsp_message_parser_copy_parameter(struct snd_motu *motu,
struct snd_firewire_motu_register_dsp_parameter *param)
{
struct msg_parser *parser = motu->message_parser;
- unsigned long flags;
- spin_lock_irqsave(&parser->lock, flags);
+ guard(spinlock_irqsave)(&parser->lock);
memcpy(param, &parser->param, sizeof(*param));
- spin_unlock_irqrestore(&parser->lock, flags);
}
unsigned int snd_motu_register_dsp_message_parser_count_event(struct snd_motu *motu)
@@ -403,12 +396,11 @@ bool snd_motu_register_dsp_message_parser_copy_event(struct snd_motu *motu, u32
{
struct msg_parser *parser = motu->message_parser;
unsigned int pos = parser->pull_pos;
- unsigned long flags;
if (pos == parser->push_pos)
return false;
- spin_lock_irqsave(&parser->lock, flags);
+ guard(spinlock_irqsave)(&parser->lock);
*event = parser->event_queue[pos];
@@ -417,7 +409,5 @@ bool snd_motu_register_dsp_message_parser_copy_event(struct snd_motu *motu, u32
pos = 0;
parser->pull_pos = pos;
- spin_unlock_irqrestore(&parser->lock, flags);
-
return true;
}
diff --git a/sound/firewire/motu/motu-stream.c b/sound/firewire/motu/motu-stream.c
index 64aec9c3eefd..e5f21360cfb7 100644
--- a/sound/firewire/motu/motu-stream.c
+++ b/sound/firewire/motu/motu-stream.c
@@ -407,32 +407,23 @@ static void motu_lock_changed(struct snd_motu *motu)
int snd_motu_stream_lock_try(struct snd_motu *motu)
{
- int err;
+ guard(spinlock_irq)(&motu->lock);
- spin_lock_irq(&motu->lock);
-
- if (motu->dev_lock_count < 0) {
- err = -EBUSY;
- goto out;
- }
+ if (motu->dev_lock_count < 0)
+ return -EBUSY;
if (motu->dev_lock_count++ == 0)
motu_lock_changed(motu);
- err = 0;
-out:
- spin_unlock_irq(&motu->lock);
- return err;
+ return 0;
}
void snd_motu_stream_lock_release(struct snd_motu *motu)
{
- spin_lock_irq(&motu->lock);
+ guard(spinlock_irq)(&motu->lock);
if (WARN_ON(motu->dev_lock_count <= 0))
- goto out;
+ return;
if (--motu->dev_lock_count == 0)
motu_lock_changed(motu);
-out:
- spin_unlock_irq(&motu->lock);
}
diff --git a/sound/firewire/motu/motu-transaction.c b/sound/firewire/motu/motu-transaction.c
index 2dc1d6e59144..804f4208cf81 100644
--- a/sound/firewire/motu/motu-transaction.c
+++ b/sound/firewire/motu/motu-transaction.c
@@ -51,7 +51,6 @@ static void handle_message(struct fw_card *card, struct fw_request *request,
{
struct snd_motu *motu = callback_data;
__be32 *buf = (__be32 *)data;
- unsigned long flags;
if (tcode != TCODE_WRITE_QUADLET_REQUEST) {
fw_send_response(card, request, RCODE_COMPLETE);
@@ -63,9 +62,9 @@ static void handle_message(struct fw_card *card, struct fw_request *request,
return;
}
- spin_lock_irqsave(&motu->lock, flags);
- motu->msg = be32_to_cpu(*buf);
- spin_unlock_irqrestore(&motu->lock, flags);
+ scoped_guard(spinlock_irqsave, &motu->lock) {
+ motu->msg = be32_to_cpu(*buf);
+ }
fw_send_response(card, request, RCODE_COMPLETE);
--
2.50.1
^ permalink raw reply related [flat|nested] 22+ messages in thread
* [PATCH 17/19] ALSA: firewire: oxfw: Use guard() for spin locks
2025-08-27 9:19 [PATCH 00/19] ALSA: firewire: Use auto-cleanup macros Takashi Iwai
` (15 preceding siblings ...)
2025-08-27 9:20 ` [PATCH 16/19] ALSA: firewire: motu: " Takashi Iwai
@ 2025-08-27 9:20 ` Takashi Iwai
2025-08-27 9:20 ` [PATCH 18/19] ALSA: firewire: tascam: " Takashi Iwai
` (2 subsequent siblings)
19 siblings, 0 replies; 22+ messages in thread
From: Takashi Iwai @ 2025-08-27 9:20 UTC (permalink / raw)
To: linux-sound; +Cc: Takashi Sakamoto, Clemens Ladisch
Clean up the code using guard() for spin locks.
Merely code refactoring, and no behavior change.
Signed-off-by: Takashi Iwai <tiwai@suse.de>
---
sound/firewire/oxfw/oxfw-hwdep.c | 37 +++++++++----------------------
sound/firewire/oxfw/oxfw-midi.c | 10 ++-------
sound/firewire/oxfw/oxfw-stream.c | 21 +++++-------------
3 files changed, 18 insertions(+), 50 deletions(-)
diff --git a/sound/firewire/oxfw/oxfw-hwdep.c b/sound/firewire/oxfw/oxfw-hwdep.c
index 3be214d8a922..f8ac362fc73a 100644
--- a/sound/firewire/oxfw/oxfw-hwdep.c
+++ b/sound/firewire/oxfw/oxfw-hwdep.c
@@ -53,18 +53,14 @@ static __poll_t hwdep_poll(struct snd_hwdep *hwdep, struct file *file,
poll_table *wait)
{
struct snd_oxfw *oxfw = hwdep->private_data;
- __poll_t events;
poll_wait(file, &oxfw->hwdep_wait, wait);
- spin_lock_irq(&oxfw->lock);
+ guard(spinlock_irq)(&oxfw->lock);
if (oxfw->dev_lock_changed)
- events = EPOLLIN | EPOLLRDNORM;
+ return EPOLLIN | EPOLLRDNORM;
else
- events = 0;
- spin_unlock_irq(&oxfw->lock);
-
- return events;
+ return 0;
}
static int hwdep_get_info(struct snd_oxfw *oxfw, void __user *arg)
@@ -88,48 +84,35 @@ static int hwdep_get_info(struct snd_oxfw *oxfw, void __user *arg)
static int hwdep_lock(struct snd_oxfw *oxfw)
{
- int err;
-
- spin_lock_irq(&oxfw->lock);
+ guard(spinlock_irq)(&oxfw->lock);
if (oxfw->dev_lock_count == 0) {
oxfw->dev_lock_count = -1;
- err = 0;
+ return 0;
} else {
- err = -EBUSY;
+ return -EBUSY;
}
-
- spin_unlock_irq(&oxfw->lock);
-
- return err;
}
static int hwdep_unlock(struct snd_oxfw *oxfw)
{
- int err;
-
- spin_lock_irq(&oxfw->lock);
+ guard(spinlock_irq)(&oxfw->lock);
if (oxfw->dev_lock_count == -1) {
oxfw->dev_lock_count = 0;
- err = 0;
+ return 0;
} else {
- err = -EBADFD;
+ return -EBADFD;
}
-
- spin_unlock_irq(&oxfw->lock);
-
- return err;
}
static int hwdep_release(struct snd_hwdep *hwdep, struct file *file)
{
struct snd_oxfw *oxfw = hwdep->private_data;
- spin_lock_irq(&oxfw->lock);
+ guard(spinlock_irq)(&oxfw->lock);
if (oxfw->dev_lock_count == -1)
oxfw->dev_lock_count = 0;
- spin_unlock_irq(&oxfw->lock);
return 0;
}
diff --git a/sound/firewire/oxfw/oxfw-midi.c b/sound/firewire/oxfw/oxfw-midi.c
index 7f757f02a877..a16bf885f918 100644
--- a/sound/firewire/oxfw/oxfw-midi.c
+++ b/sound/firewire/oxfw/oxfw-midi.c
@@ -84,9 +84,8 @@ static int midi_playback_close(struct snd_rawmidi_substream *substream)
static void midi_capture_trigger(struct snd_rawmidi_substream *substrm, int up)
{
struct snd_oxfw *oxfw = substrm->rmidi->private_data;
- unsigned long flags;
- spin_lock_irqsave(&oxfw->lock, flags);
+ guard(spinlock_irqsave)(&oxfw->lock);
if (up)
amdtp_am824_midi_trigger(&oxfw->tx_stream,
@@ -94,16 +93,13 @@ static void midi_capture_trigger(struct snd_rawmidi_substream *substrm, int up)
else
amdtp_am824_midi_trigger(&oxfw->tx_stream,
substrm->number, NULL);
-
- spin_unlock_irqrestore(&oxfw->lock, flags);
}
static void midi_playback_trigger(struct snd_rawmidi_substream *substrm, int up)
{
struct snd_oxfw *oxfw = substrm->rmidi->private_data;
- unsigned long flags;
- spin_lock_irqsave(&oxfw->lock, flags);
+ guard(spinlock_irqsave)(&oxfw->lock);
if (up)
amdtp_am824_midi_trigger(&oxfw->rx_stream,
@@ -111,8 +107,6 @@ static void midi_playback_trigger(struct snd_rawmidi_substream *substrm, int up)
else
amdtp_am824_midi_trigger(&oxfw->rx_stream,
substrm->number, NULL);
-
- spin_unlock_irqrestore(&oxfw->lock, flags);
}
static void set_midi_substream_names(struct snd_oxfw *oxfw,
diff --git a/sound/firewire/oxfw/oxfw-stream.c b/sound/firewire/oxfw/oxfw-stream.c
index 00f7feb91f92..5e36d7153a7b 100644
--- a/sound/firewire/oxfw/oxfw-stream.c
+++ b/sound/firewire/oxfw/oxfw-stream.c
@@ -866,33 +866,24 @@ void snd_oxfw_stream_lock_changed(struct snd_oxfw *oxfw)
int snd_oxfw_stream_lock_try(struct snd_oxfw *oxfw)
{
- int err;
-
- spin_lock_irq(&oxfw->lock);
+ guard(spinlock_irq)(&oxfw->lock);
/* user land lock this */
- if (oxfw->dev_lock_count < 0) {
- err = -EBUSY;
- goto end;
- }
+ if (oxfw->dev_lock_count < 0)
+ return -EBUSY;
/* this is the first time */
if (oxfw->dev_lock_count++ == 0)
snd_oxfw_stream_lock_changed(oxfw);
- err = 0;
-end:
- spin_unlock_irq(&oxfw->lock);
- return err;
+ return 0;
}
void snd_oxfw_stream_lock_release(struct snd_oxfw *oxfw)
{
- spin_lock_irq(&oxfw->lock);
+ guard(spinlock_irq)(&oxfw->lock);
if (WARN_ON(oxfw->dev_lock_count <= 0))
- goto end;
+ return;
if (--oxfw->dev_lock_count == 0)
snd_oxfw_stream_lock_changed(oxfw);
-end:
- spin_unlock_irq(&oxfw->lock);
}
--
2.50.1
^ permalink raw reply related [flat|nested] 22+ messages in thread
* [PATCH 18/19] ALSA: firewire: tascam: Use guard() for spin locks
2025-08-27 9:19 [PATCH 00/19] ALSA: firewire: Use auto-cleanup macros Takashi Iwai
` (16 preceding siblings ...)
2025-08-27 9:20 ` [PATCH 17/19] ALSA: firewire: oxfw: " Takashi Iwai
@ 2025-08-27 9:20 ` 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
19 siblings, 0 replies; 22+ messages in thread
From: Takashi Iwai @ 2025-08-27 9:20 UTC (permalink / raw)
To: linux-sound; +Cc: Takashi Sakamoto, Clemens Ladisch
Clean up the code using guard() for spin locks.
Merely code refactoring, and no behavior change.
Signed-off-by: Takashi Iwai <tiwai@suse.de>
---
sound/firewire/tascam/amdtp-tascam.c | 15 +++++------
sound/firewire/tascam/tascam-hwdep.c | 37 ++++++++-------------------
sound/firewire/tascam/tascam-midi.c | 10 ++------
sound/firewire/tascam/tascam-stream.c | 21 +++++----------
4 files changed, 25 insertions(+), 58 deletions(-)
diff --git a/sound/firewire/tascam/amdtp-tascam.c b/sound/firewire/tascam/amdtp-tascam.c
index 079afa4bd381..59c339d9b5fb 100644
--- a/sound/firewire/tascam/amdtp-tascam.c
+++ b/sound/firewire/tascam/amdtp-tascam.c
@@ -157,15 +157,14 @@ static void read_status_messages(struct amdtp_stream *s,
if ((before ^ after) & mask) {
struct snd_firewire_tascam_change *entry =
&tscm->queue[tscm->push_pos];
- unsigned long flag;
- spin_lock_irqsave(&tscm->lock, flag);
- entry->index = index;
- entry->before = before;
- entry->after = after;
- if (++tscm->push_pos >= SND_TSCM_QUEUE_COUNT)
- tscm->push_pos = 0;
- spin_unlock_irqrestore(&tscm->lock, flag);
+ scoped_guard(spinlock_irqsave, &tscm->lock) {
+ entry->index = index;
+ entry->before = before;
+ entry->after = after;
+ if (++tscm->push_pos >= SND_TSCM_QUEUE_COUNT)
+ tscm->push_pos = 0;
+ }
wake_up(&tscm->hwdep_wait);
}
diff --git a/sound/firewire/tascam/tascam-hwdep.c b/sound/firewire/tascam/tascam-hwdep.c
index 8fc30cba29d5..867b4ea1096e 100644
--- a/sound/firewire/tascam/tascam-hwdep.c
+++ b/sound/firewire/tascam/tascam-hwdep.c
@@ -130,18 +130,14 @@ static __poll_t hwdep_poll(struct snd_hwdep *hwdep, struct file *file,
poll_table *wait)
{
struct snd_tscm *tscm = hwdep->private_data;
- __poll_t events;
poll_wait(file, &tscm->hwdep_wait, wait);
- spin_lock_irq(&tscm->lock);
+ guard(spinlock_irq)(&tscm->lock);
if (tscm->dev_lock_changed || tscm->push_pos != tscm->pull_pos)
- events = EPOLLIN | EPOLLRDNORM;
+ return EPOLLIN | EPOLLRDNORM;
else
- events = 0;
- spin_unlock_irq(&tscm->lock);
-
- return events;
+ return 0;
}
static int hwdep_get_info(struct snd_tscm *tscm, void __user *arg)
@@ -165,38 +161,26 @@ static int hwdep_get_info(struct snd_tscm *tscm, void __user *arg)
static int hwdep_lock(struct snd_tscm *tscm)
{
- int err;
-
- spin_lock_irq(&tscm->lock);
+ guard(spinlock_irq)(&tscm->lock);
if (tscm->dev_lock_count == 0) {
tscm->dev_lock_count = -1;
- err = 0;
+ return 0;
} else {
- err = -EBUSY;
+ return -EBUSY;
}
-
- spin_unlock_irq(&tscm->lock);
-
- return err;
}
static int hwdep_unlock(struct snd_tscm *tscm)
{
- int err;
-
- spin_lock_irq(&tscm->lock);
+ guard(spinlock_irq)(&tscm->lock);
if (tscm->dev_lock_count == -1) {
tscm->dev_lock_count = 0;
- err = 0;
+ return 0;
} else {
- err = -EBADFD;
+ return -EBADFD;
}
-
- spin_unlock_irq(&tscm->lock);
-
- return err;
}
static int tscm_hwdep_state(struct snd_tscm *tscm, void __user *arg)
@@ -211,10 +195,9 @@ static int hwdep_release(struct snd_hwdep *hwdep, struct file *file)
{
struct snd_tscm *tscm = hwdep->private_data;
- spin_lock_irq(&tscm->lock);
+ guard(spinlock_irq)(&tscm->lock);
if (tscm->dev_lock_count == -1)
tscm->dev_lock_count = 0;
- spin_unlock_irq(&tscm->lock);
return 0;
}
diff --git a/sound/firewire/tascam/tascam-midi.c b/sound/firewire/tascam/tascam-midi.c
index c57fac4f1968..1bf9d7b3da33 100644
--- a/sound/firewire/tascam/tascam-midi.c
+++ b/sound/firewire/tascam/tascam-midi.c
@@ -43,30 +43,24 @@ static void midi_playback_drain(struct snd_rawmidi_substream *substream)
static void midi_capture_trigger(struct snd_rawmidi_substream *substrm, int up)
{
struct snd_tscm *tscm = substrm->rmidi->private_data;
- unsigned long flags;
- spin_lock_irqsave(&tscm->lock, flags);
+ guard(spinlock_irqsave)(&tscm->lock);
if (up)
tscm->tx_midi_substreams[substrm->number] = substrm;
else
tscm->tx_midi_substreams[substrm->number] = NULL;
-
- spin_unlock_irqrestore(&tscm->lock, flags);
}
static void midi_playback_trigger(struct snd_rawmidi_substream *substrm, int up)
{
struct snd_tscm *tscm = substrm->rmidi->private_data;
- unsigned long flags;
- spin_lock_irqsave(&tscm->lock, flags);
+ guard(spinlock_irqsave)(&tscm->lock);
if (up)
snd_fw_async_midi_port_run(&tscm->out_ports[substrm->number],
substrm);
-
- spin_unlock_irqrestore(&tscm->lock, flags);
}
int snd_tscm_create_midi_devices(struct snd_tscm *tscm)
diff --git a/sound/firewire/tascam/tascam-stream.c b/sound/firewire/tascam/tascam-stream.c
index dfe783d01d7d..9c8fddd7dee1 100644
--- a/sound/firewire/tascam/tascam-stream.c
+++ b/sound/firewire/tascam/tascam-stream.c
@@ -527,33 +527,24 @@ void snd_tscm_stream_lock_changed(struct snd_tscm *tscm)
int snd_tscm_stream_lock_try(struct snd_tscm *tscm)
{
- int err;
-
- spin_lock_irq(&tscm->lock);
+ guard(spinlock_irq)(&tscm->lock);
/* user land lock this */
- if (tscm->dev_lock_count < 0) {
- err = -EBUSY;
- goto end;
- }
+ if (tscm->dev_lock_count < 0)
+ return -EBUSY;
/* this is the first time */
if (tscm->dev_lock_count++ == 0)
snd_tscm_stream_lock_changed(tscm);
- err = 0;
-end:
- spin_unlock_irq(&tscm->lock);
- return err;
+ return 0;
}
void snd_tscm_stream_lock_release(struct snd_tscm *tscm)
{
- spin_lock_irq(&tscm->lock);
+ guard(spinlock_irq)(&tscm->lock);
if (WARN_ON(tscm->dev_lock_count <= 0))
- goto end;
+ return;
if (--tscm->dev_lock_count == 0)
snd_tscm_stream_lock_changed(tscm);
-end:
- spin_unlock_irq(&tscm->lock);
}
--
2.50.1
^ permalink raw reply related [flat|nested] 22+ messages in thread
* [PATCH 19/19] ALSA: firewire: lib: Use guard() for spin locks
2025-08-27 9:19 [PATCH 00/19] ALSA: firewire: Use auto-cleanup macros Takashi Iwai
` (17 preceding siblings ...)
2025-08-27 9:20 ` [PATCH 18/19] ALSA: firewire: tascam: " Takashi Iwai
@ 2025-08-27 9:20 ` Takashi Iwai
2025-08-28 12:56 ` [PATCH 00/19] ALSA: firewire: Use auto-cleanup macros Takashi Sakamoto
19 siblings, 0 replies; 22+ messages in thread
From: Takashi Iwai @ 2025-08-27 9:20 UTC (permalink / raw)
To: linux-sound; +Cc: Takashi Sakamoto, Clemens Ladisch
Clean up the code using guard() for spin locks.
Merely code refactoring, and no behavior change.
Signed-off-by: Takashi Iwai <tiwai@suse.de>
---
sound/firewire/fcp.c | 19 ++++++++-----------
sound/firewire/iso-resources.c | 16 ++++++++--------
2 files changed, 16 insertions(+), 19 deletions(-)
diff --git a/sound/firewire/fcp.c b/sound/firewire/fcp.c
index df44dd5dc4b2..e60bfd0ee4ac 100644
--- a/sound/firewire/fcp.c
+++ b/sound/firewire/fcp.c
@@ -242,9 +242,9 @@ int fcp_avc_transaction(struct fw_unit *unit,
init_waitqueue_head(&t.wait);
t.deferrable = (*(const u8 *)command == 0x00 || *(const u8 *)command == 0x03);
- spin_lock_irq(&transactions_lock);
- list_add_tail(&t.list, &transactions);
- spin_unlock_irq(&transactions_lock);
+ scoped_guard(spinlock_irq, &transactions_lock) {
+ list_add_tail(&t.list, &transactions);
+ }
for (;;) {
tcode = command_size == 4 ? TCODE_WRITE_QUADLET_REQUEST
@@ -280,9 +280,9 @@ int fcp_avc_transaction(struct fw_unit *unit,
}
}
- spin_lock_irq(&transactions_lock);
- list_del(&t.list);
- spin_unlock_irq(&transactions_lock);
+ scoped_guard(spinlock_irq, &transactions_lock) {
+ list_del(&t.list);
+ }
return ret;
}
@@ -300,7 +300,7 @@ void fcp_bus_reset(struct fw_unit *unit)
{
struct fcp_transaction *t;
- spin_lock_irq(&transactions_lock);
+ guard(spinlock_irq)(&transactions_lock);
list_for_each_entry(t, &transactions, list) {
if (t->unit == unit &&
(t->state == STATE_PENDING ||
@@ -309,7 +309,6 @@ void fcp_bus_reset(struct fw_unit *unit)
wake_up(&t->wait);
}
}
- spin_unlock_irq(&transactions_lock);
}
EXPORT_SYMBOL(fcp_bus_reset);
@@ -341,12 +340,11 @@ static void fcp_response(struct fw_card *card, struct fw_request *request,
void *data, size_t length, void *callback_data)
{
struct fcp_transaction *t;
- unsigned long flags;
if (length < 1 || (*(const u8 *)data & 0xf0) != CTS_AVC)
return;
- spin_lock_irqsave(&transactions_lock, flags);
+ guard(spinlock_irqsave)(&transactions_lock);
list_for_each_entry(t, &transactions, list) {
struct fw_device *device = fw_parent_device(t->unit);
if (device->card != card ||
@@ -370,7 +368,6 @@ static void fcp_response(struct fw_card *card, struct fw_request *request,
wake_up(&t->wait);
}
}
- spin_unlock_irqrestore(&transactions_lock, flags);
}
static struct fw_address_handler response_register_handler = {
diff --git a/sound/firewire/iso-resources.c b/sound/firewire/iso-resources.c
index b47ee029d688..4f63279225c5 100644
--- a/sound/firewire/iso-resources.c
+++ b/sound/firewire/iso-resources.c
@@ -114,10 +114,10 @@ int fw_iso_resources_allocate(struct fw_iso_resources *r,
r->bandwidth = packet_bandwidth(max_payload_bytes, speed);
retry_after_bus_reset:
- spin_lock_irq(&card->lock);
- r->generation = card->generation;
- r->bandwidth_overhead = current_bandwidth_overhead(card);
- spin_unlock_irq(&card->lock);
+ scoped_guard(spinlock_irq, &card->lock) {
+ r->generation = card->generation;
+ r->bandwidth_overhead = current_bandwidth_overhead(card);
+ }
err = wait_isoch_resource_delay_after_bus_reset(card);
if (err < 0)
@@ -167,10 +167,10 @@ int fw_iso_resources_update(struct fw_iso_resources *r)
if (!r->allocated)
return 0;
- spin_lock_irq(&card->lock);
- r->generation = card->generation;
- r->bandwidth_overhead = current_bandwidth_overhead(card);
- spin_unlock_irq(&card->lock);
+ scoped_guard(spinlock_irq, &card->lock) {
+ r->generation = card->generation;
+ r->bandwidth_overhead = current_bandwidth_overhead(card);
+ }
bandwidth = r->bandwidth + r->bandwidth_overhead;
--
2.50.1
^ permalink raw reply related [flat|nested] 22+ messages in thread
* Re: [PATCH 00/19] ALSA: firewire: Use auto-cleanup macros
2025-08-27 9:19 [PATCH 00/19] ALSA: firewire: Use auto-cleanup macros Takashi Iwai
` (18 preceding siblings ...)
2025-08-27 9:20 ` [PATCH 19/19] ALSA: firewire: lib: " Takashi Iwai
@ 2025-08-28 12:56 ` Takashi Sakamoto
2025-08-28 13:23 ` Takashi Iwai
19 siblings, 1 reply; 22+ messages in thread
From: Takashi Sakamoto @ 2025-08-28 12:56 UTC (permalink / raw)
To: Takashi Iwai; +Cc: linux-sound, Clemens Ladisch
Hi,
On Wed, Aug 27, 2025 at 11:19:54AM +0200, Takashi Iwai wrote:
> This is another patch set for cleaning up the code with the recent
> auto-cleanup macros like guard() & co, applied to FireWire sound
> drivers.
>
> Only code refactoring, and no behavior changes intended.
>
>
> Takashi
Thanks for the patchset. I have the similar series in my local, but not
yet completed. The patchset mostly looks good to me, but I can find
some nitpickings.
> ===
>
> Takashi Iwai (19):
> ALSA: firewire: bebob: Use guard() for mutex locks
> ALSA: firewire: dice: Use guard() for mutex locks
> ALSA: firewire: Use guard() for mutex locks
The patch title misses 'digi00x: '.
> ALSA: firewire: fireworks: Use guard() for mutex locks
> ALSA: firewire: motu: Use guard() for mutex locks
> ALSA: firewire: oxfw: Use guard() for mutex locks
> ALSA: firewire: tascam: Use guard() for mutex locks
> ALSA: firewire: fireface: Use guard() for mutex locks
> ALSA: firewire: isight: Use guard() for mutex locks
> ALSA: firewire: lib: Use guard() for mutex locks
> ALSA: firewire: bebob: Use guard() for spin locks
> ALSA: firewire: dice: Use guard() for spin locks
> ALSA: firewire: digi00x: Use guard() for spin locks
> ALSA: firewire: fireface: Use guard() for spin locks
> ALSA: firewire: fireworks: Use guard() for spin locks
> ALSA: firewire: motu: Use guard() for spin locks
> ALSA: firewire: oxfw: Use guard() for spin locks
> ALSA: firewire: tascam: Use guard() for spin locks
> ALSA: firewire: lib: Use guard() for spin locks
In my opinion, 'scoped_guard()' is available without blaces when the
inner component is just one line, however the above patches include
such lines. Additionally, some parts of scoped_guard() are followed by
useless blank line.
$ git grep -n -A2 scoped_guard sound/firewire/dice/dice-pcm.c
sound/firewire/dice/dice-pcm.c:199: scoped_guard(mutex, &dice->mutex) {
sound/firewire/dice/dice-pcm.c-200-
sound/firewire/dice/dice-pcm.c-201- // When source of clock is not internal or any stream is reserved for
--
sound/firewire/dice/dice-pcm.c:302: scoped_guard(mutex, &dice->mutex) {
sound/firewire/dice/dice-pcm.c-303- err = snd_dice_stream_start_duplex(dice);
sound/firewire/dice/dice-pcm.c-304- }
--
sound/firewire/dice/dice-pcm.c:316: scoped_guard(mutex, &dice->mutex) {
sound/firewire/dice/dice-pcm.c-317- err = snd_dice_stream_start_duplex(dice);
sound/firewire/dice/dice-pcm.c-318- }
Thanks
Takashi Sakamoto
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: [PATCH 00/19] ALSA: firewire: Use auto-cleanup macros
2025-08-28 12:56 ` [PATCH 00/19] ALSA: firewire: Use auto-cleanup macros Takashi Sakamoto
@ 2025-08-28 13:23 ` Takashi Iwai
0 siblings, 0 replies; 22+ messages in thread
From: Takashi Iwai @ 2025-08-28 13:23 UTC (permalink / raw)
To: Takashi Sakamoto; +Cc: Takashi Iwai, linux-sound, Clemens Ladisch
On Thu, 28 Aug 2025 14:56:23 +0200,
Takashi Sakamoto wrote:
>
> > Takashi Iwai (19):
> > ALSA: firewire: bebob: Use guard() for mutex locks
> > ALSA: firewire: dice: Use guard() for mutex locks
> > ALSA: firewire: Use guard() for mutex locks
>
> The patch title misses 'digi00x: '.
OK, will fix.
> > ALSA: firewire: fireworks: Use guard() for mutex locks
> > ALSA: firewire: motu: Use guard() for mutex locks
> > ALSA: firewire: oxfw: Use guard() for mutex locks
> > ALSA: firewire: tascam: Use guard() for mutex locks
> > ALSA: firewire: fireface: Use guard() for mutex locks
> > ALSA: firewire: isight: Use guard() for mutex locks
> > ALSA: firewire: lib: Use guard() for mutex locks
> > ALSA: firewire: bebob: Use guard() for spin locks
> > ALSA: firewire: dice: Use guard() for spin locks
> > ALSA: firewire: digi00x: Use guard() for spin locks
> > ALSA: firewire: fireface: Use guard() for spin locks
> > ALSA: firewire: fireworks: Use guard() for spin locks
> > ALSA: firewire: motu: Use guard() for spin locks
> > ALSA: firewire: oxfw: Use guard() for spin locks
> > ALSA: firewire: tascam: Use guard() for spin locks
> > ALSA: firewire: lib: Use guard() for spin locks
>
> In my opinion, 'scoped_guard()' is available without blaces when the
> inner component is just one line, however the above patches include
> such lines. Additionally, some parts of scoped_guard() are followed by
> useless blank line.
OK, will fix in v2, too.
thanks,
Takashi
^ permalink raw reply [flat|nested] 22+ messages in thread
end of thread, other threads:[~2025-08-28 13:23 UTC | newest]
Thread overview: 22+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 ` [PATCH 03/19] ALSA: firewire: " Takashi Iwai
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
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).