Skip to contentSkip to conversation

dma: mmp_pdma: fix a memory alloc error

PATCH In review Xiang Wang 2 participants 7 messages Jun 18, 2013 – Aug 19, 2013 dmaengine

lore
Share & tools
lore

Xiang Wang

author
#0 lore raw

PATCH v2 1/1 dma: mmp_pdma: fix a memory alloc error

From: Xiang Wang <[email protected]>

pdev->phy is of type "struct mmp_pdma_phy *". But when allocating memory for it, "struct mmp_pdma_chan" is used by mistake.

---
 drivers/dma/mmp_pdma.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
drivers/dma/mmp_pdma.c +1 -1
index c26699f..18ac57f 100644
@@ -801,7 +801,7 @@ static int mmp_pdma_probe(struct platform_device *op)
 	}
 
 	pdev->phy = devm_kzalloc(pdev->dev,
-		dma_channels * sizeof(struct mmp_pdma_chan), GFP_KERNEL);
+		dma_channels * sizeof(*pdev->phy), GFP_KERNEL);
 	if (pdev->phy == NULL)
 		return -ENOMEM;
 
Signature · 1 line
1.7.5.4
author
#1 lore raw

Hi,
Do you have any comments about this patch? Have modified according to Vinod's advice. Thanks!

2013/6/18 Xiang Wang <[email protected]>:

Quoted 27 lines

From: Xiang Wang <[email protected]>

pdev->phy is of type "struct mmp_pdma_phy *". But when allocating memory for it, "struct mmp_pdma_chan" is used by mistake.

---
 drivers/dma/mmp_pdma.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
drivers/dma/mmp_pdma.c +1 -2
index c26699f..18ac57f 100644
@@ -801,7 +801,7 @@ static int mmp_pdma_probe(struct platform_device *op)
        }
 
        pdev->phy = devm_kzalloc(pdev->dev,
-               dma_channels * sizeof(struct mmp_pdma_chan), GFP_KERNEL);
+               dma_channels * sizeof(*pdev->phy), GFP_KERNEL);
        if (pdev->phy == NULL)
                return -ENOMEM;
 
--

1.7.5.4

Signature · 2 lines
Regards,
Xiang
#2 lore raw
In reply to Xiang Wang
Quoted 16 lines · Xiang Wang

From: Xiang Wang <[email protected]>

pdev->phy is of type "struct mmp_pdma_phy *". But when allocating memory for it, "struct mmp_pdma_chan" is used by mistake.

---
 drivers/dma/mmp_pdma.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
drivers/dma/mmp_pdma.c +0 -0
index c26699f..18ac57f 100644

drivers/dma/mmp_pdma.c static int mmp_pdma_probe(struct platform_device *op) · line 804

Quoted 5 lines
drivers/dma/mmp_pdma.c +1 -1
@@ -801,7 +801,7 @@ static int mmp_pdma_probe(struct platform_device *op)
 	}
 
 	pdev->phy = devm_kzalloc(pdev->dev,
-		dma_channels * sizeof(struct mmp_pdma_chan), GFP_KERNEL);
+		dma_channels * sizeof(*pdev->phy), GFP_KERNEL);

While at it, can you make the flag GFP_NOWAIT. that is the recommendation for dmac drivers

--
~Vinod

author
#3 lore raw

2013/7/5 Vinod Koul <[email protected]>:

Quoted 19 lines · Xiang Wang
Quoted 18 lines

From: Xiang Wang <[email protected]>

pdev->phy is of type "struct mmp_pdma_phy *". But when allocating memory for it, "struct mmp_pdma_chan" is used by mistake.

---
 drivers/dma/mmp_pdma.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
drivers/dma/mmp_pdma.c +0 -0
index c26699f..18ac57f 100644
@@ -801,7 +801,7 @@ static int mmp_pdma_probe(struct platform_device *op)
      }
 
Quoted 8 lines

drivers/dma/mmp_pdma.c static int mmp_pdma_probe(struct platform_device *op) · line 804

Quoted 3 lines
drivers/dma/mmp_pdma.c +1 -1
      pdev->phy = devm_kzalloc(pdev->dev,
-             dma_channels * sizeof(struct mmp_pdma_chan), GFP_KERNEL);
+             dma_channels * sizeof(*pdev->phy), GFP_KERNEL);

While at it, can you make the flag GFP_NOWAIT. that is the recommendation for dmac drivers

--
~Vinod

Hi, Vinod
Would you please explain a little more about why we should use GFP_NOWAIT here? This memory is not dedicated for DMA controller. Do we have special reasons to use GFP_NOWAIT? Thanks!

Signature · 2 lines
Regards,
Xiang
#4 lore raw

On Thu, Jul 25, 2013 at 10:22:50AM +0800, Xiang Wang wrote:

Btw its generally a good idea to remove the parts not required for further discussion

Quoted 3 lines

Would you please explain a little more about why we should use GFP_NOWAIT here? This memory is not dedicated for DMA controller. Do we have special reasons to use GFP_NOWAIT? Thanks!

There are few reasons
- the dma requests can be triggered from atomic context
- so for above you can argue to use the GFP_ATOMIC and the guideline for dma drivers [1] was discussed briefly

~Vinod
[1]: http://lkml.indiana.edu/hypermail/linux/kernel/0911.1/02316.html

author
#5 lore raw

2013/7/29 Vinod Koul <[email protected]>:

Quoted 13 lines · Xiang Wang

Btw its generally a good idea to remove the parts not required for further discussion

Quoted 3 lines

Would you please explain a little more about why we should use GFP_NOWAIT here? This memory is not dedicated for DMA controller. Do we have special reasons to use GFP_NOWAIT? Thanks!

There are few reasons
- the dma requests can be triggered from atomic context
- so for above you can argue to use the GFP_ATOMIC and the guideline for dma drivers [1] was discussed briefly

Quoted 4 lines

~Vinod
[1]: http://lkml.indiana.edu/hypermail/linux/kernel/0911.1/02316.html

--

Hi, Vinod
Thanks for your explanation. But want to double confirm with you that the memory alloc in my patch is in probe function, still need to use GFP_NOWAIT? Thanks!

Signature · 2 lines
Regards,
Xiang
#6 lore raw
Quoted 14 lines · Xiang Wang

2013/7/29 Vinod Koul <[email protected]>:

Quoted 13 lines · Xiang Wang

Btw its generally a good idea to remove the parts not required for further discussion

Quoted 3 lines

Would you please explain a little more about why we should use GFP_NOWAIT here? This memory is not dedicated for DMA controller. Do we have special reasons to use GFP_NOWAIT? Thanks!

There are few reasons
- the dma requests can be triggered from atomic context
- so for above you can argue to use the GFP_ATOMIC and the guideline for dma drivers [1] was discussed briefly

Quoted 8 lines
Quoted 4 lines

~Vinod
[1]: http://lkml.indiana.edu/hypermail/linux/kernel/0911.1/02316.html

--

Hi, Vinod
Thanks for your explanation. But want to double confirm with you that the memory alloc in my patch is in probe function, still need to use GFP_NOWAIT? Thanks!

Yes I would recommend it

~Vinod