All of lore.kernel.org
 help / color / mirror / Atom feed
* dma: mic_x100_dma: use devm_kzalloc to allocate mic_dma_dev
@ 2018-08-04  2:15 Huang Shijie
  0 siblings, 0 replies; 2+ messages in thread
From: Huang Shijie @ 2018-08-04  2:15 UTC (permalink / raw)
  To: vkoul; +Cc: dmaengine, sudeep.dutt, ashutosh.dixit, Huang Shijie

The following patch introduced an issue.
       dmaengine: mic_x100_dma: use the new helper to simplify the code

This issue is :

	kfree(mic_dma_dev)
	.....
	dma_async_device_unregister(mic_dma_dev->device);

Free the memory, and use it again.

So use devm_kzalloc to allocate mic_dma_dev.
When the Devres try to release the resources, it will call release at the
following order:

	dma_async_device_unregister(mic_dma_dev->device);
	.....
	kfree(mic_dma_dev)

Signed-off-by: Huang Shijie <sjhuang@iluvatar.ai>
---
 drivers/dma/mic_x100_dma.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/drivers/dma/mic_x100_dma.c b/drivers/dma/mic_x100_dma.c
index b76cb17d879c..adfd316db1a8 100644
--- a/drivers/dma/mic_x100_dma.c
+++ b/drivers/dma/mic_x100_dma.c
@@ -639,7 +639,7 @@ static struct mic_dma_device *mic_dma_dev_reg(struct mbus_device *mbdev,
 	int ret;
 	struct device *dev = &mbdev->dev;
 
-	mic_dma_dev = kzalloc(sizeof(*mic_dma_dev), GFP_KERNEL);
+	mic_dma_dev = devm_kzalloc(dev, sizeof(*mic_dma_dev), GFP_KERNEL);
 	if (!mic_dma_dev) {
 		ret = -ENOMEM;
 		goto alloc_error;
@@ -664,7 +664,6 @@ static struct mic_dma_device *mic_dma_dev_reg(struct mbus_device *mbdev,
 reg_error:
 	mic_dma_uninit(mic_dma_dev);
 init_error:
-	kfree(mic_dma_dev);
 	mic_dma_dev = NULL;
 alloc_error:
 	dev_err(dev, "Error at %s %d ret=%d\n", __func__, __LINE__, ret);
@@ -674,7 +673,6 @@ static struct mic_dma_device *mic_dma_dev_reg(struct mbus_device *mbdev,
 static void mic_dma_dev_unreg(struct mic_dma_device *mic_dma_dev)
 {
 	mic_dma_uninit(mic_dma_dev);
-	kfree(mic_dma_dev);
 }
 
 /* DEBUGFS CODE */

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

* dma: mic_x100_dma: use devm_kzalloc to allocate mic_dma_dev
@ 2018-08-21 11:34 Vinod Koul
  0 siblings, 0 replies; 2+ messages in thread
From: Vinod Koul @ 2018-08-21 11:34 UTC (permalink / raw)
  To: Huang Shijie; +Cc: dmaengine, sudeep.dutt, ashutosh.dixit

On 04-08-18, 10:15, Huang Shijie wrote:
> The following patch introduced an issue.
>        dmaengine: mic_x100_dma: use the new helper to simplify the code

please use cannaonical form for describing patches i.e., commit abcdef:
("....") introduced ...

> 
> This issue is :
> 
> 	kfree(mic_dma_dev)
> 	.....
> 	dma_async_device_unregister(mic_dma_dev->device);
> 
> Free the memory, and use it again.
> 
> So use devm_kzalloc to allocate mic_dma_dev.
> When the Devres try to release the resources, it will call release at the
> following order:
> 
> 	dma_async_device_unregister(mic_dma_dev->device);
> 	.....
> 	kfree(mic_dma_dev)
> 

We should add:
Fixes: ...

And update the title to mention that this is a fix

> Signed-off-by: Huang Shijie <sjhuang@iluvatar.ai>
> ---
>  drivers/dma/mic_x100_dma.c | 4 +---
>  1 file changed, 1 insertion(+), 3 deletions(-)
> 
> diff --git a/drivers/dma/mic_x100_dma.c b/drivers/dma/mic_x100_dma.c
> index b76cb17d879c..adfd316db1a8 100644
> --- a/drivers/dma/mic_x100_dma.c
> +++ b/drivers/dma/mic_x100_dma.c
> @@ -639,7 +639,7 @@ static struct mic_dma_device *mic_dma_dev_reg(struct mbus_device *mbdev,
>  	int ret;
>  	struct device *dev = &mbdev->dev;
>  
> -	mic_dma_dev = kzalloc(sizeof(*mic_dma_dev), GFP_KERNEL);
> +	mic_dma_dev = devm_kzalloc(dev, sizeof(*mic_dma_dev), GFP_KERNEL);
>  	if (!mic_dma_dev) {
>  		ret = -ENOMEM;
>  		goto alloc_error;
> @@ -664,7 +664,6 @@ static struct mic_dma_device *mic_dma_dev_reg(struct mbus_device *mbdev,
>  reg_error:
>  	mic_dma_uninit(mic_dma_dev);
>  init_error:
> -	kfree(mic_dma_dev);
>  	mic_dma_dev = NULL;
>  alloc_error:
>  	dev_err(dev, "Error at %s %d ret=%d\n", __func__, __LINE__, ret);
> @@ -674,7 +673,6 @@ static struct mic_dma_device *mic_dma_dev_reg(struct mbus_device *mbdev,
>  static void mic_dma_dev_unreg(struct mic_dma_device *mic_dma_dev)
>  {
>  	mic_dma_uninit(mic_dma_dev);
> -	kfree(mic_dma_dev);
>  }
>  
>  /* DEBUGFS CODE */
> -- 
> 2.17.1

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

end of thread, other threads:[~2018-08-21 11:34 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-08-04  2:15 dma: mic_x100_dma: use devm_kzalloc to allocate mic_dma_dev Huang Shijie
2018-08-21 11:34 Vinod Koul

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.