aboutsummaryrefslogtreecommitdiffstats
path: root/sound/soc/soc-dapm.c
diff options
context:
space:
mode:
authorDaniel Mack <daniel@zonque.org>2014-10-07 07:41:24 -0400
committerMark Brown <broonie@kernel.org>2014-10-07 08:11:35 -0400
commite5092c96c9c28f4d12811edcd02ca8eec16e748e (patch)
tree67be9d9351f59ab72e9f93242908190ad9c79ae4 /sound/soc/soc-dapm.c
parenta5448c88b812390a3622e76d774e10c0da1fb970 (diff)
ASoC: soc-dapm: fix use after free
Coverity spotted the following possible use-after-free condition in dapm_create_or_share_mixmux_kcontrol(): If kcontrol is NULL, and (wname_in_long_name && kcname_in_long_name) validates to true, 'name' will be set to an allocated string, and be freed a few lines later via the 'long_name' alias. 'name', however, is used by dev_err() in case snd_ctl_add() fails. Fix this by adding a jump label that frees 'long_name' at the end of the function. Signed-off-by: Daniel Mack <daniel@zonque.org> Signed-off-by: Mark Brown <broonie@kernel.org> Cc: stable@vger.kernel.org
Diffstat (limited to 'sound/soc/soc-dapm.c')
-rw-r--r--sound/soc/soc-dapm.c25
1 files changed, 14 insertions, 11 deletions
diff --git a/sound/soc/soc-dapm.c b/sound/soc/soc-dapm.c
index 2c456a376ade..c61cb9cedbcd 100644
--- a/sound/soc/soc-dapm.c
+++ b/sound/soc/soc-dapm.c
@@ -592,9 +592,9 @@ static int dapm_create_or_share_mixmux_kcontrol(struct snd_soc_dapm_widget *w,
592 int shared; 592 int shared;
593 struct snd_kcontrol *kcontrol; 593 struct snd_kcontrol *kcontrol;
594 bool wname_in_long_name, kcname_in_long_name; 594 bool wname_in_long_name, kcname_in_long_name;
595 char *long_name; 595 char *long_name = NULL;
596 const char *name; 596 const char *name;
597 int ret; 597 int ret = 0;
598 598
599 prefix = soc_dapm_prefix(dapm); 599 prefix = soc_dapm_prefix(dapm);
600 if (prefix) 600 if (prefix)
@@ -653,15 +653,17 @@ static int dapm_create_or_share_mixmux_kcontrol(struct snd_soc_dapm_widget *w,
653 653
654 kcontrol = snd_soc_cnew(&w->kcontrol_news[kci], NULL, name, 654 kcontrol = snd_soc_cnew(&w->kcontrol_news[kci], NULL, name,
655 prefix); 655 prefix);
656 kfree(long_name); 656 if (!kcontrol) {
657 if (!kcontrol) 657 ret = -ENOMEM;
658 return -ENOMEM; 658 goto exit_free;
659 }
660
659 kcontrol->private_free = dapm_kcontrol_free; 661 kcontrol->private_free = dapm_kcontrol_free;
660 662
661 ret = dapm_kcontrol_data_alloc(w, kcontrol); 663 ret = dapm_kcontrol_data_alloc(w, kcontrol);
662 if (ret) { 664 if (ret) {
663 snd_ctl_free_one(kcontrol); 665 snd_ctl_free_one(kcontrol);
664 return ret; 666 goto exit_free;
665 } 667 }
666 668
667 ret = snd_ctl_add(card, kcontrol); 669 ret = snd_ctl_add(card, kcontrol);
@@ -669,17 +671,18 @@ static int dapm_create_or_share_mixmux_kcontrol(struct snd_soc_dapm_widget *w,
669 dev_err(dapm->dev, 671 dev_err(dapm->dev,
670 "ASoC: failed to add widget %s dapm kcontrol %s: %d\n", 672 "ASoC: failed to add widget %s dapm kcontrol %s: %d\n",
671 w->name, name, ret); 673 w->name, name, ret);
672 return ret; 674 goto exit_free;
673 } 675 }
674 } 676 }
675 677
676 ret = dapm_kcontrol_add_widget(kcontrol, w); 678 ret = dapm_kcontrol_add_widget(kcontrol, w);
677 if (ret) 679 if (ret == 0)
678 return ret; 680 w->kcontrols[kci] = kcontrol;
679 681
680 w->kcontrols[kci] = kcontrol; 682exit_free:
683 kfree(long_name);
681 684
682 return 0; 685 return ret;
683} 686}
684 687
685/* create new dapm mixer control */ 688/* create new dapm mixer control */