ALSA: SOC: DMA: increment buffer pointer atomically
Subsystems (2)
PATCH v2 1/1 ALSA: SOC: DMA: increment buffer pointer atomically
From: Andreas Pape <[email protected]>
Setting pointer and afterwards check for wrap around leads to the possibility of returning the inconsistent pointer position. This patch increments buffer pointer atomically to avoid this issue.
Since commit: b7ae6f3 dmaengine implementation has been moved from ASoC to ALSA core. So change goes to sound/soc/soc-dmaengine-pcm.c, apply to sound/core/pcm_dmaengine.c now
cherry picked from ADIT v3.14 e2f803f("ALSA: SOC: DMA: increment buffer pointer atomically")
(cherry picked from ADIT v4.1 commit 9e7eff10a38157db75f12e032fc378d3104a2812)
(cherry picked from ADIT v4.9 commit 66c00aa1e7cd3b077fc2e5a45a4594b86246cf78)
---
v1 can be found in
http://mailman.alsa-project.org/pipermail/alsa-devel/2016-November/115277.html
sound/core/pcm_dmaengine.c +6 -4
@@ -139,12 +139,14 @@ EXPORT_SYMBOL_GPL(snd_dmaengine_pcm_set_config_from_dai_data);static void dmaengine_pcm_dma_complete (void *arg) { +unsigned int new_pos;struct snd_pcm_substream *substream = arg;struct dmaengine_pcm_runtime_data *prtd =substream_to_prtd (substream); - prtd->pos +=snd_pcm_lib_period_bytes (substream); -if (prtd->pos >=snd_pcm_lib_buffer_bytes (substream)) - prtd->pos =0 ; + new_pos =READ_ONCE (prtd->pos) +snd_pcm_lib_period_bytes (substream); +if (new_pos >=snd_pcm_lib_buffer_bytes (substream)) + new_pos =0 ; +WRITE_ONCE (prtd->pos, new_pos);snd_pcm_period_elapsed (substream); }
@@ -235,7 +237,7 @@ EXPORT_SYMBOL_GPL(snd_dmaengine_pcm_trigger);snd_pcm_uframes_t snd_dmaengine_pcm_pointer_no_residue (struct snd_pcm_substream *substream) {struct dmaengine_pcm_runtime_data *prtd =substream_to_prtd (substream); -return bytes_to_frames (substream->runtime, prtd->pos); +return bytes_to_frames (substream->runtime,READ_ONCE (prtd->pos)); }EXPORT_SYMBOL_GPL (snd_dmaengine_pcm_pointer_no_residue);
Signature · 1 line
2.7.4
Hi all,
Any comments to the patch in [1]?
Should I change anything?
[1] http://mailman.alsa-project.org/pipermail/alsa-devel/2018-July/138319.html
Best regards
*Timo Wischer*
*A*dvanced *D*river *I*nformation *T*echnology GmbH Engineering Software Base (ADITG/ESB) Robert-Bosch-Str. 200
31139 Hildesheim
Germany
Tel. +49 5121 49 6938
Fax +49 5121 49 6999
[email protected]
ADIT is a joint venture company of Robert Bosch GmbH/Robert Bosch Car Multimedia GmbH and DENSO Corporation
Sitz: Hildesheim, Registergericht: Amtsgericht Hildesheim HRB 3438
Geschäftsführung: Wilhelm Grabow, Ken Yaguchi
Quoted 48 lines · On 07/19/2018 12:29 PM, [email protected] wrote:
From: Andreas Pape <[email protected]>
Setting pointer and afterwards check for wrap around leads to the possibility of returning the inconsistent pointer position. This patch increments buffer pointer atomically to avoid this issue.
Signed-off-by Andreas Pape <[email protected]>Since commit: b7ae6f3 dmaengine implementation has been moved from ASoC to ALSA core. So change goes to
sound/soc/soc-dmaengine-pcm.c, apply tosound/core/pcm_dmaengine.cnowcherry picked from ADIT v3.14
e2f803f("ALSA: SOC: DMA: increment buffer pointer atomically")Signed-off-by Veeraiyan Chidambaram <[email protected]>(cherry picked from ADIT v4.1 commit
9e7eff10a38157db75f12e032fc378d3104a2812)Signed-off-by Takashi Sakamoto <[email protected]>(cherry picked from ADIT v4.9 commit
66c00aa1e7cd3b077fc2e5a45a4594b86246cf78)Signed-off-by Jiada Wang <[email protected]>Signed-off-by Timo Wischer <[email protected]>---
v1 can be found in
http://mailman.alsa-project.org/pipermail/alsa-devel/2016-November/115277.htmlsound/core/pcm_dmaengine.c +5
-3@@ -139,12 +139,14 @@ EXPORT_SYMBOL_GPL(snd_dmaengine_pcm_set_config_from_dai_data);static void dmaengine_pcm_dma_complete (void *arg) { +unsigned int new_pos;struct snd_pcm_substream *substream = arg;struct dmaengine_pcm_runtime_data *prtd =substream_to_prtd (substream); - prtd->pos +=snd_pcm_lib_period_bytes (substream); -if (prtd->pos >=snd_pcm_lib_buffer_bytes (substream)) - prtd->pos =0 ; + new_pos =READ_ONCE (prtd->pos) +snd_pcm_lib_period_bytes (substream); +if (new_pos >=snd_pcm_lib_buffer_bytes (substream)) + new_pos =0 ; +WRITE_ONCE (prtd->pos, new_pos);snd_pcm_period_elapsed (substream); }
sound/core/pcm_dmaengine.c EXPORT_SYMBOL_GPL(snd_dmaengine_pcm_trigger); · line 243
Quoted 8 lines
sound/core/pcm_dmaengine.c +1
-1@@ -235,7 +237,7 @@ EXPORT_SYMBOL_GPL(snd_dmaengine_pcm_trigger);snd_pcm_uframes_t snd_dmaengine_pcm_pointer_no_residue (struct snd_pcm_substream *substream) {struct dmaengine_pcm_runtime_data *prtd =substream_to_prtd (substream); -return bytes_to_frames (substream->runtime, prtd->pos); +return bytes_to_frames (substream->runtime,READ_ONCE (prtd->pos)); }EXPORT_SYMBOL_GPL (snd_dmaengine_pcm_pointer_no_residue);
_______________________________________________
Alsa-devel mailing list
[email protected]
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel