Skip to contentSkip to conversation

ALSA: usb-audio: endpoint : remove redundant check before usb_free_coherent()

PATCH In review Xu Wang 2 participants 2 messages Feb 4, 2021 Sound

lore
Share & tools
lore

Xu Wang

author
#0 lore raw

PATCH 1/1 ALSA: usb-audio: endpoint : remove redundant check before usb_free_coherent()

usb_free_coherent() is safe with NULL addr and this check is not required.

---
 sound/usb/endpoint.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
sound/usb/endpoint.c +3 -4
index 8e568823c992..d5ed4ddfd451 100644
@@ -82,10 +82,9 @@ 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)
-		usb_free_coherent(u->ep->chip->dev, u->buffer_size,
-				  u->urb->transfer_buffer,
-				  u->urb->transfer_dma);
+	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;
 }
Signature · 1 line
2.17.1
#1 lore raw
Quoted 3 lines · Xu Wang

usb_free_coherent() is safe with NULL addr and this check is not required.

The check there isn't about NULL buffer or not; instead it checks whether the buffer was allocated for each or it shares the single buffer (for sync endpoints). In the latter case, your patch will lead to double-free.

thanks,

Takashi