ASoC: dapm: Fix NULL pointer dereference when registering card with widgets
diff mbox

Message ID 1412339560-18019-1-git-send-email-jarkko.nikula@linux.intel.com
State Accepted
Commit b2d9de549c30170eed5691d369cf16680e0ce03a
Headers show

Commit Message

Jarkko Nikula Oct. 3, 2014, 12:32 p.m. UTC
Commit 0bd2ac3dae74 ("ASoC: Remove CODEC pointer from snd_soc_dapm_context")
introduced regression to snd_soc_dapm_new_controls() when registering a card
with card->dapm_widgets set. Call chain is:

    snd_soc_register_card()
    -> snd_soc_instantiate_card()
       -> snd_soc_dapm_new_controls()
          -> snd_soc_dapm_new_control()

Null pointer dereference occurs since card->dapm context doesn't have
associated component. Fix this by setting widget codec pointer
conditionally.

Signed-off-by: Jarkko Nikula <jarkko.nikula@linux.intel.com>
---
 sound/soc/soc-dapm.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Comments

Lars-Peter Clausen Oct. 3, 2014, 1:26 p.m. UTC | #1
On 10/03/2014 02:32 PM, Jarkko Nikula wrote:
> Commit 0bd2ac3dae74 ("ASoC: Remove CODEC pointer from snd_soc_dapm_context")
> introduced regression to snd_soc_dapm_new_controls() when registering a card
> with card->dapm_widgets set. Call chain is:
>
>      snd_soc_register_card()
>      -> snd_soc_instantiate_card()
>         -> snd_soc_dapm_new_controls()
>            -> snd_soc_dapm_new_control()
>
> Null pointer dereference occurs since card->dapm context doesn't have
> associated component. Fix this by setting widget codec pointer
> conditionally.
>
> Signed-off-by: Jarkko Nikula <jarkko.nikula@linux.intel.com>

Thanks. Stupid mistake.

Acked-by: Lars-Peter Clausen <lars@metafoo.de>
Mark Brown Oct. 3, 2014, 2:39 p.m. UTC | #2
On Fri, Oct 03, 2014 at 03:32:40PM +0300, Jarkko Nikula wrote:
> Commit 0bd2ac3dae74 ("ASoC: Remove CODEC pointer from snd_soc_dapm_context")
> introduced regression to snd_soc_dapm_new_controls() when registering a card
> with card->dapm_widgets set. Call chain is:

Applied, thanks.

Patch
diff mbox

diff --git a/sound/soc/soc-dapm.c b/sound/soc/soc-dapm.c
index 2d06892088d5..3f0b4108f7ca 100644
--- a/sound/soc/soc-dapm.c
+++ b/sound/soc/soc-dapm.c
@@ -3125,7 +3125,8 @@  snd_soc_dapm_new_control(struct snd_soc_dapm_context *dapm,
 	}
 
 	w->dapm = dapm;
-	w->codec = dapm->component->codec;
+	if (dapm->component)
+		w->codec = dapm->component->codec;
 	INIT_LIST_HEAD(&w->sources);
 	INIT_LIST_HEAD(&w->sinks);
 	INIT_LIST_HEAD(&w->list);