linux-sound.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Takashi Iwai <tiwai@suse.de>
To: linux-sound@vger.kernel.org
Subject: [PATCH 24/61] ALSA: echoaudio: Use guard() for mutex locks
Date: Fri, 29 Aug 2025 16:42:59 +0200	[thread overview]
Message-ID: <20250829144342.4290-25-tiwai@suse.de> (raw)
In-Reply-To: <20250829144342.4290-1-tiwai@suse.de>

Replace the manual mutex lock/unlock pairs with guard() for code
simplification.

Only code refactoring, and no behavior change.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
---
 sound/pci/echoaudio/echoaudio.c | 36 +++++++++++++--------------------
 1 file changed, 14 insertions(+), 22 deletions(-)

diff --git a/sound/pci/echoaudio/echoaudio.c b/sound/pci/echoaudio/echoaudio.c
index 2b33ef588ac3..4cfe8ad97069 100644
--- a/sound/pci/echoaudio/echoaudio.c
+++ b/sound/pci/echoaudio/echoaudio.c
@@ -237,7 +237,7 @@ static int hw_rule_sample_rate(struct snd_pcm_hw_params *params,
 	struct snd_interval fixed;
 	int err;
 
-	mutex_lock(&chip->mode_mutex);
+	guard(mutex)(&chip->mode_mutex);
 
 	if (chip->can_set_rate) {
 		err = 0;
@@ -247,7 +247,6 @@ static int hw_rule_sample_rate(struct snd_pcm_hw_params *params,
 		err = snd_interval_refine(rate, &fixed);
 	}
 
-	mutex_unlock(&chip->mode_mutex);
 	return err;
 }
 
@@ -415,7 +414,7 @@ static int pcm_digital_in_open(struct snd_pcm_substream *substream)
 	int err, max_channels;
 
 	max_channels = num_digital_busses_in(chip) - substream->number;
-	mutex_lock(&chip->mode_mutex);
+	guard(mutex)(&chip->mode_mutex);
 	if (chip->digital_mode == DIGITAL_MODE_ADAT)
 		err = pcm_open(substream, max_channels);
 	else	/* If the card has ADAT, subtract the 6 channels
@@ -424,24 +423,22 @@ static int pcm_digital_in_open(struct snd_pcm_substream *substream)
 		err = pcm_open(substream, max_channels - ECHOCARD_HAS_ADAT);
 
 	if (err < 0)
-		goto din_exit;
+		return err;
 
 	err = snd_pcm_hw_rule_add(substream->runtime, 0,
 				  SNDRV_PCM_HW_PARAM_CHANNELS,
 				  hw_rule_capture_channels_by_format, NULL,
 				  SNDRV_PCM_HW_PARAM_FORMAT, -1);
 	if (err < 0)
-		goto din_exit;
+		return err;
 	err = snd_pcm_hw_rule_add(substream->runtime, 0,
 				  SNDRV_PCM_HW_PARAM_FORMAT,
 				  hw_rule_capture_format_by_channels, NULL,
 				  SNDRV_PCM_HW_PARAM_CHANNELS, -1);
 	if (err < 0)
-		goto din_exit;
+		return err;
 
-din_exit:
-	mutex_unlock(&chip->mode_mutex);
-	return err;
+	return 0;
 }
 
 
@@ -454,7 +451,7 @@ static int pcm_digital_out_open(struct snd_pcm_substream *substream)
 	int err, max_channels;
 
 	max_channels = num_digital_busses_out(chip) - substream->number;
-	mutex_lock(&chip->mode_mutex);
+	guard(mutex)(&chip->mode_mutex);
 	if (chip->digital_mode == DIGITAL_MODE_ADAT)
 		err = pcm_open(substream, max_channels);
 	else	/* If the card has ADAT, subtract the 6 channels
@@ -463,7 +460,7 @@ static int pcm_digital_out_open(struct snd_pcm_substream *substream)
 		err = pcm_open(substream, max_channels - ECHOCARD_HAS_ADAT);
 
 	if (err < 0)
-		goto dout_exit;
+		return err;
 
 	err = snd_pcm_hw_rule_add(substream->runtime, 0,
 				  SNDRV_PCM_HW_PARAM_CHANNELS,
@@ -471,18 +468,16 @@ static int pcm_digital_out_open(struct snd_pcm_substream *substream)
 				  NULL, SNDRV_PCM_HW_PARAM_FORMAT,
 				  -1);
 	if (err < 0)
-		goto dout_exit;
+		return err;
 	err = snd_pcm_hw_rule_add(substream->runtime, 0,
 				  SNDRV_PCM_HW_PARAM_FORMAT,
 				  hw_rule_playback_format_by_channels,
 				  NULL, SNDRV_PCM_HW_PARAM_CHANNELS,
 				  -1);
 	if (err < 0)
-		goto dout_exit;
+		return err;
 
-dout_exit:
-	mutex_unlock(&chip->mode_mutex);
-	return err;
+	return 0;
 }
 
 #endif /* !ECHOCARD_HAS_VMIXER */
@@ -499,7 +494,7 @@ static int pcm_close(struct snd_pcm_substream *substream)
 	 * freed by its callback
 	 */
 
-	mutex_lock(&chip->mode_mutex);
+	guard(mutex)(&chip->mode_mutex);
 
 	dev_dbg(chip->card->dev, "pcm_open opencount=%d can_set_rate=%d, rate_set=%d",
 		chip->opencount, chip->can_set_rate, chip->rate_set);
@@ -516,7 +511,6 @@ static int pcm_close(struct snd_pcm_substream *substream)
 		break;
 	}
 
