From: Lars-Peter Clausen <lars@metafoo.de>
To: Xiubo Li <Li.Xiubo@freescale.com>
Cc: alsa-devel@alsa-project.org, tiwai@suse.de,
linux-kernel@vger.kernel.org, lgirdwood@gmail.com,
broonie@kernel.org
Subject: Re: [PATCH] ASoC: core: Use devm_kzalloc() instead kzalloc()
Date: Thu, 16 Jan 2014 22:52:35 +0100 [thread overview]
Message-ID: <52D854A3.5090109@metafoo.de> (raw)
In-Reply-To: <1389861887-32721-1-git-send-email-Li.Xiubo@freescale.com>
On 01/16/2014 09:44 AM, Xiubo Li wrote:
> Makes the code slightly shorter
>
> Signed-off-by: Xiubo Li <Li.Xiubo@freescale.com>
I don't like this. I don't think it is a good design pattern to call devm
function from within (especial non-devm) library functions. It creates an
asymmetric API. The memory is allocated when snd_dmaengine_pcm_register() is
called, but it is not freed when snd_dmaengine_pcm_unregister() is called.
This goes against the principle of least surprise.
- Lars
> ---
> sound/soc/soc-generic-dmaengine-pcm.c | 4 +---
> 1 file changed, 1 insertion(+), 3 deletions(-)
>
> diff --git a/sound/soc/soc-generic-dmaengine-pcm.c b/sound/soc/soc-generic-dmaengine-pcm.c
> index 5bace12..bfb012f 100644
> --- a/sound/soc/soc-generic-dmaengine-pcm.c
> +++ b/sound/soc/soc-generic-dmaengine-pcm.c
> @@ -388,7 +388,7 @@ int snd_dmaengine_pcm_register(struct device *dev,
> struct dmaengine_pcm *pcm;
> int ret;
>
> - pcm = kzalloc(sizeof(*pcm), GFP_KERNEL);
> + pcm = devm_kzalloc(dev, sizeof(*pcm), GFP_KERNEL);
> if (!pcm)
> return -ENOMEM;
>
> @@ -408,7 +408,6 @@ int snd_dmaengine_pcm_register(struct device *dev,
>
> err_free_dma:
> dmaengine_pcm_release_chan(pcm);
> - kfree(pcm);
> return ret;
> }
> EXPORT_SYMBOL_GPL(snd_dmaengine_pcm_register);
> @@ -433,7 +432,6 @@ void snd_dmaengine_pcm_unregister(struct device *dev)
>
> snd_soc_remove_platform(platform);
> dmaengine_pcm_release_chan(pcm);
> - kfree(pcm);
> }
> EXPORT_SYMBOL_GPL(snd_dmaengine_pcm_unregister);
>
>
next prev parent reply other threads:[~2014-01-16 21:50 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-01-16 8:44 [PATCH] ASoC: core: Use devm_kzalloc() instead kzalloc() Xiubo Li
2014-01-16 21:52 ` Lars-Peter Clausen [this message]
2014-01-17 18:48 ` [alsa-devel] " Mark Brown
2014-01-20 3:18 ` Li.Xiubo
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=52D854A3.5090109@metafoo.de \
--to=lars@metafoo.de \
--cc=Li.Xiubo@freescale.com \
--cc=alsa-devel@alsa-project.org \
--cc=broonie@kernel.org \
--cc=lgirdwood@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=tiwai@suse.de \
/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