public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
To: Ravulapati Vishnu vardhan rao  <Vishnuvardhanrao.Ravulapati@amd.com>
Cc: "moderated list:SOUND - SOC LAYER / DYNAMIC AUDIO POWER
	MANAGEM..."  <alsa-devel@alsa-project.org>,
	Maruthi Bayyavarapu <maruthi.bayyavarapu@amd.com>,
	Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>,
	open list <linux-kernel@vger.kernel.org>,
	Takashi Iwai <tiwai@suse.com>, YueHaibing <yuehaibing@huawei.com>,
	Liam Girdwood <lgirdwood@gmail.com>,
	Akshu.Agrawal@amd.com, Sanju R Mehta <sanju.mehta@amd.com>,
	Mark Brown <broonie@kernel.org>,
	djkurtz@google.com, Vijendar Mukunda <Vijendar.Mukunda@amd.com>,
	Alex Deucher <alexander.deucher@amd.com>,
	Colin Ian King <colin.king@canonical.com>
Subject: Re: [alsa-devel] [RESEND PATCH v5 2/6] ASoC: amd: Refactoring of DAI from DMA driver
Date: Wed, 13 Nov 2019 10:22:19 -0600	[thread overview]
Message-ID: <40d1690c-175c-c6ee-ee44-390c30cccc05@linux.intel.com> (raw)
In-Reply-To: <1573629249-13272-3-git-send-email-Vishnuvardhanrao.Ravulapati@amd.com>


> +	val = rv_readl(adata->acp3x_base + mmACP_BTTDM_ITER);
> +	rv_writel((val | 0x2), adata->acp3x_base + mmACP_BTTDM_ITER);
> +	val = rv_readl(adata->acp3x_base + mmACP_BTTDM_IRER);
> +	rv_writel((val | 0x2), adata->acp3x_base + mmACP_BTTDM_IRER);
> +
> +	val = (FRM_LEN | (slots << 15) | (slot_len << 18));

nit-pick: you have extra parentheses that are not needed for (val | 
0x02) and the outer ones on the previous line


