From: Lars-Peter Clausen <lars@metafoo.de>
To: Misael Lopez Cruz <misael.lopez@ti.com>, alsa-devel@alsa-project.org
Cc: Peter Ujfalusi <peter.ujfalusi@ti.com>,
Mark Brown <broonie@kernel.org>,
Liam Girdwood <lgirdwood@gmail.com>
Subject: Re: [PATCH] ALSA: pcm_dmaengine: Run complete cb only if runtime check passes
Date: Wed, 15 Jul 2015 22:05:19 +0200 [thread overview]
Message-ID: <55A6BCFF.2030302@metafoo.de> (raw)
In-Reply-To: <1436980994-29340-1-git-send-email-misael.lopez@ti.com>
On 07/15/2015 07:23 PM, Misael Lopez Cruz wrote:
> The DMA complete callback uses substream's runtime data, so make
> sure the runtime check passes before going forward.
>
> The callback could run while the stream is closing or after it's
> already closed. By then, the substream's runtime data might already
> been freed and cause NULL pointer dereferences.
If the callback runs after the stream has been closed that's a bug in the
DMAengine driver. This patch does not fix the issue, the sub-stream itself
might have been freed as well, so things will still crash.
To fix a potential race condition that can happen if one cpu is running the
callback handlers and the stream is closed from another see this thread:
http://www.spinics.net/lists/dmaengine/msg05126.html
- Lars
>
> Signed-off-by: Misael Lopez Cruz <misael.lopez@ti.com>
> Reviewed-by: Peter Ujfalusi <peter.ujfalusi@ti.com>
> ---
> sound/core/pcm_dmaengine.c | 7 ++++++-
> 1 file changed, 6 insertions(+), 1 deletion(-)
>
> diff --git a/sound/core/pcm_dmaengine.c b/sound/core/pcm_dmaengine.c
> index fba365a..061a8f7 100644
> --- a/sound/core/pcm_dmaengine.c
> +++ b/sound/core/pcm_dmaengine.c
> @@ -133,7 +133,12 @@ EXPORT_SYMBOL_GPL(snd_dmaengine_pcm_set_config_from_dai_data);
> static void dmaengine_pcm_dma_complete(void *arg)
> {
> struct snd_pcm_substream *substream = arg;
> - struct dmaengine_pcm_runtime_data *prtd = substream_to_prtd(substream);
> + struct dmaengine_pcm_runtime_data *prtd;
> +
> + if (PCM_RUNTIME_CHECK(substream))
> + return;
> +
> + prtd = substream_to_prtd(substream);
>
> prtd->pos += snd_pcm_lib_period_bytes(substream);
> if (prtd->pos >= snd_pcm_lib_buffer_bytes(substream))
>
prev parent reply other threads:[~2015-07-15 20:05 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-07-15 17:23 [PATCH] ALSA: pcm_dmaengine: Run complete cb only if runtime check passes Misael Lopez Cruz
2015-07-15 20:05 ` Lars-Peter Clausen [this message]
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=55A6BCFF.2030302@metafoo.de \
--to=lars@metafoo.de \
--cc=alsa-devel@alsa-project.org \
--cc=broonie@kernel.org \
--cc=lgirdwood@gmail.com \
--cc=misael.lopez@ti.com \
--cc=peter.ujfalusi@ti.com \
/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: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox