Skip to content

Commit eb99b1b

Browse files
ivanorlov2206tiwai
authored andcommitted
ALSA: pcmtest: stop timer before buffer is released
Stop timer in the 'trigger' and 'sync_stop' callbacks since we want the timer to be stopped before the DMA buffer is released. Otherwise, it could trigger a kernel panic in some circumstances, for instance when the DMA buffer is already released but the timer callback is still running. Signed-off-by: Ivan Orlov <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Takashi Iwai <[email protected]>
1 parent 8804fa0 commit eb99b1b

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

sound/drivers/pcmtest.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,6 @@ static int snd_pcmtst_pcm_close(struct snd_pcm_substream *substream)
397397
struct pcmtst_buf_iter *v_iter = substream->runtime->private_data;
398398

399399
timer_shutdown_sync(&v_iter->timer_instance);
400-
v_iter->substream = NULL;
401400
playback_capture_test = !v_iter->is_buf_corrupted;
402401
kfree(v_iter);
403402
return 0;
@@ -435,6 +434,7 @@ static int snd_pcmtst_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
435434
case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
436435
// We can't call timer_shutdown_sync here, as it is forbidden to sleep here
437436
v_iter->suspend = true;
437+
timer_delete(&v_iter->timer_instance);
438438
break;
439439
}
440440

@@ -512,12 +512,22 @@ static int snd_pcmtst_ioctl(struct snd_pcm_substream *substream, unsigned int cm
512512
return snd_pcm_lib_ioctl(substream, cmd, arg);
513513
}
514514

515+
static int snd_pcmtst_sync_stop(struct snd_pcm_substream *substream)
516+
{
517+
struct pcmtst_buf_iter *v_iter = substream->runtime->private_data;
518+
519+
timer_delete_sync(&v_iter->timer_instance);
520+
521+
return 0;
522+
}
523+
515524
static const struct snd_pcm_ops snd_pcmtst_playback_ops = {
516525
.open = snd_pcmtst_pcm_open,
517526
.close = snd_pcmtst_pcm_close,
518527
.trigger = snd_pcmtst_pcm_trigger,
519528
.hw_params = snd_pcmtst_pcm_hw_params,
520529
.ioctl = snd_pcmtst_ioctl,
530+
.sync_stop = snd_pcmtst_sync_stop,
521531
.hw_free = snd_pcmtst_pcm_hw_free,
522532
.prepare = snd_pcmtst_pcm_prepare,
523533
.pointer = snd_pcmtst_pcm_pointer,
@@ -530,6 +540,7 @@ static const struct snd_pcm_ops snd_pcmtst_capture_ops = {
530540
.hw_params = snd_pcmtst_pcm_hw_params,
531541
.hw_free = snd_pcmtst_pcm_hw_free,
532542
.ioctl = snd_pcmtst_ioctl,
543+
.sync_stop = snd_pcmtst_sync_stop,
533544
.prepare = snd_pcmtst_pcm_prepare,
534545
.pointer = snd_pcmtst_pcm_pointer,
535546
};

0 commit comments

Comments
 (0)