> +static int acp3x_i2s_trigger(struct snd_pcm_substream *substream,
> +		int cmd, struct snd_soc_dai *dai)
> +{
> +	int ret = 0;

nit-pick: move last, xmas-style

> +	struct i2s_stream_instance *rtd = substream->runtime->private_data;
> +	u32 val, period_bytes;

> +static int acp3x_dai_probe(struct platform_device *pdev)
> +{
> +	int status;
> +	struct resource *res;
> +	struct i2s_dev_data *adata;
> +
> +	adata = devm_kzalloc(&pdev->dev, sizeof(struct i2s_dev_data),
> +			GFP_KERNEL);
> +	if (!adata)
> +		return -ENOMEM;
> +
> +	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> +	if (!res) {
> +		dev_err(&pdev->dev, "IORESOURCE_MEM FAILED\n");
> +		goto err;
> +	}
> +
> +	adata->acp3x_base = devm_ioremap(&pdev->dev, res->start,
> +			resource_size(res));
> +	if (IS_ERR(adata->acp3x_base))
> +		return PTR_ERR(adata->acp3x_base);
> +
> +	adata->i2s_irq = res->start;
> +	dev_set_drvdata(&pdev->dev, adata);
> +	status = devm_snd_soc_register_component(&pdev->dev,
> +			&acp3x_dai_component,
> +			&acp3x_i2s_dai, 1);
> +	if (status) {
> +		dev_err(&pdev->dev, "Fail to register acp i2s dai\n");
> +		goto dev_err;
> +	}
> +	pm_runtime_set_autosuspend_delay(&pdev->dev, 10000);
> +	pm_runtime_use_autosuspend(&pdev->dev);
> +	pm_runtime_enable(&pdev->dev);
> +	return 0;
> +err:
> +	kfree(adata);
> +	return -ENOMEM;
> +dev_err:
> +	kfree(adata->acp3x_base);
> +	kfree(adata);
> +	kfree(res);
> +	return -ENODEV;

this can be improved a bit by using ret = -ENOMEM/-ENODEV before the 
goto, and organizing the labels and the kfree calls in the reverse order 
of the initialization/allocation steps.


> @@ -666,7 +461,24 @@ static int acp3x_audio_probe(struct platform_device *pdev)
>   	pm_runtime_use_autosuspend(&pdev->dev);
>   	pm_runtime_enable(&pdev->dev);
>   	return 0;
> +
> +err:
> +	kfree(res);
> +	return -ENOMEM;
> +base_err:
> +	kfree(res);
> +	kfree(adata);
> +	return -ENOMEM;
> +io_irq:
> +	kfree(res);
> +	kfree(adata->acp3x_base);
> +	kfree(adata);
> +	return -ENOMEM;
> +
>   dev_err:
> +	kfree(res);
> +	kfree(adata->acp3x_base);
> +	kfree(adata);
>   	status = acp3x_deinit(adata->acp3x_base);
>   	if (status)
>   		dev_err(&pdev->dev, "ACP de-init failed\n");
same here, you should have all the kfrees in the reverse order of the 
kzalloc, and labels pointing straight at the sequence that needs to be 
executed. Duplicating the error flow makes it hard to maintain the code 
and check for memory leaks.

  reply	other threads:[~2019-11-13 17:18 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <1573629249-13272-1-git-send-email-Vishnuvardhanrao.Ravulapati@amd.com>
2019-11-13  7:14 ` [PATCH v5 1/6] ASoC: amd:Create multiple I2S platform device Endpoint Ravulapati Vishnu vardhan rao
2019-11-13 16:11   ` [alsa-devel] " Pierre-Louis Bossart
2019-11-13  7:14 ` [RESEND PATCH v5 2/6] ASoC: amd: Refactoring of DAI from DMA driver Ravulapati Vishnu vardhan rao
2019-11-13 16:22   ` Pierre-Louis Bossart [this message]
2019-11-13 16:36   ` [alsa-devel] " kbuild test robot
2019-11-13  7:14 ` [RESEND PATCH v5 3/6] ASoC: amd: Enabling I2S instance in DMA and DAI Ravulapati Vishnu vardhan rao
2019-11-13 16:29   ` [alsa-devel] " Pierre-Louis Bossart
2019-11-13  7:14 ` [RESEND PATCH v5 4/6] ASoC: amd: add ACP3x TDM mode support Ravulapati Vishnu vardhan rao
2019-11-13  7:14 ` [RESEND PATCH v5 5/6] ASoC: amd: handle ACP3x i2s-sp interrupt Ravulapati Vishnu vardhan rao
2019-11-13 16:31   ` [alsa-devel] " Pierre-Louis Bossart
2019-11-13  7:14 ` [RESEND PATCH v5 6/6] ASoC: amd: Added ACP3x system resume and runtime pm Ravulapati Vishnu vardhan rao
2019-11-13 16:39   ` [alsa-devel] " Pierre-Louis Bossart
2019-11-13 17:13   ` kbuild test robot

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=40d1690c-175c-c6ee-ee44-390c30cccc05@linux.intel.com \
    --to=pierre-louis.bossart@linux.intel.com \
    --cc=Akshu.Agrawal@amd.com \
    --cc=Vijendar.Mukunda@amd.com \
    --cc=Vishnuvardhanrao.Ravulapati@amd.com \
    --cc=alexander.deucher@amd.com \
    --cc=alsa-devel@alsa-project.org \
    --cc=broonie@kernel.org \
    --cc=colin.king@canonical.com \
    --cc=djkurtz@google.com \
    --cc=kuninori.morimoto.gx@renesas.com \
    --cc=lgirdwood@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=maruthi.bayyavarapu@amd.com \
    --cc=sanju.mehta@amd.com \
    --cc=tiwai@suse.com \
    --cc=yuehaibing@huawei.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox