Skip to content

Commit 1fb8510

Browse files
committed
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>
1 parent 31584ed commit 1fb8510

15 files changed

Lines changed: 46 additions & 78 deletions

File tree

‎drivers/media/pci/saa7134/saa7134-alsa.c‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -173,9 +173,7 @@ static void saa7134_irq_alsa_done(struct saa7134_dev *dev,
173173
dprintk("irq: overrun [full=%d/%d] - Blocks in %d\n",dev->dmasound.read_count,
174174
dev->dmasound.bufsize, dev->dmasound.blocks);
175175
spin_unlock(&dev->slock);
176-
snd_pcm_stream_lock(dev->dmasound.substream);
177-
snd_pcm_stop(dev->dmasound.substream,SNDRV_PCM_STATE_XRUN);
178-
snd_pcm_stream_unlock(dev->dmasound.substream);
176+
snd_pcm_stop_xrun(dev->dmasound.substream);
179177
return;
180178
}
181179

‎include/sound/pcm.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -506,6 +506,7 @@ int snd_pcm_status(struct snd_pcm_substream *substream,
506506
int snd_pcm_start(struct snd_pcm_substream *substream);
507507
int snd_pcm_stop(struct snd_pcm_substream *substream, snd_pcm_state_t status);
508508
int snd_pcm_drain_done(struct snd_pcm_substream *substream);
509+
int snd_pcm_stop_xrun(struct snd_pcm_substream *substream);
509510
#ifdef CONFIG_PM
510511
int snd_pcm_suspend(struct snd_pcm_substream *substream);
511512
int snd_pcm_suspend_all(struct snd_pcm *pcm);

‎sound/arm/pxa2xx-pcm-lib.c‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -200,9 +200,7 @@ void pxa2xx_pcm_dma_irq(int dma_ch, void *dev_id)
200200
} else {
201201
printk(KERN_ERR "DMA error on channel %d (DCSR=%#x)\n",
202202
dma_ch, dcsr);
203-
snd_pcm_stream_lock(substream);
204-
snd_pcm_stop(substream, SNDRV_PCM_STATE_XRUN);
205-
snd_pcm_stream_unlock(substream);
203+
snd_pcm_stop_xrun(substream);
206204
}
207205
}
208206
EXPORT_SYMBOL(pxa2xx_pcm_dma_irq);

‎sound/core/pcm_native.c‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1098,6 +1098,29 @@ int snd_pcm_drain_done(struct snd_pcm_substream *substream)
10981098
SNDRV_PCM_STATE_SETUP);
10991099
}
11001100

1101+
/**
1102+
* snd_pcm_stop_xrun - stop the running streams as XRUN
1103+
* @substream: the PCM substream instance
1104+
* @state: PCM state after stopping the stream
1105+
*
1106+
* This stops the given running substream (and all linked substreams) as XRUN.
1107+
* Unlike snd_pcm_stop(), this function takes the substream lock by itself.
1108+
*
1109+
* Return: Zero if successful, or a negative error code.
1110+
*/
1111+
int snd_pcm_stop_xrun(struct snd_pcm_substream *substream)
1112+
{
1113+
unsigned long flags;
1114+
int ret = 0;
1115+
1116+
snd_pcm_stream_lock_irqsave(substream, flags);
1117+
if (snd_pcm_running(substream))
1118+
ret = snd_pcm_stop(substream, SNDRV_PCM_STATE_XRUN);
1119+
snd_pcm_stream_unlock_irqrestore(substream, flags);
1120+
return ret;
1121+
}
1122+
EXPORT_SYMBOL_GPL(snd_pcm_stop_xrun);
1123+
11011124
/*
11021125
* pause callbacks
11031126
*/

‎sound/firewire/amdtp.c‎

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1006,11 +1006,7 @@ void amdtp_stream_pcm_abort(struct amdtp_stream *s)
10061006
struct snd_pcm_substream *pcm;
10071007

