linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] ASoC: core: Use devm_kzalloc() instead kzalloc()
@ 2014-01-16  8:44 Xiubo Li
  2014-01-16 21:52 ` [alsa-devel] " Lars-Peter Clausen
  0 siblings, 1 reply; 4+ messages in thread
From: Xiubo Li @ 2014-01-16  8:44 UTC (permalink / raw)
  To: lars, lgirdwood, broonie, perex, tiwai; +Cc: alsa-devel, linux-kernel, Xiubo Li

Makes the code slightly shorter

Signed-off-by: Xiubo Li <Li.Xiubo@freescale.com>
---
 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);
 
-- 
1.8.4



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [alsa-devel] [PATCH] ASoC: core: Use devm_kzalloc() instead kzalloc()
  2014-01-16  8:44 [PATCH] ASoC: core: Use devm_kzalloc() instead kzalloc() Xiubo Li
@ 2014-01-16 21:52 ` Lars-Peter Clausen
  2014-01-17 18:48   ` Mark Brown
  0 siblings, 1 reply; 4+ messages in thread
From: Lars-Peter Clausen @ 2014-01-16 21:52 UTC (permalink / raw)
  To: Xiubo Li; +Cc: lgirdwood, broonie, perex, tiwai, alsa-devel, linux-kernel

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);
>
>


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [alsa-devel] [PATCH] ASoC: core: Use devm_kzalloc() instead kzalloc()
  2014-01-16 21:52 ` [alsa-devel] " Lars-Peter Clausen
@ 2014-01-17 18:48   ` Mark Brown
  2014-01-20  3:18     ` Li.Xiubo
  0 siblings, 1 reply; 4+ messages in thread
From: Mark Brown @ 2014-01-17 18:48 UTC (permalink / raw)
  To: Lars-Peter Clausen
  Cc: Xiubo Li, lgirdwood, perex, tiwai, alsa-devel, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 678 bytes --]

On Thu, Jan 16, 2014 at 10:52:35PM +0100, Lars-Peter Clausen wrote:
> 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.

Yes, I tend to agree - unless we only support managed registration the
API shouldn't do managed things internally.

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* RE: [alsa-devel] [PATCH] ASoC: core: Use devm_kzalloc() instead kzalloc()
  2014-01-17 18:48   ` Mark Brown
@ 2014-01-20  3:18     ` Li.Xiubo
  0 siblings, 0 replies; 4+ messages in thread
From: Li.Xiubo @ 2014-01-20  3:18 UTC (permalink / raw)
  To: Mark Brown, Lars-Peter Clausen
  Cc: lgirdwood, perex, tiwai, alsa-devel, linux-kernel

Hi Mar, Lars


> > 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.
> 
> Yes, I tend to agree - unless we only support managed registration the
> API shouldn't do managed things internally.

Got it.

Thanks,


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2014-01-20  3:18 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-01-16  8:44 [PATCH] ASoC: core: Use devm_kzalloc() instead kzalloc() Xiubo Li
2014-01-16 21:52 ` [alsa-devel] " Lars-Peter Clausen
2014-01-17 18:48   ` Mark Brown
2014-01-20  3:18     ` Li.Xiubo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).