Skip to contentSkip to conversation

ALSA: usb-audio: Fix NULL dererence at error path

PATCH New Takashi Iwai 1 participant 1 message Sep 30, 2022 Sound

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ALSA: usb-audio: Fix NULL dererence at error path

At an error path to release URB buffers and contexts, the driver might hit a NULL dererence for u->urb pointer, when u->buffer_size has been already set but the actual URB allocation failed.

Fix it by adding the NULL check of urb. Also, make sure that buffer_size is cleared after the error path or the close.

---
 sound/usb/endpoint.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
sound/usb/endpoint.c +2 -1
index b2d0b42b581f..36f753a28341 100644
@@ -95,12 +95,13 @@ static inline unsigned get_usb_high_speed_rate(unsigned int rate)
  */
 static void release_urb_ctx(struct snd_urb_ctx *u)
 {
-	if (u->buffer_size)
+	if (u->urb && u->buffer_size)
 		usb_free_coherent(u->ep->chip->dev, u->buffer_size,
 				  u->urb->transfer_buffer,
 				  u->urb->transfer_dma);
 	usb_free_urb(u->urb);
 	u->urb = NULL;
+	u->buffer_size = 0;
 }
 
 static const char *usb_error_string(int err)
Signature · 1 line
2.35.3