From: Takashi Iwai <tiwai@suse.de>
Subject: ALSA: usb-audio: Fix NULL dereference while quick replugging
Patch-mainline: Never, incompatible with upstream code
References: bnc#870335

At disconnection of usb-audio device, the pending URBs might be still
woken up although their resouces have been released.  This results in
Oops.

This patch fixes the problem by killing URBs properly at disconnection
and let the close (hw_free) ops releases resources.

The upstream code has already a similar change, so it's only for 3.0.x
kernels.

Signed-off-by: Takashi Iwai <tiwai@suse.de>

---
 sound/usb/urb.c |   11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

--- a/sound/usb/urb.c
+++ b/sound/usb/urb.c
@@ -61,7 +61,7 @@ static int deactivate_urbs(struct snd_us
 	if (!force && subs->stream->chip->shutdown) /* to be sure... */
 		return -EBADFD;
 
-	async = !can_sleep && chip->async_unlink;
+	async = chip->async_unlink;
 
 	if (!async && in_interrupt())
 		return 0;
@@ -146,11 +146,12 @@ void snd_usb_release_substream_urbs(stru
 {
 	int i;
 
+	if (!subs->nurbs)
+		return;
+
 	/* stop urbs (to be sure) */
-	if (!subs->stream->chip->shutdown) {
-		deactivate_urbs(subs, force, 1);
-		wait_clear_urbs(subs);
-	}
+	deactivate_urbs(subs, force, 1);
+	wait_clear_urbs(subs);
 
 	for (i = 0; i < MAX_URBS; i++)
 		release_urb_ctx(&subs->dataurb[i]);
