All of lore.kernel.org
 help / color / mirror / Atom feed
From: Charles Keepax <ckeepax@opensource.cirrus.com>
To: yesanishhere@gmail.com
Cc: alsa-devel@alsa-project.org, broonie@kernel.org, tiwai@suse.com,
	lgirdwood@gmail.com
Subject: Re: [Resend] [PATCH 3/4] ASoC: dapm: Avoid creating kcontrol for params
Date: Wed, 20 Sep 2017 12:05:34 +0100	[thread overview]
Message-ID: <20170920110534.exix6dqf4la2nday@localhost.localdomain> (raw)
In-Reply-To: <1505896116-43310-4-git-send-email-yesanishhere@gmail.com>

On Wed, Sep 20, 2017 at 01:28:35AM -0700, yesanishhere@gmail.com wrote:
> From: anish kumar <yesanishhere@gmail.com>
> 
> Currently in codec to codec dai link if there are multiple
> params defined then dapm can use created kcontrol to
> decide which param to apply at runtime.
> 
> However, in case there is only single param configuration
> then there is no point in creating the kcontrol and also there
> is no point in allocating memory for kcontrol.
> 
> In the snd_soc_dapm_new_pcm function, there is memory
> allocation happening for kcontrol which is later used
> or not used based on num_param. It is better to not
> allocate memory when there is only a single configuration.
> This change is to remedy that anomaly.
> 
> Signed-off-by: anish kumar <yesanishhere@gmail.com>
> ---

This does make the code look quite a bit nicer, I think there is
one small issue below.

<snip>

> +int snd_soc_dapm_new_pcm(struct snd_soc_card *card,
> +			 const struct snd_soc_pcm_stream *params,
> +			 unsigned int num_params,
> +			 struct snd_soc_dapm_widget *source,
> +			 struct snd_soc_dapm_widget *sink)
> +{
> +	struct snd_soc_dapm_widget template;
> +	struct snd_soc_dapm_widget *w;
> +	char *link_name;
> +	int ret;
> +
> +	link_name = devm_kasprintf(card->dev, GFP_KERNEL, "%s-%s",
> +				   source->name, sink->name);
> +	if (!link_name)
> +		return -ENOMEM;
>  
> +	memset(&template, 0, sizeof(template));
> +	template.reg = SND_SOC_NOPM;
> +	template.id = snd_soc_dapm_dai_link;
> +	template.name = link_name;
> +	template.event = snd_soc_dai_link_event;
> +	template.event_flags = SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
> +		SND_SOC_DAPM_PRE_PMD;
> +	template.kcontrol_news = NULL;
> +
> +	/* allocate memory for control, only in case of multiple configs */
> +	if (num_params > 1) {
> +		template.num_kcontrols = 1;
> +		template.kcontrol_news =
> +					snd_soc_dapm_alloc_kcontrol(card,
> +						link_name, params, num_params);
> +		if (!template.kcontrol_news) {
> +			ret = -ENOMEM;
> +			goto outfree_link_name;
> +		}
> +	}
>  	dev_dbg(card->dev, "ASoC: adding %s widget\n", link_name);
>  
>  	w = snd_soc_dapm_new_control_unlocked(&card->dapm, &template);

If we fail this call or the call to snd_soc_dapm_add_path that
follows it we don't clean up all the stuff we allocated in
snd_soc_dapm_alloc_kcontrol. We probably need to add a de-alloc
function for the error paths as well.

Thanks,
Charles

  reply	other threads:[~2017-09-20 11:05 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-09-20  8:28 [Resend] [PATCH 0/4] ASoC: dapm: Avoid creating kcontrol for params yesanishhere
2017-09-20  8:28 ` [Resend] [PATCH 1/4] ASoC: dapm: fix error path in snd_soc_dapm_new_pcm yesanishhere
2017-09-20 11:02   ` Charles Keepax
2017-09-20 11:42   ` Applied "ASoC: dapm: fix error path in snd_soc_dapm_new_pcm" to the asoc tree Mark Brown
2017-09-20  8:28 ` [Resend] [PATCH 2/4] ASoC: dapm: Refactor the code in snd_soc_dapm_new_pcm yesanishhere
2017-09-20 11:02   ` Charles Keepax
2017-09-20  8:28 ` [Resend] [PATCH 3/4] ASoC: dapm: Avoid creating kcontrol for params yesanishhere
2017-09-20 11:05   ` Charles Keepax [this message]
2017-09-20  8:28 ` [Resend] [PATCH 4/4] ASoC: dapm: Remove the redundant check yesanishhere

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=20170920110534.exix6dqf4la2nday@localhost.localdomain \
    --to=ckeepax@opensource.cirrus.com \
    --cc=alsa-devel@alsa-project.org \
    --cc=broonie@kernel.org \
    --cc=lgirdwood@gmail.com \
    --cc=tiwai@suse.com \
    --cc=yesanishhere@gmail.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.