ALSA: usb: qcom: Use guard() for mutex locks

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

The manual mutex lock/unlock are still left in
handle_uaudio_stream_req() and its callee as they have a bit complex
locking patterns.

Only code refactoring, and no behavior change.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
Link: https://patch.msgid.link/20250829150724.6886-8-tiwai@suse.de
This commit is contained in:
Takashi Iwai 2025-08-29 17:07:15 +02:00
parent 6dcbb0a9a6
commit e5d3eeb426

View File

@ -744,7 +744,7 @@ static void qmi_stop_session(void)
int if_idx;
int idx;
mutex_lock(&qdev_mutex);
guard(mutex)(&qdev_mutex);
/* find all active intf for set alt 0 and cleanup usb audio dev */
for (idx = 0; idx < SNDRV_CARDS; idx++) {
if (!atomic_read(&uadev[idx].in_use))
@ -780,11 +780,9 @@ static void qmi_stop_session(void)
disable_audio_stream(subs);
}
atomic_set(&uadev[idx].in_use, 0);
mutex_lock(&chip->mutex);
guard(mutex)(&chip->mutex);
uaudio_dev_cleanup(&uadev[idx]);
mutex_unlock(&chip->mutex);
}
mutex_unlock(&qdev_mutex);
}
/**
@ -810,8 +808,8 @@ static int uaudio_sideband_notifier(struct usb_interface *intf,
chip = usb_get_intfdata(intf);
mutex_lock(&qdev_mutex);
mutex_lock(&chip->mutex);
guard(mutex)(&qdev_mutex);
guard(mutex)(&chip->mutex);
dev = &uadev[chip->card->number];
@ -825,9 +823,6 @@ static int uaudio_sideband_notifier(struct usb_interface *intf,
}
}
mutex_unlock(&chip->mutex);
mutex_unlock(&qdev_mutex);
return 0;
}
@ -1577,17 +1572,15 @@ static void handle_uaudio_stream_req(struct qmi_handle *handle,
goto response;
}
mutex_lock(&chip->mutex);
if (req_msg->enable) {
if (info_idx < 0 || chip->system_suspend || subs->opened) {
ret = -EBUSY;
mutex_unlock(&chip->mutex);
goto response;
scoped_guard(mutex, &chip->mutex) {
if (req_msg->enable) {
if (info_idx < 0 || chip->system_suspend || subs->opened) {
ret = -EBUSY;
goto response;
}
subs->opened = 1;
}
subs->opened = 1;
}
mutex_unlock(&chip->mutex);
if (req_msg->service_interval_valid) {
ret = get_data_interval_from_si(subs,
@ -1610,9 +1603,8 @@ static void handle_uaudio_stream_req(struct qmi_handle *handle,
ret = prepare_qmi_response(subs, req_msg, &resp,
info_idx);
if (ret < 0) {
mutex_lock(&chip->mutex);
guard(mutex)(&chip->mutex);
subs->opened = 0;
mutex_unlock(&chip->mutex);
}
} else {
info = &uadev[pcm_card_num].info[info_idx];
@ -1643,14 +1635,13 @@ static void handle_uaudio_stream_req(struct qmi_handle *handle,
}
disable_audio_stream(subs);
mutex_lock(&chip->mutex);
guard(mutex)(&chip->mutex);
subs->opened = 0;
mutex_unlock(&chip->mutex);
}
response:
if (!req_msg->enable && ret != -EINVAL && ret != -ENODEV) {
mutex_lock(&chip->mutex);
guard(mutex)(&chip->mutex);
if (info_idx >= 0) {
info = &uadev[pcm_card_num].info[info_idx];
uaudio_dev_intf_cleanup(uadev[pcm_card_num].udev,
@ -1659,7 +1650,6 @@ static void handle_uaudio_stream_req(struct qmi_handle *handle,
if (atomic_read(&uadev[pcm_card_num].in_use))
kref_put(&uadev[pcm_card_num].kref,
uaudio_dev_release);
mutex_unlock(&chip->mutex);
}
mutex_unlock(&qdev_mutex);
@ -1762,12 +1752,12 @@ static void qc_usb_audio_offload_probe(struct snd_usb_audio *chip)
!usb_qmi_get_pcm_num(chip, 0))
return;
mutex_lock(&qdev_mutex);
mutex_lock(&chip->mutex);
guard(mutex)(&qdev_mutex);
guard(mutex)(&chip->mutex);
if (!uadev[chip->card->number].chip) {
sdev = kzalloc(sizeof(*sdev), GFP_KERNEL);
if (!sdev)
goto exit;
return;
sb = xhci_sideband_register(intf, XHCI_SIDEBAND_VENDOR,
uaudio_sideband_notifier);
@ -1806,9 +1796,6 @@ static void qc_usb_audio_offload_probe(struct snd_usb_audio *chip)
snd_soc_usb_connect(uaudio_qdev->auxdev->dev.parent, sdev);
}
mutex_unlock(&chip->mutex);
mutex_unlock(&qdev_mutex);
return;
unreg_xhci:
@ -1818,9 +1805,6 @@ static void qc_usb_audio_offload_probe(struct snd_usb_audio *chip)
kfree(sdev);
uadev[chip->card->number].sdev = NULL;
uadev[chip->card->number].chip = NULL;
exit:
mutex_unlock(&chip->mutex);
mutex_unlock(&qdev_mutex);
}
/**
@ -1856,16 +1840,13 @@ static void qc_usb_audio_offload_disconnect(struct snd_usb_audio *chip)
if (card_num >= SNDRV_CARDS)
return;
mutex_lock(&qdev_mutex);
mutex_lock(&chip->mutex);
guard(mutex)(&qdev_mutex);
guard(mutex)(&chip->mutex);
dev = &uadev[card_num];
/* Device has already been cleaned up, or never populated */
if (!dev->chip) {
mutex_unlock(&chip->mutex);
mutex_unlock(&qdev_mutex);
if (!dev->chip)
return;
}
/* cleaned up already */
if (!dev->udev)
@ -1886,9 +1867,6 @@ static void qc_usb_audio_offload_disconnect(struct snd_usb_audio *chip)
kfree(dev->sdev);
dev->sdev = NULL;
}
mutex_unlock(&chip->mutex);
mutex_unlock(&qdev_mutex);
}
/**
@ -1913,13 +1891,10 @@ static void qc_usb_audio_offload_suspend(struct usb_interface *intf,
if (card_num >= SNDRV_CARDS)
return;
mutex_lock(&qdev_mutex);
mutex_lock(&chip->mutex);
guard(mutex)(&qdev_mutex);
guard(mutex)(&chip->mutex);
uaudio_send_disconnect_ind(chip);
mutex_unlock(&chip->mutex);
mutex_unlock(&qdev_mutex);
}
static struct snd_usb_platform_ops offload_ops = {