diff options
author | Lars-Peter Clausen <lars@metafoo.de> | 2013-05-14 05:05:32 -0400 |
---|---|---|
committer | Mark Brown <broonie@opensource.wolfsonmicro.com> | 2013-05-14 08:52:52 -0400 |
commit | 2b581074357c42f63ae827ee28c9f244b91a38ac (patch) | |
tree | 9b809dd8b56bcfc88393328f58919ca9a8215109 /sound/soc/soc-dapm.c | |
parent | bd477c31ca3ae85645fb2852bfa3954a623f9237 (diff) |
ASoC: core: Use kasprintf instead of opencoding it
kasprintf calculates the size of the result string, allocates a buffer large
enough to hold the string and then performs the format string operation. There
are a couple of places in ASoC where these three steps are done by hand and
where kasprintf can be used instead.
Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
Acked-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Diffstat (limited to 'sound/soc/soc-dapm.c')
-rw-r--r-- | sound/soc/soc-dapm.c | 31 |
1 files changed, 10 insertions, 21 deletions
diff --git a/sound/soc/soc-dapm.c b/sound/soc/soc-dapm.c index e4e5420de725..071579be7cb9 100644 --- a/sound/soc/soc-dapm.c +++ b/sound/soc/soc-dapm.c | |||
@@ -521,7 +521,6 @@ static int dapm_create_or_share_mixmux_kcontrol(struct snd_soc_dapm_widget *w, | |||
521 | int wlistentries; | 521 | int wlistentries; |
522 | size_t wlistsize; | 522 | size_t wlistsize; |
523 | bool wname_in_long_name, kcname_in_long_name; | 523 | bool wname_in_long_name, kcname_in_long_name; |
524 | size_t name_len; | ||
525 | char *long_name; | 524 | char *long_name; |
526 | const char *name; | 525 | const char *name; |
527 | int ret; | 526 | int ret; |
@@ -586,25 +585,19 @@ static int dapm_create_or_share_mixmux_kcontrol(struct snd_soc_dapm_widget *w, | |||
586 | } | 585 | } |
587 | 586 | ||
588 | if (wname_in_long_name && kcname_in_long_name) { | 587 | if (wname_in_long_name && kcname_in_long_name) { |
589 | name_len = strlen(w->name) - prefix_len + 1 + | ||
590 | strlen(w->kcontrol_news[kci].name) + 1; | ||
591 | |||
592 | long_name = kmalloc(name_len, GFP_KERNEL); | ||
593 | if (long_name == NULL) { | ||
594 | kfree(wlist); | ||
595 | return -ENOMEM; | ||
596 | } | ||
597 | |||
598 | /* | 588 | /* |
599 | * The control will get a prefix from the control | 589 | * The control will get a prefix from the control |
600 | * creation process but we're also using the same | 590 | * creation process but we're also using the same |
601 | * prefix for widgets so cut the prefix off the | 591 | * prefix for widgets so cut the prefix off the |
602 | * front of the widget name. | 592 | * front of the widget name. |
603 | */ | 593 | */ |
604 | snprintf(long_name, name_len, "%s %s", | 594 | long_name = kasprintf(GFP_KERNEL, "%s %s", |
605 | w->name + prefix_len, | 595 | w->name + prefix_len, |
606 | w->kcontrol_news[kci].name); | 596 | w->kcontrol_news[kci].name); |
607 | long_name[name_len - 1] = '\0'; | 597 | if (long_name == NULL) { |
598 | kfree(wlist); | ||
599 | return -ENOMEM; | ||
600 | } | ||
608 | 601 | ||
609 | name = long_name; | 602 | name = long_name; |
610 | } else if (wname_in_long_name) { | 603 | } else if (wname_in_long_name) { |
@@ -3077,7 +3070,6 @@ snd_soc_dapm_new_control(struct snd_soc_dapm_context *dapm, | |||
3077 | const struct snd_soc_dapm_widget *widget) | 3070 | const struct snd_soc_dapm_widget *widget) |
3078 | { | 3071 | { |
3079 | struct snd_soc_dapm_widget *w; | 3072 | struct snd_soc_dapm_widget *w; |
3080 | size_t name_len; | ||
3081 | int ret; | 3073 | int ret; |
3082 | 3074 | ||
3083 | if ((w = dapm_cnew_widget(widget)) == NULL) | 3075 | if ((w = dapm_cnew_widget(widget)) == NULL) |
@@ -3118,19 +3110,16 @@ snd_soc_dapm_new_control(struct snd_soc_dapm_context *dapm, | |||
3118 | break; | 3110 | break; |
3119 | } | 3111 | } |
3120 | 3112 | ||
3121 | name_len = strlen(widget->name) + 1; | ||
3122 | if (dapm->codec && dapm->codec->name_prefix) | 3113 | if (dapm->codec && dapm->codec->name_prefix) |
3123 | name_len += 1 + strlen(dapm->codec->name_prefix); | 3114 | w->name = kasprintf(GFP_KERNEL, "%s %s", |
3124 | w->name = kmalloc(name_len, GFP_KERNEL); | 3115 | dapm->codec->name_prefix, widget->name); |
3116 | else | ||
3117 | w->name = kasprintf(GFP_KERNEL, "%s", widget->name); | ||
3118 | |||
3125 | if (w->name == NULL) { | 3119 | if (w->name == NULL) { |
3126 | kfree(w); | 3120 | kfree(w); |
3127 | return NULL; | 3121 | return NULL; |
3128 | } | 3122 | } |
3129 | if (dapm->codec && dapm->codec->name_prefix) | ||
3130 | snprintf((char *)w->name, name_len, "%s %s", | ||
3131 | dapm->codec->name_prefix, widget->name); | ||
3132 | else | ||
3133 | snprintf((char *)w->name, name_len, "%s", widget->name); | ||
3134 | 3123 | ||
3135 | switch (w->id) { | 3124 | switch (w->id) { |
3136 | case snd_soc_dapm_switch: | 3125 | case snd_soc_dapm_switch: |