Skip to content

Commit fc7dc61

Browse files
Oskar Schirmerbroonie
authored andcommitted
ASoC: fsl: imx-pcm-fiq: omit fiq counter to avoid harm in unbalanced situations
Unbalanced calls to snd_imx_pcm_trigger() may result in endless FIQ activity and thus provoke eternal sound. While on the first glance, the switch statement looks pretty symmetric, the SUSPEND/RESUME pair is not: the suspend case comes along snd_pcm_suspend_all(), which for fsl/imx-pcm-fiq is called only at snd_soc_suspend(), but the resume case originates straight from the SNDRV_PCM_IOCTL_RESUME. This way userland may provoke an unbalanced resume, which might cause the fiq_enable counter to increase and never return to zero again, so eventually imx_pcm_fiq is never disabled. Simply removing the fiq_enable will solve the problem, as long as one never goes play and capture game simultaneously, but beware trying both at once, the early TRIGGER_STOP will cut off the other activity prematurely. So now playing and capturing is scrutinized separately, instead of by counting. Signed-off-by: Oskar Schirmer <oskar@scara.com> Signed-off-by: Mark Brown <broonie@linaro.org> Cc: stable@vger.kernel.org
1 parent 71d0c3a commit fc7dc61

File tree

1 file changed

+17
-12
lines changed

1 file changed

+17
-12
lines changed

sound/soc/fsl/imx-pcm-fiq.c

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ struct imx_pcm_runtime_data {
4444
struct hrtimer hrt;
4545
int poll_time_ns;
4646
struct snd_pcm_substream *substream;
47-
atomic_t running;
47+
atomic_t playing;
48+
atomic_t capturing;
4849
};
4950

5051
static enum hrtimer_restart snd_hrtimer_callback(struct hrtimer *hrt)
@@ -56,7 +57,7 @@ static enum hrtimer_restart snd_hrtimer_callback(struct hrtimer *hrt)
5657
struct pt_regs regs;
5758
unsigned long delta;
5859

59-
if (!atomic_read(&iprtd->running))
60+
if (!atomic_read(&iprtd->playing) && !atomic_read(&iprtd->capturing))
6061
return HRTIMER_NORESTART;
6162

6263
get_fiq_regs(&regs);
@@ -124,7 +125,6 @@ static int snd_imx_pcm_prepare(struct snd_pcm_substream *substream)
124125
return 0;
125126
}
126127

127-
static int fiq_enable;
128128
static int imx_pcm_fiq;
129129

130130
static int snd_imx_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
@@ -136,23 +136,27 @@ static int snd_imx_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
136136
case SNDRV_PCM_TRIGGER_START:
137137
case SNDRV_PCM_TRIGGER_RESUME:
138138
case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
139-
atomic_set(&iprtd->running, 1);
139+
if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
140+
atomic_set(&iprtd->playing, 1);
141+
else
142+
atomic_set(&iprtd->capturing, 1);
140143
hrtimer_start(&iprtd->hrt, ns_to_ktime(iprtd->poll_time_ns),
141144
HRTIMER_MODE_REL);
142-
if (++fiq_enable == 1)
143-
enable_fiq(imx_pcm_fiq);
144-
145+
enable_fiq(imx_pcm_fiq);
145146
break;
146147

147148
case SNDRV_PCM_TRIGGER_STOP:
148149
case SNDRV_PCM_TRIGGER_SUSPEND:
149150
case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
150-
atomic_set(&iprtd->running, 0);
151-
152-
if (--fiq_enable == 0)
151+
if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
152+
atomic_set(&iprtd->playing, 0);
153+
else
154+
atomic_set(&iprtd->capturing, 0);
155+
if (!atomic_read(&iprtd->playing) &&
156+
!atomic_read(&iprtd->capturing))
153157
disable_fiq(imx_pcm_fiq);
154-
155158
break;
159+
156160
default:
157161
return -EINVAL;
158162
}
@@ -200,7 +204,8 @@ static int snd_imx_open(struct snd_pcm_substream *substream)
200204

201205
iprtd->substream = substream;
202206

203-
atomic_set(&iprtd->running, 0);
207+
atomic_set(&iprtd->playing, 0);
208+
atomic_set(&iprtd->capturing, 0);
204209
hrtimer_init(&iprtd->hrt, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
205210
iprtd->hrt.function = snd_hrtimer_callback;
206211

0 commit comments

Comments
 (0)