ALSA: pcm: Add snd_pcm_stop_xrun() helper
Add a new helper function snd_pcm_stop_xrun() to the standard sequnce lock/snd_pcm_stop(XRUN)/unlock by a single call, and replace the existing open codes with this helper. The function checks the PCM running state to prevent setting the wrong state, too, for more safety. Signed-off-by: Takashi Iwai <tiwai@suse.de>
This commit is contained in:
@@ -679,25 +679,16 @@ int usb6fire_pcm_init(struct sfire_chip *chip)
|
||||
void usb6fire_pcm_abort(struct sfire_chip *chip)
|
||||
{
|
||||
struct pcm_runtime *rt = chip->pcm;
|
||||
unsigned long flags;
|
||||
int i;
|
||||
|
||||
if (rt) {
|
||||
rt->panic = true;
|
||||
|
||||
if (rt->playback.instance) {
|
||||
snd_pcm_stream_lock_irqsave(rt->playback.instance, flags);
|
||||
snd_pcm_stop(rt->playback.instance,
|
||||
SNDRV_PCM_STATE_XRUN);
|
||||
snd_pcm_stream_unlock_irqrestore(rt->playback.instance, flags);
|
||||
}
|
||||
if (rt->playback.instance)
|
||||
snd_pcm_stop_xrun(rt->playback.instance);
|
||||
|
||||
if (rt->capture.instance) {
|
||||
snd_pcm_stream_lock_irqsave(rt->capture.instance, flags);
|
||||
snd_pcm_stop(rt->capture.instance,
|
||||
SNDRV_PCM_STATE_XRUN);
|
||||
snd_pcm_stream_unlock_irqrestore(rt->capture.instance, flags);
|
||||
}
|
||||
if (rt->capture.instance)
|
||||
snd_pcm_stop_xrun(rt->capture.instance);
|
||||
|
||||
for (i = 0; i < PCM_N_URBS; i++) {
|
||||
usb_poison_urb(&rt->in_urbs[i].instance);
|
||||
|
@@ -391,9 +391,7 @@ static void snd_complete_urb(struct urb *urb)
|
||||
usb_audio_err(ep->chip, "cannot submit urb (err = %d)\n", err);
|
||||
if (ep->data_subs && ep->data_subs->pcm_substream) {
|
||||
substream = ep->data_subs->pcm_substream;
|
||||
snd_pcm_stream_lock_irqsave(substream, flags);
|
||||
snd_pcm_stop(substream, SNDRV_PCM_STATE_XRUN);
|
||||
snd_pcm_stream_unlock_irqrestore(substream, flags);
|
||||
snd_pcm_stop_xrun(substream);
|
||||
}
|
||||
|
||||
exit_clear:
|
||||
|
@@ -613,24 +613,14 @@ static int start_usb_playback(struct ua101 *ua)
|
||||
|
||||
static void abort_alsa_capture(struct ua101 *ua)
|
||||
{
|
||||
unsigned long flags;
|
||||
|
||||
if (test_bit(ALSA_CAPTURE_RUNNING, &ua->states)) {
|
||||
snd_pcm_stream_lock_irqsave(ua->capture.substream, flags);
|
||||
snd_pcm_stop(ua->capture.substream, SNDRV_PCM_STATE_XRUN);
|
||||
snd_pcm_stream_unlock_irqrestore(ua->capture.substream, flags);
|
||||
}
|
||||
if (test_bit(ALSA_CAPTURE_RUNNING, &ua->states))
|
||||
snd_pcm_stop_xrun(ua->capture.substream);
|
||||
}
|
||||
|
||||
static void abort_alsa_playback(struct ua101 *ua)
|
||||
{
|
||||
unsigned long flags;
|
||||
|
||||
if (test_bit(ALSA_PLAYBACK_RUNNING, &ua->states)) {
|
||||
snd_pcm_stream_lock_irqsave(ua->playback.substream, flags);
|
||||
snd_pcm_stop(ua->playback.substream, SNDRV_PCM_STATE_XRUN);
|
||||
snd_pcm_stream_unlock_irqrestore(ua->playback.substream, flags);
|
||||
}
|
||||
if (test_bit(ALSA_PLAYBACK_RUNNING, &ua->states))
|
||||
snd_pcm_stop_xrun(ua->playback.substream);
|
||||
}
|
||||
|
||||
static int set_stream_hw(struct ua101 *ua, struct snd_pcm_substream *substream,
|
||||
|
@@ -272,13 +272,8 @@ static void usX2Y_clients_stop(struct usX2Ydev *usX2Y)
|
||||
for (s = 0; s < 4; s++) {
|
||||
struct snd_usX2Y_substream *subs = usX2Y->subs[s];
|
||||
if (subs) {
|
||||
if (atomic_read(&subs->state) >= state_PRERUNNING) {
|
||||
unsigned long flags;
|
||||
|
||||
snd_pcm_stream_lock_irqsave(subs->pcm_substream, flags);
|
||||
snd_pcm_stop(subs->pcm_substream, SNDRV_PCM_STATE_XRUN);
|
||||
snd_pcm_stream_unlock_irqrestore(subs->pcm_substream, flags);
|
||||
}
|
||||
if (atomic_read(&subs->state) >= state_PRERUNNING)
|
||||
snd_pcm_stop_xrun(subs->pcm_substream);
|
||||
for (u = 0; u < NRURBS; u++) {
|
||||
struct urb *urb = subs->urb[u];
|
||||
if (NULL != urb)
|
||||
|
Reference in New Issue
Block a user