]> www.infradead.org Git - users/hch/misc.git/commitdiff
ALSA: hiface: Use guard() for mutex locks
authorTakashi Iwai <tiwai@suse.de>
Fri, 29 Aug 2025 15:07:12 +0000 (17:07 +0200)
committerTakashi Iwai <tiwai@suse.de>
Mon, 1 Sep 2025 11:54:06 +0000 (13:54 +0200)
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>
Link: https://patch.msgid.link/20250829150724.6886-5-tiwai@suse.de
sound/usb/hiface/chip.c
sound/usb/hiface/pcm.c

index 95385e90882c74199bcb3470dc2d16e100f60260..bce28f6836661d7460741bb73d10c8bc297c3965 100644 (file)
@@ -101,7 +101,7 @@ static int hiface_chip_probe(struct usb_interface *intf,
 
        /* check whether the card is already registered */
        chip = NULL;
-       mutex_lock(&register_mutex);
+       guard(mutex)(&register_mutex);
 
        for (i = 0; i < SNDRV_CARDS; i++)
                if (enable[i])
@@ -109,13 +109,12 @@ static int hiface_chip_probe(struct usb_interface *intf,
 
        if (i >= SNDRV_CARDS) {
                dev_err(&device->dev, "no available " CARD_NAME " audio device\n");
-               ret = -ENODEV;
-               goto err;
+               return -ENODEV;
        }
 
        ret = hiface_chip_create(intf, device, i, quirk, &chip);
        if (ret < 0)
-               goto err;
+               return ret;
 
        ret = hiface_pcm_init(chip, quirk ? quirk->extra_freq : 0);
        if (ret < 0)
@@ -127,15 +126,11 @@ static int hiface_chip_probe(struct usb_interface *intf,
                goto err_chip_destroy;
        }
 
-       mutex_unlock(&register_mutex);
-
        usb_set_intfdata(intf, chip);
        return 0;
 
 err_chip_destroy:
        snd_card_free(chip->card);
-err:
-       mutex_unlock(&register_mutex);
        return ret;
 }
 
index cf650fab54d7e25f480923a5a0a3fbf88bf772d6..f992e94feb64cd28fde117ce90579aead23b9984 100644 (file)
@@ -356,7 +356,7 @@ static int hiface_pcm_open(struct snd_pcm_substream *alsa_sub)
        if (rt->panic)
                return -EPIPE;
 
-       mutex_lock(&rt->stream_mutex);
+       guard(mutex)(&rt->stream_mutex);
        alsa_rt->hw = pcm_hw;
 
        if (alsa_sub->stream == SNDRV_PCM_STREAM_PLAYBACK)
@@ -364,7 +364,6 @@ static int hiface_pcm_open(struct snd_pcm_substream *alsa_sub)
 
        if (!sub) {
                struct device *device = &rt->chip->dev->dev;
-               mutex_unlock(&rt->stream_mutex);
                dev_err(device, "Invalid stream type\n");
                return -EINVAL;
        }
@@ -377,15 +376,12 @@ static int hiface_pcm_open(struct snd_pcm_substream *alsa_sub)
                ret = snd_pcm_hw_constraint_list(alsa_sub->runtime, 0,
                                                 SNDRV_PCM_HW_PARAM_RATE,
                                                 &constraints_extra_rates);
-               if (ret < 0) {
-                       mutex_unlock(&rt->stream_mutex);
+               if (ret < 0)
                        return ret;
-               }
        }
 
        sub->instance = alsa_sub;
        sub->active = false;
-       mutex_unlock(&rt->stream_mutex);
        return 0;
 }
 
@@ -398,7 +394,7 @@ static int hiface_pcm_close(struct snd_pcm_substream *alsa_sub)
        if (rt->panic)
                return 0;
 
-       mutex_lock(&rt->stream_mutex);
+       guard(mutex)(&rt->stream_mutex);
        if (sub) {
                hiface_pcm_stream_stop(rt);
 
@@ -409,7 +405,6 @@ static int hiface_pcm_close(struct snd_pcm_substream *alsa_sub)
                spin_unlock_irqrestore(&sub->lock, flags);
 
        }
-       mutex_unlock(&rt->stream_mutex);
        return 0;
 }
 
@@ -425,7 +420,7 @@ static int hiface_pcm_prepare(struct snd_pcm_substream *alsa_sub)
        if (!sub)
                return -ENODEV;
 
-       mutex_lock(&rt->stream_mutex);
+       guard(mutex)(&rt->stream_mutex);
 
        hiface_pcm_stream_stop(rt);
 
@@ -435,17 +430,12 @@ static int hiface_pcm_prepare(struct snd_pcm_substream *alsa_sub)
        if (rt->stream_state == STREAM_DISABLED) {
 
                ret = hiface_pcm_set_rate(rt, alsa_rt->rate);
-               if (ret) {
-                       mutex_unlock(&rt->stream_mutex);
+               if (ret)
                        return ret;
-               }
                ret = hiface_pcm_stream_start(rt);
-               if (ret) {
-                       mutex_unlock(&rt->stream_mutex);
+               if (ret)
                        return ret;
-               }
        }
-       mutex_unlock(&rt->stream_mutex);
        return 0;
 }
 
@@ -532,9 +522,8 @@ void hiface_pcm_abort(struct hiface_chip *chip)
        if (rt) {
                rt->panic = true;
 
-               mutex_lock(&rt->stream_mutex);
+               guard(mutex)(&rt->stream_mutex);
                hiface_pcm_stream_stop(rt);
-               mutex_unlock(&rt->stream_mutex);
        }
 }