From: Eugeniu Rosca <erosca@de.adit-jv.com> To: Lars-Peter Clausen <lars@metafoo.de>, Vinod Koul <vkoul@kernel.org>, Mark Brown <broonie@kernel.org>, Jaroslav Kysela <perex@perex.cz>, Takashi Iwai <tiwai@suse.com>, <alsa-devel@alsa-project.org>, <linux-kernel@vger.kernel.org> Cc: Jiada Wang <jiada_wang@mentor.com>, Dean Jenkins <Dean_Jenkins@mentor.com>, Eugeniu Rosca <erosca@de.adit-jv.com>, Andreas Pape <apape@de.adit-jv.com>, Eugeniu Rosca <roscaeugeniu@gmail.com> Subject: [PATCH] ALSA: dmaengine: increment buffer pointer atomically Date: Mon, 26 Sep 2022 18:58:13 +0200 [thread overview] Message-ID: <1664211493-11789-1-git-send-email-erosca@de.adit-jv.com> (raw) From: Andreas Pape <apape@de.adit-jv.com> Setting pointer and afterwards checking for wraparound leads to the possibility of returning the inconsistent pointer position. This patch increments buffer pointer atomically to avoid this issue. Fixes: e7f73a1613567a ("ASoC: Add dmaengine PCM helper functions") Signed-off-by: Andreas Pape <apape@de.adit-jv.com> Signed-off-by: Eugeniu Rosca <erosca@de.adit-jv.com> --- sound/core/pcm_dmaengine.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/sound/core/pcm_dmaengine.c b/sound/core/pcm_dmaengine.c index 5b2ca028f5aa..494ec0c207fa 100644 --- a/sound/core/pcm_dmaengine.c +++ b/sound/core/pcm_dmaengine.c @@ -133,12 +133,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 = prtd->pos + snd_pcm_lib_period_bytes(substream); + if (new_pos >= snd_pcm_lib_buffer_bytes(substream)) + new_pos = 0; + prtd->pos = new_pos; snd_pcm_period_elapsed(substream); } -- 2.37.2
WARNING: multiple messages have this Message-ID (diff)
From: Eugeniu Rosca <erosca@de.adit-jv.com> To: Lars-Peter Clausen <lars@metafoo.de>, Vinod Koul <vkoul@kernel.org>, Mark Brown <broonie@kernel.org>, Jaroslav Kysela <perex@perex.cz>, Takashi Iwai <tiwai@suse.com>, <alsa-devel@alsa-project.org>, <linux-kernel@vger.kernel.org> Cc: Jiada Wang <jiada_wang@mentor.com>, Dean Jenkins <Dean_Jenkins@mentor.com>, Andreas Pape <apape@de.adit-jv.com>, Eugeniu Rosca <erosca@de.adit-jv.com>, Eugeniu Rosca <roscaeugeniu@gmail.com> Subject: [PATCH] ALSA: dmaengine: increment buffer pointer atomically Date: Mon, 26 Sep 2022 18:58:13 +0200 [thread overview] Message-ID: <1664211493-11789-1-git-send-email-erosca@de.adit-jv.com> (raw) From: Andreas Pape <apape@de.adit-jv.com> Setting pointer and afterwards checking for wraparound leads to the possibility of returning the inconsistent pointer position. This patch increments buffer pointer atomically to avoid this issue. Fixes: e7f73a1613567a ("ASoC: Add dmaengine PCM helper functions") Signed-off-by: Andreas Pape <apape@de.adit-jv.com> Signed-off-by: Eugeniu Rosca <erosca@de.adit-jv.com> --- sound/core/pcm_dmaengine.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/sound/core/pcm_dmaengine.c b/sound/core/pcm_dmaengine.c index 5b2ca028f5aa..494ec0c207fa 100644 --- a/sound/core/pcm_dmaengine.c +++ b/sound/core/pcm_dmaengine.c @@ -133,12 +133,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 = prtd->pos + snd_pcm_lib_period_bytes(substream); + if (new_pos >= snd_pcm_lib_buffer_bytes(substream)) + new_pos = 0; + prtd->pos = new_pos; snd_pcm_period_elapsed(substream); } -- 2.37.2
next reply other threads:[~2022-09-26 16:59 UTC|newest] Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top 2022-09-26 16:58 Eugeniu Rosca [this message] 2022-09-26 16:58 ` [PATCH] ALSA: dmaengine: increment buffer pointer atomically Eugeniu Rosca 2022-09-27 6:55 ` Takashi Iwai 2022-09-27 6:55 ` Takashi Iwai
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=1664211493-11789-1-git-send-email-erosca@de.adit-jv.com \ --to=erosca@de.adit-jv.com \ --cc=Dean_Jenkins@mentor.com \ --cc=alsa-devel@alsa-project.org \ --cc=apape@de.adit-jv.com \ --cc=broonie@kernel.org \ --cc=jiada_wang@mentor.com \ --cc=lars@metafoo.de \ --cc=linux-kernel@vger.kernel.org \ --cc=perex@perex.cz \ --cc=roscaeugeniu@gmail.com \ --cc=tiwai@suse.com \ --cc=vkoul@kernel.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.