diff mbox

[v2,3/5] ASoC: dapm: Append "Autodisable" to autodisable widget names

Message ID 1430411912-6599-3-git-send-email-ckeepax@opensource.wolfsonmicro.com (mailing list archive)
State New, archived
Headers show

Commit Message

Charles Keepax April 30, 2015, 4:38 p.m. UTC
This makes it a little easier to follow what is happening in debugfs.
Additionally is also useful in facilitating work to add autodisable
muxes because the control name is already used for the mux widget and
thus shouldn't be reused for the autodisable widget.

Signed-off-by: Charles Keepax <ckeepax@opensource.wolfsonmicro.com>
---
 sound/soc/soc-dapm.c |   22 +++++++++++++++++++---
 1 files changed, 19 insertions(+), 3 deletions(-)

Comments

Lars-Peter Clausen April 30, 2015, 5:40 p.m. UTC | #1
On 04/30/2015 06:38 PM, Charles Keepax wrote:
> diff --git a/sound/soc/soc-dapm.c b/sound/soc/soc-dapm.c
> index beb48b6..e557018 100644
> --- a/sound/soc/soc-dapm.c
> +++ b/sound/soc/soc-dapm.c
> @@ -308,11 +308,19 @@ static int dapm_kcontrol_data_alloc(struct snd_soc_dapm_widget *widget,
>   {
>   	struct dapm_kcontrol_data *data;
>   	struct soc_mixer_control *mc;
> +	const char *name;
> +	int ret;
>
>   	data = kzalloc(sizeof(*data), GFP_KERNEL);
>   	if (!data)
>   		return -ENOMEM;
>
> +	name = kasprintf(GFP_KERNEL, "%s %s", kcontrol->id.name, "Autodisable");

We should only allocate the name if we create a widget, otherwise we are 
going to leak the memory.

> +	if (!name) {
> +		ret = -ENOMEM;
> +		goto err_data;
> +	}
> +
>   	INIT_LIST_HEAD(&data->paths);
>
diff mbox

Patch

diff --git a/sound/soc/soc-dapm.c b/sound/soc/soc-dapm.c
index beb48b6..e557018 100644
--- a/sound/soc/soc-dapm.c
+++ b/sound/soc/soc-dapm.c
@@ -308,11 +308,19 @@  static int dapm_kcontrol_data_alloc(struct snd_soc_dapm_widget *widget,
 {
 	struct dapm_kcontrol_data *data;
 	struct soc_mixer_control *mc;
+	const char *name;
+	int ret;
 
 	data = kzalloc(sizeof(*data), GFP_KERNEL);
 	if (!data)
 		return -ENOMEM;
 
+	name = kasprintf(GFP_KERNEL, "%s %s", kcontrol->id.name, "Autodisable");
+	if (!name) {
+		ret = -ENOMEM;
+		goto err_data;
+	}
+
 	INIT_LIST_HEAD(&data->paths);
 
 	switch (widget->id) {
@@ -334,15 +342,15 @@  static int dapm_kcontrol_data_alloc(struct snd_soc_dapm_widget *widget,
 				template.off_val = 0;
 			template.on_val = template.off_val;
 			template.id = snd_soc_dapm_kcontrol;
-			template.name = kcontrol->id.name;
+			template.name = name;
 
 			data->value = template.on_val;
 
 			data->widget = snd_soc_dapm_new_control(widget->dapm,
 				&template);
 			if (!data->widget) {
-				kfree(data);
-				return -ENOMEM;
+				ret = -ENOMEM;
+				goto err_name;
 			}
 		}
 		break;
@@ -353,11 +361,19 @@  static int dapm_kcontrol_data_alloc(struct snd_soc_dapm_widget *widget,
 	kcontrol->private_data = data;
 
 	return 0;
+
+err_name:
+	kfree(name);
+err_data:
+	kfree(data);
+	return ret;
 }
 
 static void dapm_kcontrol_free(struct snd_kcontrol *kctl)
 {
 	struct dapm_kcontrol_data *data = snd_kcontrol_chip(kctl);
+	if (data->widget)
+		kfree(data->widget->name);
 	kfree(data->wlist);
 	kfree(data);
 }