Commit 1fd7e28a authored by Omair Mohammed Abdullah's avatar Omair Mohammed Abdullah Committed by Ben Hutchings

ALSA: aloop - add locking to timer access

commit d4f1e48b upstream.

When the loopback timer handler is running, calling del_timer() (for STOP
trigger) will not wait for the handler to complete before deactivating the
timer. The timer gets rescheduled in the handler as usual. Then a subsequent
START trigger will try to start the timer using add_timer() with a timer pending
leading to a kernel panic.

Serialize the calls to add_timer() and del_timer() using a spin lock to avoid
this.
Signed-off-by: default avatarOmair Mohammed Abdullah <omair.m.abdullah@linux.intel.com>
Signed-off-by: default avatarVinod Koul <vinod.koul@linux.intel.com>
Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
Signed-off-by: default avatarBen Hutchings <ben@decadent.org.uk>
parent 77372386
...@@ -119,6 +119,7 @@ struct loopback_pcm { ...@@ -119,6 +119,7 @@ struct loopback_pcm {
unsigned int period_size_frac; unsigned int period_size_frac;
unsigned long last_jiffies; unsigned long last_jiffies;
struct timer_list timer; struct timer_list timer;
spinlock_t timer_lock;
}; };
static struct platform_device *devices[SNDRV_CARDS]; static struct platform_device *devices[SNDRV_CARDS];
...@@ -169,6 +170,7 @@ static void loopback_timer_start(struct loopback_pcm *dpcm) ...@@ -169,6 +170,7 @@ static void loopback_timer_start(struct loopback_pcm *dpcm)
unsigned long tick; unsigned long tick;
unsigned int rate_shift = get_rate_shift(dpcm); unsigned int rate_shift = get_rate_shift(dpcm);
spin_lock(&dpcm->timer_lock);
if (rate_shift != dpcm->pcm_rate_shift) { if (rate_shift != dpcm->pcm_rate_shift) {
dpcm->pcm_rate_shift = rate_shift; dpcm->pcm_rate_shift = rate_shift;
dpcm->period_size_frac = frac_pos(dpcm, dpcm->pcm_period_size); dpcm->period_size_frac = frac_pos(dpcm, dpcm->pcm_period_size);
...@@ -181,12 +183,15 @@ static void loopback_timer_start(struct loopback_pcm *dpcm) ...@@ -181,12 +183,15 @@ static void loopback_timer_start(struct loopback_pcm *dpcm)
tick = (tick + dpcm->pcm_bps - 1) / dpcm->pcm_bps; tick = (tick + dpcm->pcm_bps - 1) / dpcm->pcm_bps;
dpcm->timer.expires = jiffies + tick; dpcm->timer.expires = jiffies + tick;
add_timer(&dpcm->timer); add_timer(&dpcm->timer);
spin_unlock(&dpcm->timer_lock);
} }
static inline void loopback_timer_stop(struct loopback_pcm *dpcm) static inline void loopback_timer_stop(struct loopback_pcm *dpcm)
{ {
spin_lock(&dpcm->timer_lock);
del_timer(&dpcm->timer); del_timer(&dpcm->timer);
dpcm->timer.expires = 0; dpcm->timer.expires = 0;
spin_unlock(&dpcm->timer_lock);
} }
#define CABLE_VALID_PLAYBACK (1 << SNDRV_PCM_STREAM_PLAYBACK) #define CABLE_VALID_PLAYBACK (1 << SNDRV_PCM_STREAM_PLAYBACK)
...@@ -659,6 +664,7 @@ static int loopback_open(struct snd_pcm_substream *substream) ...@@ -659,6 +664,7 @@ static int loopback_open(struct snd_pcm_substream *substream)
dpcm->substream = substream; dpcm->substream = substream;
setup_timer(&dpcm->timer, loopback_timer_function, setup_timer(&dpcm->timer, loopback_timer_function,
(unsigned long)dpcm); (unsigned long)dpcm);
spin_lock_init(&dpcm->timer_lock);
cable = loopback->cables[substream->number][dev]; cable = loopback->cables[substream->number][dev];
if (!cable) { if (!cable) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment