diff mbox series

[2/2] ALSA: aloop: Avoid unexpected timer event callback tasklets

Message ID 20191122175218.17187-2-andrew_gabbasov@mentor.com (mailing list archive)
State New, archived
Headers show
Series [1/2] ALSA: aloop: Remove redundant locking in timer open function | expand

Commit Message

Gabbasov, Andrew Nov. 22, 2019, 5:52 p.m. UTC
loopback_snd_timer_close_cable() function waits until all
scheduled tasklets are completed, but the timer is closed after that
and can generate more event callbacks, scheduling new tasklets,
that will not be synchronized with cable closing.
Move tasklet_kill() call to be executed after snd_timer_close()
call to avoid such case.

Fixes: 26c53379f98d ("ALSA: aloop: Support selection of snd_timer instead of jiffies")
Signed-off-by: Andrew Gabbasov <andrew_gabbasov@mentor.com>
---
 sound/drivers/aloop.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

Comments

Takashi Iwai Nov. 22, 2019, 6:14 p.m. UTC | #1
On Fri, 22 Nov 2019 18:52:18 +0100,
Andrew Gabbasov wrote:
> 
> loopback_snd_timer_close_cable() function waits until all
> scheduled tasklets are completed, but the timer is closed after that
> and can generate more event callbacks, scheduling new tasklets,
> that will not be synchronized with cable closing.
> Move tasklet_kill() call to be executed after snd_timer_close()
> call to avoid such case.
> 
> Fixes: 26c53379f98d ("ALSA: aloop: Support selection of snd_timer instead of jiffies")
> Signed-off-by: Andrew Gabbasov <andrew_gabbasov@mentor.com>

Applied, thanks.


Takashi
diff mbox series

Patch

diff --git a/sound/drivers/aloop.c b/sound/drivers/aloop.c
index 6408932f5f72..0ebfbe70db00 100644
--- a/sound/drivers/aloop.c
+++ b/sound/drivers/aloop.c
@@ -302,15 +302,16 @@  static int loopback_snd_timer_close_cable(struct loopback_pcm *dpcm)
 	if (!cable->snd_timer.instance)
 		return 0;
 
-	/* wait till drain tasklet has finished if requested */
-	tasklet_kill(&cable->snd_timer.event_tasklet);
-
 	/* will only be called from free_cable() when other stream was
 	 * already closed. Other stream cannot be reopened as long as
 	 * loopback->cable_lock is locked. Therefore no need to lock
 	 * cable->lock;
 	 */
 	snd_timer_close(cable->snd_timer.instance);
+
+	/* wait till drain tasklet has finished if requested */
+	tasklet_kill(&cable->snd_timer.event_tasklet);
+
 	snd_timer_instance_free(cable->snd_timer.instance);
 	memset(&cable->snd_timer, 0, sizeof(cable->snd_timer));