From: Will Porter <mrwillporter@gmail.com>
To: Takashi Iwai <tiwai@suse.com>
Cc: "Jaroslav Kysela" <perex@perex.cz>,
"Geoffrey D. Bennett" <g@b4.vu>,
"Asahi Lina" <lina@asahilina.net>,
"Chris J Arges" <chris.j.arges@canonical.com>,
"Nick Kossifidis" <mickflemm@gmail.com>,
"Detlef Urban" <onkel@paraair.de>,
"Roy Vegard Ovesen" <roy.vegard.ovesen@gmail.com>,
fenugrec <fenugrec@mail.com>,
"Frederic Popp" <frederic.l.popp@t-online.de>,
"Cássio Gabriel" <cassiogabrielcontato@gmail.com>,
"Shipei Qu" <qu@darknavy.com>,
linux-sound@vger.kernel.org, linux-kernel@vger.kernel.org,
"Will Porter" <mrwillporter@gmail.com>
Subject: [PATCH 4/6] ALSA: usb-audio: Guard Scarlett2 protocol transfers
Date: Thu, 27 Aug 2026 18:21:41 -0500 [thread overview]
Message-ID: <20260827232143.149197-5-mrwillporter@gmail.com> (raw)
In-Reply-To: <20260827232143.149197-1-mrwillporter@gmail.com>
Scarlett2 controls and hwdep operations reach the proprietary USB
transport without preventing runtime suspend or disconnect. Protect the
central request-and-response helper. One reference then covers the
command, acknowledgment wait, and response.
The runtime and system resume hook submits only the notification URB. It
takes no protocol mutex. Thus, the transport guard does not invert the
existing data_mutex or usb_mutex order. Keep the suspend-time config save
on the unguarded helper because it runs inside the USB suspend callback.
This change protects each USB transaction. It does not hold a runtime-PM
reference across the asynchronous flash-erase interval.
Assisted-by: Codex:gpt-5.6-sol
Signed-off-by: Will Porter <mrwillporter@gmail.com>
---
sound/usb/mixer_scarlett2.c | 36 ++++++++++++++++++++++++++++++------
1 file changed, 30 insertions(+), 6 deletions(-)
diff --git a/sound/usb/mixer_scarlett2.c b/sound/usb/mixer_scarlett2.c
index 502854cc9f9f..ed5fe746d438 100644
--- a/sound/usb/mixer_scarlett2.c
+++ b/sound/usb/mixer_scarlett2.c
@@ -2603,9 +2603,9 @@ static int scarlett2_usb_rx(struct usb_device *dev, int interface,
}
/* Send a proprietary format request to the Scarlett interface */
-static int scarlett2_usb(
- struct usb_mixer_interface *mixer, u32 cmd,
- void *req_data, u16 req_size, void *resp_data, u16 resp_size)
+static int scarlett2_usb_nopm(struct usb_mixer_interface *mixer, u32 cmd,
+ void *req_data, u16 req_size,
+ void *resp_data, u16 resp_size)
{
struct scarlett2_data *private = mixer->private_data;
struct usb_device *dev = mixer->chip->dev;
@@ -2713,6 +2713,18 @@ static int scarlett2_usb(
return err;
}
+static int scarlett2_usb(struct usb_mixer_interface *mixer, u32 cmd,
+ void *req_data, u16 req_size,
+ void *resp_data, u16 resp_size)
+{
+ CLASS(snd_usb_lock, pm)(mixer->chip);
+ if (pm.err < 0)
+ return -EIO;
+
+ return scarlett2_usb_nopm(mixer, cmd, req_data, req_size,
+ resp_data, resp_size);
+}
+
/* Send a USB message to get data; result placed in *buf */
static int scarlett2_usb_get(
struct usb_mixer_interface *mixer,
@@ -3020,9 +3032,21 @@ static int scarlett2_usb_set_config_buf(
/* Send SCARLETT2_USB_DATA_CMD SCARLETT2_USB_CONFIG_SAVE */
static void scarlett2_config_save(struct usb_mixer_interface *mixer)
{
- int err;
+ __le32 req = cpu_to_le32(SCARLETT2_USB_CONFIG_SAVE);
+ int err = scarlett2_usb(mixer, SCARLETT2_USB_DATA_CMD,
+ &req, sizeof(req), NULL, 0);
+
+ if (err < 0)
+ usb_audio_err(mixer->chip, "config save failed: %d\n", err);
+}
+
+/* The USB suspend callback must not acquire another PM reference. */
+static void scarlett2_config_save_nopm(struct usb_mixer_interface *mixer)
+{
+ __le32 req = cpu_to_le32(SCARLETT2_USB_CONFIG_SAVE);
+ int err = scarlett2_usb_nopm(mixer, SCARLETT2_USB_DATA_CMD,
+ &req, sizeof(req), NULL, 0);
- err = scarlett2_usb_activate_config(mixer, SCARLETT2_USB_CONFIG_SAVE);
if (err < 0)
usb_audio_err(mixer->chip, "config save failed: %d\n", err);
}
@@ -8639,7 +8663,7 @@ static void scarlett2_private_suspend(struct usb_mixer_interface *mixer)
struct scarlett2_data *private = mixer->private_data;
if (cancel_delayed_work_sync(&private->work))
- scarlett2_config_save(private->mixer);
+ scarlett2_config_save_nopm(private->mixer);
scarlett2_cleanup_urb(mixer);
}
--
2.47.3
next prev parent reply other threads:[~2026-08-27 23:22 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-24 23:03 [RFC] ALSA: usb-audio: missing PM guards in device mixer paths Will Porter
2026-08-25 8:17 ` Takashi Iwai
2026-08-27 23:21 ` [PATCH 0/6] ALSA: usb-audio: guard device-specific control transfers Will Porter
2026-08-27 23:21 ` [PATCH 1/6] ALSA: usb-audio: Add PM guard to Studio 1810c controls Will Porter
2026-08-27 23:21 ` [PATCH 2/6] ALSA: usb-audio: Add PM guards to US-16x08 transfers Will Porter
2026-08-27 23:21 ` [PATCH 3/6] ALSA: usb-audio: Add PM guard to Scarlett meter reads Will Porter
2026-08-27 23:21 ` Will Porter [this message]
2026-08-27 23:21 ` [PATCH 5/6] ALSA: usb-audio: Add PM guards to RME Digiface controls Will Porter
2026-08-27 23:21 ` [PATCH 6/6] ALSA: usb-audio: Guard FCP protocol transfers Will Porter
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=20260827232143.149197-5-mrwillporter@gmail.com \
--to=mrwillporter@gmail.com \
--cc=cassiogabrielcontato@gmail.com \
--cc=chris.j.arges@canonical.com \
--cc=fenugrec@mail.com \
--cc=frederic.l.popp@t-online.de \
--cc=g@b4.vu \
--cc=lina@asahilina.net \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-sound@vger.kernel.org \
--cc=mickflemm@gmail.com \
--cc=onkel@paraair.de \
--cc=perex@perex.cz \
--cc=qu@darknavy.com \
--cc=roy.vegard.ovesen@gmail.com \
--cc=tiwai@suse.com \
/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
all inboxes | Powered by JetHome®