Linux Sound subsystem development
 help / color / mirror / Atom feed
* [PATCH] ALSA: usb-audio: scarlett2: unwind notify URB init failures
@ 2026-06-29 16:02 Yousef Alhouseen
  2026-06-30 12:23 ` Takashi Iwai
  0 siblings, 1 reply; 3+ messages in thread
From: Yousef Alhouseen @ 2026-06-29 16:02 UTC (permalink / raw)
  To: Geoffrey D . Bennett
  Cc: Jaroslav Kysela, Takashi Iwai, linux-sound, linux-kernel,
	Yousef Alhouseen

scarlett2_init_notify() stores the newly allocated URB in mixer->urb
before allocating the transfer buffer and submitting the URB. If a later
step fails, the function returns an error while leaving a partially
initialized notification URB attached to the mixer.

Clean up the URB and transfer buffer locally on those failure paths.
Leave mixer->urb NULL so later cleanup or retry paths do not see a
stale notification URB.

Signed-off-by: Yousef Alhouseen <alhouseenyousef@gmail.com>
---
 sound/usb/mixer_scarlett2.c | 18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)

diff --git a/sound/usb/mixer_scarlett2.c b/sound/usb/mixer_scarlett2.c
index 78fb72e626ca..67a089ad7723 100644
--- a/sound/usb/mixer_scarlett2.c
+++ b/sound/usb/mixer_scarlett2.c
@@ -8729,6 +8729,7 @@ static int scarlett2_init_notify(struct usb_mixer_interface *mixer)
 	struct scarlett2_data *private = mixer->private_data;
 	unsigned int pipe = usb_rcvintpipe(dev, private->bEndpointAddress);
 	void *transfer_buffer;
+	int err;
 
 	if (mixer->urb) {
 		usb_audio_err(mixer->chip,
@@ -8744,8 +8745,11 @@ static int scarlett2_init_notify(struct usb_mixer_interface *mixer)
 		return -ENOMEM;
 
 	transfer_buffer = kmalloc(private->wMaxPacketSize, GFP_KERNEL);
-	if (!transfer_buffer)
+	if (!transfer_buffer) {
+		usb_free_urb(mixer->urb);
+		mixer->urb = NULL;
 		return -ENOMEM;
+	}
 
 	usb_fill_int_urb(mixer->urb, dev, pipe,
 			 transfer_buffer, private->wMaxPacketSize,
@@ -8753,7 +8757,17 @@ static int scarlett2_init_notify(struct usb_mixer_interface *mixer)
 
 	init_completion(&private->cmd_done);
 
-	return usb_submit_urb(mixer->urb, GFP_KERNEL);
+	err = usb_submit_urb(mixer->urb, GFP_KERNEL);
+	if (err) {
+		usb_audio_err(mixer->chip,
+			      "%s: usb_submit_urb failed: %d\n",
+			      __func__, err);
+		kfree(transfer_buffer);
+		usb_free_urb(mixer->urb);
+		mixer->urb = NULL;
+	}
+
+	return err;
 }
 
 /* Cargo cult proprietary initialisation sequence */
-- 
2.54.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-06-30 20:37 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-29 16:02 [PATCH] ALSA: usb-audio: scarlett2: unwind notify URB init failures Yousef Alhouseen
2026-06-30 12:23 ` Takashi Iwai
2026-06-30 20:37   ` Yousef Alhouseen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox