>From e72f883a9c560fc2edd03774da0c32a64a7b8358 Mon Sep 17 00:00:00 2001
From: Takashi Iwai <tiwai@suse.de>
Date: Wed, 20 Apr 2016 12:10:10 +0200
Subject: [PATCH 1/2] ALSA: hrtimer: Use manual start/stop in callback (v3)

With the new SNDRV_TIMER_HW_RET_CTRL flag, hrtimer can manage the
callback behavior more correctly.  Now it gets a return value from
snd_timer_interrupt() whether to reprogram or stop the timer, and it
can choose the right return value; i.e. we just return
HRTIMER_NORESTART from the handler when the timer is being stopped.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
---
 sound/core/hrtimer.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/sound/core/hrtimer.c b/sound/core/hrtimer.c
index 656d9a9032dc..79762444bc79 100644
--- a/sound/core/hrtimer.c
+++ b/sound/core/hrtimer.c
@@ -46,12 +46,17 @@ static enum hrtimer_restart snd_hrtimer_callback(struct hrtimer *hrt)
 	struct snd_hrtimer *stime = container_of(hrt, struct snd_hrtimer, hrt);
 	struct snd_timer *t = stime->timer;
 	unsigned long oruns;
+	int ret;
 
 	if (!atomic_read(&stime->running))
 		return HRTIMER_NORESTART;
 
 	oruns = hrtimer_forward_now(hrt, ns_to_ktime(t->sticks * resolution));
-	snd_timer_interrupt(stime->timer, t->sticks * oruns);
+	ret = snd_timer_interrupt(stime->timer, t->sticks * oruns);
+	if (ret == SNDRV_TIMER_RET_STOP) {
+		atomic_set(&stime->running, 0);
+		return HRTIMER_NORESTART;
+	}
 
 	if (!atomic_read(&stime->running))
 		return HRTIMER_NORESTART;
-- 
2.8.1