10081008
pcm = ACCESS_ONCE(s->pcm);
1009-
if (pcm) {
1010-
snd_pcm_stream_lock_irq(pcm);
1011-
if (snd_pcm_running(pcm))
1012-
snd_pcm_stop(pcm, SNDRV_PCM_STATE_XRUN);
1013-
snd_pcm_stream_unlock_irq(pcm);
1014-
}
1009+
if (pcm)
1010+
snd_pcm_stop_xrun(pcm);
10151011
}
10161012
EXPORT_SYMBOL(amdtp_stream_pcm_abort);

‎sound/firewire/isight.c‎

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -131,14 +131,8 @@ static void isight_samples(struct isight *isight,
131131

132132
static void isight_pcm_abort(struct isight *isight)
133133
{
134-
unsigned long flags;
135-
136-
if (ACCESS_ONCE(isight->pcm_active)) {
137-
snd_pcm_stream_lock_irqsave(isight->pcm, flags);
138-
if (snd_pcm_running(isight->pcm))
139-
snd_pcm_stop(isight->pcm, SNDRV_PCM_STATE_XRUN);
140-
snd_pcm_stream_unlock_irqrestore(isight->pcm, flags);
141-
}
134+
if (ACCESS_ONCE(isight->pcm_active))
135+
snd_pcm_stop_xrun(isight->pcm);
142136
}
143137

144138
static void isight_dropped_samples(struct isight *isight, unsigned int total)

‎sound/pci/asihpi/asihpi.c‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -769,10 +769,7 @@ static void snd_card_asihpi_timer_function(unsigned long data)
769769
s->number);
770770
ds->drained_count++;
771771
if (ds->drained_count > 20) {
772-
unsigned long flags;
773-
snd_pcm_stream_lock_irqsave(s, flags);
774-
snd_pcm_stop(s, SNDRV_PCM_STATE_XRUN);
775-
snd_pcm_stream_unlock_irqrestore(s, flags);
772+
snd_pcm_stop_xrun(s);
776773
continue;
777774
}
778775
} else {

‎sound/pci/atiixp.c‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -688,9 +688,7 @@ static void snd_atiixp_xrun_dma(struct atiixp *chip, struct atiixp_dma *dma)
688688
if (! dma->substream || ! dma->running)
689689
return;
690690
dev_dbg(chip->card->dev, "XRUN detected (DMA %d)\n", dma->ops->type);
691-
snd_pcm_stream_lock(dma->substream);
692-
snd_pcm_stop(dma->substream, SNDRV_PCM_STATE_XRUN);
693-
snd_pcm_stream_unlock(dma->substream);
691+
snd_pcm_stop_xrun(dma->substream);
694692
}
695693

696694
/*

‎sound/pci/atiixp_modem.c‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -638,9 +638,7 @@ static void snd_atiixp_xrun_dma(struct atiixp_modem *chip,
638638
if (! dma->substream || ! dma->running)
639639
return;
640640
dev_dbg(chip->card->dev, "XRUN detected (DMA %d)\n", dma->ops->type);
641-
snd_pcm_stream_lock(dma->substream);
642-
snd_pcm_stop(dma->substream, SNDRV_PCM_STATE_XRUN);
643-
snd_pcm_stream_unlock(dma->substream);
641+
snd_pcm_stop_xrun(dma->substream);
644642
}
645643

646644
/*

‎sound/soc/atmel/atmel-pcm-dma.c‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,7 @@ static void atmel_pcm_dma_irq(u32 ssc_sr,
8080

8181
/* stop RX and capture: will be enabled again at restart */
8282
ssc_writex(prtd->ssc->regs, SSC_CR, prtd->mask->ssc_disable);
83-
snd_pcm_stream_lock(substream);
84-
snd_pcm_stop(substream, SNDRV_PCM_STATE_XRUN);
85-
snd_pcm_stream_unlock(substream);
83+
snd_pcm_stop_xrun(substream);
8684

8785
/* now drain RHR and read status to remove xrun condition */
8886
ssc_readx(prtd->ssc->regs, SSC_RHR);

0 commit comments

Comments
 (0)