diff options
author | Oskar Schirmer <oskar@scara.com> | 2013-11-12 10:46:38 -0500 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2013-12-04 13:55:48 -0500 |
commit | b63d5e491bbbab6f97cc4432334d3a2539cd4a1c (patch) | |
tree | 626f84d4e1d9568042b38ea54debe0935cfe6671 /sound | |
parent | ddf2f8881b5a608c9a55f3944b6e39a3decc5e4b (diff) |
ASoC: fsl: imx-pcm-fiq: omit fiq counter to avoid harm in unbalanced situations
commit fc7dc61d9a87011aaf8a6eb3144ebf9552adf5d2 upstream.
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>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'sound')
-rw-r--r-- | sound/soc/fsl/imx-pcm-fiq.c | 29 |
1 files changed, 17 insertions, 12 deletions
diff --git a/sound/soc/fsl/imx-pcm-fiq.c b/sound/soc/fsl/imx-pcm-fiq.c index 670b96b0ce2f..dcfd0fae0b35 100644 --- a/sound/soc/fsl/imx-pcm-fiq.c +++ b/sound/soc/fsl/imx-pcm-fiq.c | |||
@@ -42,7 +42,8 @@ struct imx_pcm_runtime_data { | |||
42 | struct hrtimer hrt; | 42 | struct hrtimer hrt; |
43 | int poll_time_ns; | 43 | int poll_time_ns; |
44 | struct snd_pcm_substream *substream; | 44 | struct snd_pcm_substream *substream; |
45 | atomic_t running; | 45 | atomic_t playing; |
46 | atomic_t capturing; | ||
46 | }; | 47 | }; |
47 | 48 | ||
48 | static enum hrtimer_restart snd_hrtimer_callback(struct hrtimer *hrt) | 49 | static enum hrtimer_restart snd_hrtimer_callback(struct hrtimer *hrt) |
@@ -54,7 +55,7 @@ static enum hrtimer_restart snd_hrtimer_callback(struct hrtimer *hrt) | |||
54 | struct pt_regs regs; | 55 | struct pt_regs regs; |
55 | unsigned long delta; | 56 | unsigned long delta; |
56 | 57 | ||
57 | if (!atomic_read(&iprtd->running)) | 58 | if (!atomic_read(&iprtd->playing) && !atomic_read(&iprtd->capturing)) |
58 | return HRTIMER_NORESTART; | 59 | return HRTIMER_NORESTART; |
59 | 60 | ||
60 | get_fiq_regs(®s); | 61 | get_fiq_regs(®s); |
@@ -122,7 +123,6 @@ static int snd_imx_pcm_prepare(struct snd_pcm_substream *substream) | |||
122 | return 0; | 123 | return 0; |
123 | } | 124 | } |
124 | 125 | ||
125 | static int fiq_enable; | ||
126 | static int imx_pcm_fiq; | 126 | static int imx_pcm_fiq; |
127 | 127 | ||
128 | static int snd_imx_pcm_trigger(struct snd_pcm_substream *substream, int cmd) | 128 | static int snd_imx_pcm_trigger(struct snd_pcm_substream *substream, int cmd) |
@@ -134,23 +134,27 @@ static int snd_imx_pcm_trigger(struct snd_pcm_substream *substream, int cmd) | |||
134 | case SNDRV_PCM_TRIGGER_START: | 134 | case SNDRV_PCM_TRIGGER_START: |
135 | case SNDRV_PCM_TRIGGER_RESUME: | 135 | case SNDRV_PCM_TRIGGER_RESUME: |
136 | case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: | 136 | case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: |
137 | atomic_set(&iprtd->running, 1); | 137 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) |
138 | atomic_set(&iprtd->playing, 1); | ||
139 | else | ||
140 | atomic_set(&iprtd->capturing, 1); | ||
138 | hrtimer_start(&iprtd->hrt, ns_to_ktime(iprtd->poll_time_ns), | 141 | hrtimer_start(&iprtd->hrt, ns_to_ktime(iprtd->poll_time_ns), |
139 | HRTIMER_MODE_REL); | 142 | HRTIMER_MODE_REL); |
140 | if (++fiq_enable == 1) | 143 | enable_fiq(imx_pcm_fiq); |
141 | enable_fiq(imx_pcm_fiq); | ||
142 | |||
143 | break; | 144 | break; |
144 | 145 | ||
145 | case SNDRV_PCM_TRIGGER_STOP: | 146 | case SNDRV_PCM_TRIGGER_STOP: |
146 | case SNDRV_PCM_TRIGGER_SUSPEND: | 147 | case SNDRV_PCM_TRIGGER_SUSPEND: |
147 | case SNDRV_PCM_TRIGGER_PAUSE_PUSH: | 148 | case SNDRV_PCM_TRIGGER_PAUSE_PUSH: |
148 | atomic_set(&iprtd->running, 0); | 149 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) |
149 | 150 | atomic_set(&iprtd->playing, 0); | |
150 | if (--fiq_enable == 0) | 151 | else |
152 | atomic_set(&iprtd->capturing, 0); | ||
153 | if (!atomic_read(&iprtd->playing) && | ||
154 | !atomic_read(&iprtd->capturing)) | ||
151 | disable_fiq(imx_pcm_fiq); | 155 | disable_fiq(imx_pcm_fiq); |
152 | |||
153 | break; | 156 | break; |
157 | |||
154 | default: | 158 | default: |
155 | return -EINVAL; | 159 | return -EINVAL; |
156 | } | 160 | } |
@@ -198,7 +202,8 @@ static int snd_imx_open(struct snd_pcm_substream *substream) | |||
198 | 202 | ||
199 | iprtd->substream = substream; | 203 | iprtd->substream = substream; |
200 | 204 | ||
201 | atomic_set(&iprtd->running, 0); | 205 | atomic_set(&iprtd->playing, 0); |
206 | atomic_set(&iprtd->capturing, 0); | ||
202 | hrtimer_init(&iprtd->hrt, CLOCK_MONOTONIC, HRTIMER_MODE_REL); | 207 | hrtimer_init(&iprtd->hrt, CLOCK_MONOTONIC, HRTIMER_MODE_REL); |
203 | iprtd->hrt.function = snd_hrtimer_callback; | 208 | iprtd->hrt.function = snd_hrtimer_callback; |
204 | 209 | ||