ALSA: hiface: Use guard() for mutex locks

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
This commit is contained in:
Takashi Iwai
2025-08-29 17:07:12 +02:00
parent 9e38c362a6
commit 07f55c77b9
2 changed files with 10 additions and 26 deletions

View 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;
}

View 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);
}
}