aboutsummaryrefslogtreecommitdiffstats
path: root/sound/soc/fsl
diff options
context:
space:
mode:
authorRussell King <rmk+kernel@arm.linux.org.uk>2013-06-27 07:53:37 -0400
committerRussell King <rmk+kernel@arm.linux.org.uk>2013-10-31 10:48:47 -0400
commitc9bd5e690a439df044678d89e89e380cf9db7930 (patch)
treee2f73839b2be962bd4b4f19279aafa38e7b72332 /sound/soc/fsl
parentfa6a8d6d65b19ab44e5244ea499bcd553cc72343 (diff)
DMA-API: sound: fix dma mask handling in a lot of drivers
This code sequence is unsafe in modules: static u64 mask = DMA_BIT_MASK(something); ... if (!dev->dma_mask) dev->dma_mask = &mask; as if a module is reloaded, the mask will be pointing at the original module's mask address, and this can lead to oopses. Moreover, they all follow this with: if (!dev->coherent_dma_mask) dev->coherent_dma_mask = mask; where 'mask' is the same value as the statically defined mask, and this bypasses the architecture's check on whether the DMA mask is possible. Fix these issues by using the new dma_coerce_coherent_and_mask() function. Acked-by: Mark Brown <broonie@linaro.org> Acked-by: Takashi Iwai <tiwai@suse.de> Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
Diffstat (limited to 'sound/soc/fsl')
-rw-r--r--sound/soc/fsl/fsl_dma.c9
-rw-r--r--sound/soc/fsl/imx-pcm-fiq.c12
-rw-r--r--sound/soc/fsl/mpc5200_dma.c10
3 files changed, 12 insertions, 19 deletions
diff --git a/sound/soc/fsl/fsl_dma.c b/sound/soc/fsl/fsl_dma.c
index 9cc5c1f82f09..f73c7eff8b23 100644
--- a/sound/soc/fsl/fsl_dma.c
+++ b/sound/soc/fsl/fsl_dma.c
@@ -298,14 +298,11 @@ static int fsl_dma_new(struct snd_soc_pcm_runtime *rtd)
298{ 298{
299 struct snd_card *card = rtd->card->snd_card; 299 struct snd_card *card = rtd->card->snd_card;
300 struct snd_pcm *pcm = rtd->pcm; 300 struct snd_pcm *pcm = rtd->pcm;
301 static u64 fsl_dma_dmamask = DMA_BIT_MASK(36);
302 int ret; 301 int ret;
303 302
304 if (!card->dev->dma_mask) 303 ret = dma_coerce_mask_and_coherent(card->dev, DMA_BIT_MASK(36));
305 card->dev->dma_mask = &fsl_dma_dmamask; 304 if (ret)
306 305 return ret;
307 if (!card->dev->coherent_dma_mask)
308 card->dev->coherent_dma_mask = fsl_dma_dmamask;
309 306
310 /* Some codecs have separate DAIs for playback and capture, so we 307 /* Some codecs have separate DAIs for playback and capture, so we
311 * should allocate a DMA buffer only for the streams that are valid. 308 * should allocate a DMA buffer only for the streams that are valid.
diff --git a/sound/soc/fsl/imx-pcm-fiq.c b/sound/soc/fsl/imx-pcm-fiq.c
index 34043c55f2a6..fd5f2fb955f1 100644
--- a/sound/soc/fsl/imx-pcm-fiq.c
+++ b/sound/soc/fsl/imx-pcm-fiq.c
@@ -272,18 +272,16 @@ static int imx_pcm_preallocate_dma_buffer(struct snd_pcm *pcm, int stream)
272 return 0; 272 return 0;
273} 273}
274 274
275static u64 imx_pcm_dmamask = DMA_BIT_MASK(32);
276
277static int imx_pcm_new(struct snd_soc_pcm_runtime *rtd) 275static int imx_pcm_new(struct snd_soc_pcm_runtime *rtd)
278{ 276{
279 struct snd_card *card = rtd->card->snd_card; 277 struct snd_card *card = rtd->card->snd_card;
280 struct snd_pcm *pcm = rtd->pcm; 278 struct snd_pcm *pcm = rtd->pcm;
281 int ret = 0; 279 int ret;
280
281 ret = dma_coerce_mask_and_coherent(card->dev, DMA_BIT_MASK(32));
282 if (ret)
283 return ret;
282 284
283 if (!card->dev->dma_mask)
284 card->dev->dma_mask = &imx_pcm_dmamask;
285 if (!card->dev->coherent_dma_mask)
286 card->dev->coherent_dma_mask = DMA_BIT_MASK(32);
287 if (pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream) { 285 if (pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream) {
288 ret = imx_pcm_preallocate_dma_buffer(pcm, 286 ret = imx_pcm_preallocate_dma_buffer(pcm,
289 SNDRV_PCM_STREAM_PLAYBACK); 287 SNDRV_PCM_STREAM_PLAYBACK);
diff --git a/sound/soc/fsl/mpc5200_dma.c b/sound/soc/fsl/mpc5200_dma.c
index 2a847ca494b5..8fcf22416740 100644
--- a/sound/soc/fsl/mpc5200_dma.c
+++ b/sound/soc/fsl/mpc5200_dma.c
@@ -299,7 +299,6 @@ static struct snd_pcm_ops psc_dma_ops = {
299 .hw_params = psc_dma_hw_params, 299 .hw_params = psc_dma_hw_params,
300}; 300};
301 301
302static u64 psc_dma_dmamask = DMA_BIT_MASK(32);
303static int psc_dma_new(struct snd_soc_pcm_runtime *rtd) 302static int psc_dma_new(struct snd_soc_pcm_runtime *rtd)
304{ 303{
305 struct snd_card *card = rtd->card->snd_card; 304 struct snd_card *card = rtd->card->snd_card;
@@ -307,15 +306,14 @@ static int psc_dma_new(struct snd_soc_pcm_runtime *rtd)
307 struct snd_pcm *pcm = rtd->pcm; 306 struct snd_pcm *pcm = rtd->pcm;
308 struct psc_dma *psc_dma = snd_soc_dai_get_drvdata(rtd->cpu_dai); 307 struct psc_dma *psc_dma = snd_soc_dai_get_drvdata(rtd->cpu_dai);
309 size_t size = psc_dma_hardware.buffer_bytes_max; 308 size_t size = psc_dma_hardware.buffer_bytes_max;
310 int rc = 0; 309 int rc;
311 310
312 dev_dbg(rtd->platform->dev, "psc_dma_new(card=%p, dai=%p, pcm=%p)\n", 311 dev_dbg(rtd->platform->dev, "psc_dma_new(card=%p, dai=%p, pcm=%p)\n",
313 card, dai, pcm); 312 card, dai, pcm);
314 313
315 if (!card->dev->dma_mask) 314 rc = dma_coerce_mask_and_coherent(card->dev, DMA_BIT_MASK(32));
316 card->dev->dma_mask = &psc_dma_dmamask; 315 if (rc)
317 if (!card->dev->coherent_dma_mask) 316 return rc;
318 card->dev->coherent_dma_mask = DMA_BIT_MASK(32);
319 317
320 if (pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream) { 318 if (pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream) {
321 rc = snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, pcm->card->dev, 319 rc = snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, pcm->card->dev,