提交 f58161ba 编写于 作者: T Takashi Iwai

ALSA: usb-audio: Fix crash at re-preparing the PCM stream

There are bug reports of a crash with USB-audio devices when PCM
prepare is performed immediately after the stream is stopped via
trigger callback.  It turned out that the problem is that we don't
wait until all URBs are killed.

This patch adds a new function to synchronize the pending stop
operation on an endpoint, and calls in the prepare callback for
avoiding the crash above.

Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=49181Reported-and-tested-by: NArtem S. Tashkinov <t.artem@lycos.com>
Cc: <stable@vger.kernel.org> [v3.6]
Signed-off-by: NTakashi Iwai <tiwai@suse.de>
上级 d1a3c98d
...@@ -35,6 +35,7 @@ ...@@ -35,6 +35,7 @@
#define EP_FLAG_ACTIVATED 0 #define EP_FLAG_ACTIVATED 0
#define EP_FLAG_RUNNING 1 #define EP_FLAG_RUNNING 1
#define EP_FLAG_STOPPING 2
/* /*
* snd_usb_endpoint is a model that abstracts everything related to an * snd_usb_endpoint is a model that abstracts everything related to an
...@@ -502,10 +503,20 @@ static int wait_clear_urbs(struct snd_usb_endpoint *ep) ...@@ -502,10 +503,20 @@ static int wait_clear_urbs(struct snd_usb_endpoint *ep)
if (alive) if (alive)
snd_printk(KERN_ERR "timeout: still %d active urbs on EP #%x\n", snd_printk(KERN_ERR "timeout: still %d active urbs on EP #%x\n",
alive, ep->ep_num); alive, ep->ep_num);
clear_bit(EP_FLAG_STOPPING, &ep->flags);
return 0; return 0;
} }
/* sync the pending stop operation;
* this function itself doesn't trigger the stop operation
*/
void snd_usb_endpoint_sync_pending_stop(struct snd_usb_endpoint *ep)
{
if (ep && test_bit(EP_FLAG_STOPPING, &ep->flags))
wait_clear_urbs(ep);
}
/* /*
* unlink active urbs. * unlink active urbs.
*/ */
...@@ -918,6 +929,8 @@ void snd_usb_endpoint_stop(struct snd_usb_endpoint *ep, ...@@ -918,6 +929,8 @@ void snd_usb_endpoint_stop(struct snd_usb_endpoint *ep,
if (wait) if (wait)
wait_clear_urbs(ep); wait_clear_urbs(ep);
else
set_bit(EP_FLAG_STOPPING, &ep->flags);
} }
} }
......
...@@ -19,6 +19,7 @@ int snd_usb_endpoint_set_params(struct snd_usb_endpoint *ep, ...@@ -19,6 +19,7 @@ int snd_usb_endpoint_set_params(struct snd_usb_endpoint *ep,
int snd_usb_endpoint_start(struct snd_usb_endpoint *ep, int can_sleep); int snd_usb_endpoint_start(struct snd_usb_endpoint *ep, int can_sleep);
void snd_usb_endpoint_stop(struct snd_usb_endpoint *ep, void snd_usb_endpoint_stop(struct snd_usb_endpoint *ep,
int force, int can_sleep, int wait); int force, int can_sleep, int wait);
void snd_usb_endpoint_sync_pending_stop(struct snd_usb_endpoint *ep);
int snd_usb_endpoint_activate(struct snd_usb_endpoint *ep); int snd_usb_endpoint_activate(struct snd_usb_endpoint *ep);
int snd_usb_endpoint_deactivate(struct snd_usb_endpoint *ep); int snd_usb_endpoint_deactivate(struct snd_usb_endpoint *ep);
void snd_usb_endpoint_free(struct list_head *head); void snd_usb_endpoint_free(struct list_head *head);
......
...@@ -568,6 +568,9 @@ static int snd_usb_pcm_prepare(struct snd_pcm_substream *substream) ...@@ -568,6 +568,9 @@ static int snd_usb_pcm_prepare(struct snd_pcm_substream *substream)
goto unlock; goto unlock;
} }
snd_usb_endpoint_sync_pending_stop(subs->sync_endpoint);
snd_usb_endpoint_sync_pending_stop(subs->data_endpoint);
ret = set_format(subs, subs->cur_audiofmt); ret = set_format(subs, subs->cur_audiofmt);
if (ret < 0) if (ret < 0)
goto unlock; goto unlock;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册