From: Vinod Koul <vinod.koul@intel.com>
To: Qais Yousef <qais.yousef@imgtec.com>
Cc: alsa-devel@alsa-project.org, Liam Girdwood <lgirdwood@gmail.com>,
Mark Brown <broonie@kernel.org>, Jaroslav Kysela <perex@perex.cz>,
Takashi Iwai <tiwai@suse.de>,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2] ALSA: ASoC: soc-compress.c: fix NULL dereference
Date: Tue, 13 Jan 2015 20:29:31 +0530 [thread overview]
Message-ID: <20150113145931.GD3085@intel.com> (raw)
In-Reply-To: <1421147933-21802-1-git-send-email-qais.yousef@imgtec.com>
On Tue, Jan 13, 2015 at 11:18:53AM +0000, Qais Yousef wrote:
> In soc_new_compress() when rtd->dai_link->daynmic is set, we create the pcm
^^^^^^^^
typo
> substreams with this call:
>
> ret = snd_pcm_new_internal(rtd->card->snd_card, new_name, num,
> 1, 0, &be_pcm);
>
> which passes 0 as capture_count leading to
>
> be_pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream
>
> being NULL, hence when trying to set rtd a few lines below we get an oops.
It is a good practice to add the oops here
>
> Fix by using rtd->dai_link->dpcm_playback and rtd->dai_link->dpcm_capture as
> playback_count and capture_count to snd_pcm_new_internal().
>
> Signed-off-by: Qais Yousef <qais.yousef@imgtec.com>
> Cc: Vinod Koul <vinod.koul@intel.com>
> Cc: Liam Girdwood <lgirdwood@gmail.com>
> Cc: Mark Brown <broonie@kernel.org>
> Cc: Jaroslav Kysela <perex@perex.cz>
> Cc: Takashi Iwai <tiwai@suse.de>
> Cc: linux-kernel@vger.kernel.org
> ---
> v2->v1:
> - use better way to fix it than just removing the line that caused the oops
>
> sound/soc/soc-compress.c | 9 ++++++---
> 1 file changed, 6 insertions(+), 3 deletions(-)
>
> diff --git a/sound/soc/soc-compress.c b/sound/soc/soc-compress.c
> index 590a82f01d0b..27a668463ad7 100644
> --- a/sound/soc/soc-compress.c
> +++ b/sound/soc/soc-compress.c
> @@ -659,7 +659,8 @@ int soc_new_compress(struct snd_soc_pcm_runtime *rtd, int num)
> rtd->dai_link->stream_name);
>
> ret = snd_pcm_new_internal(rtd->card->snd_card, new_name, num,
> - 1, 0, &be_pcm);
> + rtd->dai_link->dpcm_playback,
> + rtd->dai_link->dpcm_capture, &be_pcm);
> if (ret < 0) {
> dev_err(rtd->card->dev, "ASoC: can't create compressed for %s\n",
> rtd->dai_link->name);
> @@ -668,8 +669,10 @@ int soc_new_compress(struct snd_soc_pcm_runtime *rtd, int num)
>
> rtd->pcm = be_pcm;
> rtd->fe_compr = 1;
> - be_pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream->private_data = rtd;
> - be_pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream->private_data = rtd;
> + if (rtd->dai_link->dpcm_playback)
> + be_pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream->private_data = rtd;
> + if (rtd->dai_link->dpcm_capture)
this should be else if, as for compressed device we can have playback or
capture not both
> + be_pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream->private_data = rtd;
> memcpy(compr->ops, &soc_compr_dyn_ops, sizeof(soc_compr_dyn_ops));
> } else
> memcpy(compr->ops, &soc_compr_ops, sizeof(soc_compr_ops));
> --
> 2.1.0
>
--
~Vinod
next prev parent reply other threads:[~2015-01-13 15:00 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-01-13 11:18 [PATCH v2] ALSA: ASoC: soc-compress.c: fix NULL dereference Qais Yousef
2015-01-13 14:59 ` Vinod Koul [this message]
2015-01-13 15:16 ` Qais Yousef
2015-01-13 16:20 ` Mark Brown
2015-01-14 7:53 ` Qais Yousef
2015-01-13 17:21 ` James Hogan
2015-01-14 8:00 ` Qais Yousef
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=20150113145931.GD3085@intel.com \
--to=vinod.koul@intel.com \
--cc=alsa-devel@alsa-project.org \
--cc=broonie@kernel.org \
--cc=lgirdwood@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=perex@perex.cz \
--cc=qais.yousef@imgtec.com \
--cc=tiwai@suse.de \
/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