-	mutex_unlock(&chip->mode_mutex);
 	return 0;
 }
 
@@ -1440,7 +1434,7 @@ static int snd_echo_digital_mode_put(struct snd_kcontrol *kcontrol,
 	if (dmode != chip->digital_mode) {
 		/* mode_mutex is required to make this operation atomic wrt
 		pcm_digital_*_open() and set_input_clock() functions. */
-		mutex_lock(&chip->mode_mutex);
+		guard(mutex)(&chip->mode_mutex);
 
 		/* Do not allow the user to change the digital mode when a pcm
 		device is open because it also changes the number of channels
@@ -1460,7 +1454,6 @@ static int snd_echo_digital_mode_put(struct snd_kcontrol *kcontrol,
 			if (changed >= 0)
 				changed = 1;	/* No errors */
 		}
-		mutex_unlock(&chip->mode_mutex);
 	}
 	return changed;
 }
@@ -1573,13 +1566,12 @@ static int snd_echo_clock_source_put(struct snd_kcontrol *kcontrol,
 		return -EINVAL;
 	dclock = chip->clock_source_list[eclock];
 	if (chip->input_clock != dclock) {
-		mutex_lock(&chip->mode_mutex);
+		guard(mutex)(&chip->mode_mutex);
 		spin_lock_irq(&chip->lock);
 		changed = set_input_clock(chip, dclock);
 		if (!changed)
 			changed = 1;	/* no errors */
 		spin_unlock_irq(&chip->lock);
-		mutex_unlock(&chip->mode_mutex);
 	}
 
 	if (changed < 0)
-- 
2.50.1


  parent reply	other threads:[~2025-08-29 14:44 UTC|newest]

Thread overview: 62+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-08-29 14:42 [PATCH 00/61] ALSA: Use auto-cleanup for PCI drivers Takashi Iwai
2025-08-29 14:42 ` [PATCH 01/61] ALSA: ac97: Use guard() for mutex locks Takashi Iwai
2025-08-29 14:42 ` [PATCH 02/61] ALSA: ac97: Use guard() for spin locks Takashi Iwai
2025-08-29 14:42 ` [PATCH 03/61] ALSA: ali5451: " Takashi Iwai
2025-08-29 14:42 ` [PATCH 04/61] ALSA: azt3328: " Takashi Iwai
2025-08-29 14:42 ` [PATCH 05/61] ALSA: ens137x: Use guard() for mutex locks Takashi Iwai
2025-08-29 14:42 ` [PATCH 06/61] ALSA: ens137x: Use guard() for spin locks Takashi Iwai
2025-08-29 14:42 ` [PATCH 07/61] ALSA: als300: " Takashi Iwai
2025-08-29 14:42 ` [PATCH 08/61] ALSA: als4000: " Takashi Iwai
2025-08-29 14:42 ` [PATCH 09/61] ALSA: ad1889: " Takashi Iwai
2025-08-29 14:42 ` [PATCH 10/61] ALSA: atiixp: Use guard() for mutex locks Takashi Iwai
2025-08-29 14:42 ` [PATCH 11/61] ALSA: atiixp: Use guard() for spin locks Takashi Iwai
2025-08-29 14:42 ` [PATCH 12/61] ALSA: aw2: Use guard() for mutex locks Takashi Iwai
2025-08-29 14:42 ` [PATCH 13/61] ALSA: aw2: Use guard() for spin locks Takashi Iwai
2025-08-29 14:42 ` [PATCH 14/61] ALSA: bt87x: " Takashi Iwai
2025-08-29 14:42 ` [PATCH 15/61] ALSA: ca0106: " Takashi Iwai
2025-08-29 14:42 ` [PATCH 16/61] ALSA: cmipci: Use guard() for mutex locks Takashi Iwai
2025-08-29 14:42 ` [PATCH 17/61] ALSA: cmipci: Use guard() for spin locks Takashi Iwai
2025-08-29 14:42 ` [PATCH 18/61] ALSA: cs4281: " Takashi Iwai
2025-08-29 14:42 ` [PATCH 19/61] ALSA: cs46xx: Use guard() for mutex locks Takashi Iwai
2025-08-29 14:42 ` [PATCH 20/61] ALSA: cs46xx: Use guard() for spin locks Takashi Iwai
2025-08-29 14:42 ` [PATCH 21/61] ALSA: cs5535audio: " Takashi Iwai
2025-08-29 14:42 ` [PATCH 22/61] ALSA: ctxfi: Use guard() for mutex locks Takashi Iwai
2025-08-29 14:42 ` [PATCH 23/61] ALSA: ctxfi: Use guard() for spin locks Takashi Iwai
2025-08-29 14:42 ` Takashi Iwai [this message]
2025-08-29 14:43 ` [PATCH 25/61] ALSA: echoaudio: " Takashi Iwai
2025-08-29 14:43 ` [PATCH 26/61] ALSA: emu10k1: Use guard() for mutex locks Takashi Iwai
2025-08-29 14:43 ` [PATCH 27/61] ALSA: emu10k1: Use guard() for emu1010 FPGA locking Takashi Iwai
2025-08-29 14:43 ` [PATCH 28/61] ALSA: emu10k1: Use guard() for spin locks Takashi Iwai
2025-08-29 14:43 ` [PATCH 29/61] ALSA: emu10k1x: " Takashi Iwai
2025-08-29 14:43 ` [PATCH 30/61] ALSA: es1938: " Takashi Iwai
2025-08-29 14:43 ` [PATCH 31/61] ALSA: es1968: Use guard() for mutex locks Takashi Iwai
2025-08-29 14:43 ` [PATCH 32/61] ALSA: es1968: Use guard() for spin locks Takashi Iwai
2025-08-29 14:43 ` [PATCH 33/61] ALSA: fm801: " Takashi Iwai
2025-08-29 14:43 ` [PATCH 34/61] ALSA: ice1712: Use guard() for mutex locks Takashi Iwai
2025-08-29 14:43 ` [PATCH 35/61] ALSA: ice1712: Use guard() for spin locks Takashi Iwai
2025-08-29 14:43 ` [PATCH 36/61] ALSA: intel8x0: " Takashi Iwai
2025-08-29 14:43 ` [PATCH 37/61] ALSA: korg1212: Use guard() for mutex locks Takashi Iwai
2025-08-29 14:43 ` [PATCH 38/61] ALSA: korg1212: Use guard() for spin locks Takashi Iwai
2025-08-29 14:43 ` [PATCH 39/61] ALSA: lola: Use guard() for mutex locks Takashi Iwai
2025-08-29 14:43 ` [PATCH 40/61] ALSA: lola: Use guard() for spin locks Takashi Iwai
2025-08-29 14:43 ` [PATCH 41/61] ALSA: lx6464es: Use guard() for mutex locks Takashi Iwai
2025-08-29 14:43 ` [PATCH 42/61] ALSA: maestro3: Use guard() for spin locks Takashi Iwai
2025-08-29 14:43 ` [PATCH 43/61] ALSA: mixart: Use guard() for mutex locks Takashi Iwai
2025-08-29 14:43 ` [PATCH 44/61] ALSA: nm256: " Takashi Iwai
2025-08-29 14:43 ` [PATCH 45/61] ALSA: nm256: Use guard() for spin locks Takashi Iwai
2025-08-29 14:43 ` [PATCH 46/61] ALSA: oxygen: Use guard() for mutex locks Takashi Iwai
2025-08-29 14:43 ` [PATCH 47/61] ALSA: oxygen: Use guard() for spin locks Takashi Iwai
2025-08-29 14:43 ` [PATCH 48/61] ALSA: pcxhr: Use guard() for mutex locks Takashi Iwai
2025-08-29 14:43 ` [PATCH 49/61] ALSA: rme32: Use guard() for spin locks Takashi Iwai
2025-08-29 14:43 ` [PATCH 50/61] ALSA: rme96: " Takashi Iwai
2025-08-29 14:43 ` [PATCH 51/61] ALSA: hdsp: " Takashi Iwai
2025-08-29 14:43 ` [PATCH 52/61] ALSA: hdspm: " Takashi Iwai
2025-08-29 14:43 ` [PATCH 53/61] ALSA: rme9652: " Takashi Iwai
2025-08-29 14:43 ` [PATCH 54/61] ALSA: sis7019: Use guard() for mutex locks Takashi Iwai
2025-08-29 14:43 ` [PATCH 55/61] ALSA: sis7019: Use guard() for spin locks Takashi Iwai
2025-08-29 14:43 ` [PATCH 56/61] ALSA: sonicvibes: " Takashi Iwai
2025-08-29 14:43 ` [PATCH 57/61] ALSA: trident: Use guard() for mutex locks Takashi Iwai
2025-08-29 14:43 ` [PATCH 58/61] ALSA: trident: Use guard() for spin locks Takashi Iwai
2025-08-29 14:43 ` [PATCH 59/61] ALSA: via82xx: " Takashi Iwai
2025-08-29 14:43 ` [PATCH 60/61] ALSA: vx222: Use guard() for mutex locks Takashi Iwai
2025-08-29 14:43 ` [PATCH 61/61] ALSA: ymfpci: Use guard() for spin locks Takashi Iwai

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250829144342.4290-25-tiwai@suse.de \
    --to=tiwai@suse.de \
    --cc=linux-sound@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).