Skip to contentSkip to conversation

dma: mmp_pdma: fix a memory alloc error

PATCH Superseded Xiang Wang 3 participants 6 messages May 28, 2013 – Jun 18, 2013 dmaengine

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Xiang Wang

author
#0 lore raw

PATCH 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..76a8dcf 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(struct mmp_pdma_phy), GFP_KERNEL);
 	if (pdev->phy == NULL)
 		return -ENOMEM;
 
Signature · 1 line
1.7.5.4
#1 lore raw
Quoted 5 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.

Have you tested it?

Quoted 10 lines
---
 drivers/dma/mmp_pdma.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
drivers/dma/mmp_pdma.c +0 -0
index c26699f..76a8dcf 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(struct mmp_pdma_phy), GFP_KERNEL);

For me it seems you did get how it works.

--
With Best Regards,
Andy Shevchenko

author
#2 lore raw

2013/5/28 Andy Shevchenko <[email protected]>:

Quoted 27 lines · Xiang Wang
Quoted 5 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.

Have you tested it?

Quoted 10 lines
---
 drivers/dma/mmp_pdma.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
drivers/dma/mmp_pdma.c +0 -0
index c26699f..76a8dcf 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(struct mmp_pdma_phy), GFP_KERNEL);

For me it seems you did get how it works.

Quoted 3 lines

--
With Best Regards,
Andy Shevchenko

Hi, Andy
Yes. I've tested on marvell pxa988 platform using dmatest.ko.

author
#3 lore raw

2013/5/31 Xiang Wang <[email protected]>:

Quoted 28 lines

2013/5/28 Andy Shevchenko <[email protected]>:

Quoted 27 lines · Xiang Wang
Quoted 5 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.

Have you tested it?

Quoted 10 lines
---
 drivers/dma/mmp_pdma.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
drivers/dma/mmp_pdma.c +0 -0
index c26699f..76a8dcf 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(struct mmp_pdma_phy), GFP_KERNEL);

For me it seems you did get how it works.

Quoted 6 lines
Quoted 3 lines

--
With Best Regards,
Andy Shevchenko

Hi, Andy
Yes. I've tested on marvell pxa988 platform using dmatest.ko.

Hi, All
Do you have any comments about this patch? Thanks!

--
Regards,
Xiang

#4 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..76a8dcf 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(struct mmp_pdma_phy), GFP_KERNEL);

why not sizeof(*pdev-phy), that way you dont make above error

--
~Vinod

author
#5 lore raw

2013/6/17 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..76a8dcf 100644
@@ -801,7 +801,7 @@ static int mmp_pdma_probe(struct platform_device *op)
      }
 
Quoted 7 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(struct mmp_pdma_phy), GFP_KERNEL);

why not sizeof(*pdev-phy), that way you dont make above error

--
~Vinod

Hi,
Updated patch V2 to use sizeof(*pdev->phy). Thanks!

--
Regards,
Xiang