Skip to contentSkip to conversation

dma: various fixes in different DMAC drivers

PATCH Superseded Andy Shevchenko 5 participants 15 messages Feb 12, 2013 – Feb 15, 2013

Subsystems (4)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#4 lore raw

PATCH 3/6 dma: coh901318_lli: avoid unbalanced locking

In reply to Andy Shevchenko

I have not checked the code but there is a possibility that custom pool->lock is not needed at all due to dma_pool contains it's own lock.

Cc Linus Walleij <[email protected]>
Cc linux-arm-kernel at lists.infradead.org
---
 drivers/dma/coh901318_lli.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/dma/coh901318_lli.c +1 -1
index 3e96610..702112d 100644
@@ -61,7 +61,7 @@ coh901318_lli_alloc(struct coh901318_pool *pool, unsigned int len)
 	dma_addr_t phy;
 
 	if (len == 0)
-		goto err;
+		return NULL;
 
 	spin_lock(&pool->lock);
 
Signature · 1 line
1.7.10.4
#9 lore raw

PATCH 4/6 dma: coh901318_lli: set residue only if dma is in progress

In reply to Andy Shevchenko

When status is DMA_SUCCESS the residue should be zero. Otherwise it's a bug.

Cc Linus Walleij <[email protected]>
Cc linux-arm-kernel at lists.infradead.org
---
 drivers/dma/coh901318.c |    4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/dma/coh901318.c +3 -1
index a2f079a..797940e 100644
@@ -2355,7 +2355,9 @@ coh901318_tx_status(struct dma_chan *chan, dma_cookie_t cookie,
 	enum dma_status ret;
 
 	ret = dma_cookie_status(chan, cookie, txstate);
-	/* FIXME: should be conditional on ret != DMA_SUCCESS? */
+	if (ret == DMA_SUCCESS)
+		return ret;
+
 	dma_set_residue(txstate, coh901318_get_bytes_left(chan));
 
 	if (ret == DMA_IN_PROGRESS && cohc->stopped)
Signature · 1 line
1.7.10.4
#11 lore raw

PATCH 5/6 edma: do not waste memory for dma_mask

In reply to Andy Shevchenko

Accordingly to commentary in the platform_device_register_full the memory allocated for dma_mask will not going to be freed. That's why is better to assign dma_mask afterwards.

---
 drivers/dma/edma.c |    6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/dma/edma.c +4 -2
index 06ea4b8..cd7e328 100644
@@ -620,13 +620,11 @@ static struct platform_device *pdev0, *pdev1;
 static const struct platform_device_info edma_dev_info0 = {
 	.name = "edma-dma-engine",
 	.id = 0,
-	.dma_mask = DMA_BIT_MASK(32),
 };
 
 static const struct platform_device_info edma_dev_info1 = {
 	.name = "edma-dma-engine",
 	.id = 1,
-	.dma_mask = DMA_BIT_MASK(32),
 };
 
 static int edma_init(void)
@@ -640,6 +638,8 @@ static int edma_init(void)
 			ret = PTR_ERR(pdev0);
 			goto out;
 		}
+		pdev0->dev.dma_mask = &pdev0->dev.coherent_dma_mask;
+		pdev0->dev.coherent_dma_mask = DMA_BIT_MASK(32);
 	}
 
 	if (EDMA_CTLRS == 2) {
@@ -649,6 +649,8 @@ static int edma_init(void)
 			platform_device_unregister(pdev0);
 			ret = PTR_ERR(pdev1);
 		}
+		pdev1->dev.dma_mask = &pdev1->dev.coherent_dma_mask;
+		pdev1->dev.coherent_dma_mask = DMA_BIT_MASK(32);
 	}
 
 out:
Signature · 1 line
1.7.10.4
#1 lore raw

PATCH 1/6 of: dma: protect list write operation by spin_lock

In reply to Andy Shevchenko

It's possible to have an inconsistency in the list due to unprotected operation on it. The patch adds a proper locking on the list operation.

---
 drivers/of/dma.c |    2 ++
 1 file changed, 2 insertions(+)
drivers/of/dma.c +2 -0
index 59631b2..1ae6120 100644
@@ -117,7 +117,9 @@ int of_dma_controller_register(struct device_node *np,
 	ofdma->use_count = 0;
 
 	/* Now queue of_dma controller structure in list */
+	spin_lock(&of_dma_lock);
 	list_add_tail(&ofdma->of_dma_controllers, &of_dma_list);
+	spin_unlock(&of_dma_lock);
 
 	return 0;
 }
Signature · 1 line
1.7.10.4
#2 lore raw

PATCH 2/6 dmaengine.h: remove redundant else keyword

In reply to Andy Shevchenko

dmaengine_device_control returns -ENOSYS in case the dma driver doesn't have such functionality.

---
 include/linux/dmaengine.h |    3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
include/linux/dmaengine.h +1 -2
index bfcdecb..b760b38 100644
@@ -610,8 +610,7 @@ static inline int dmaengine_device_control(struct dma_chan *chan,
 {
 	if (chan->device->device_control)
 		return chan->device->device_control(chan, cmd, arg);
-	else
-		return -ENOSYS;
+	return -ENOSYS;
 }
 
 static inline int dmaengine_slave_config(struct dma_chan *chan,
Signature · 1 line
1.7.10.4
#12 lore raw

PATCH 6/6 dma: tegra20-apb-dma: remove unnecessary assignment

In reply to Andy Shevchenko

There is no need to assign 0 to residue, because dma_cookie_status() does this for us.

---
 drivers/dma/tegra20-apb-dma.c |    1 -
 1 file changed, 1 deletion(-)
drivers/dma/tegra20-apb-dma.c +0 -1
index 46e4630..fcee27e 100644
@@ -769,7 +769,6 @@ static enum dma_status tegra_dma_tx_status(struct dma_chan *dc,
 
 	ret = dma_cookie_status(dc, cookie, txstate);
 	if (ret == DMA_SUCCESS) {
-		dma_set_residue(txstate, 0);
 		spin_unlock_irqrestore(&tdc->lock, flags);
 		return ret;
 	}
Signature · 1 line
1.7.10.4
#0 lore raw

cover dma: various fixes in different DMAC drivers

This is a patcset of independent fixes of the DMAC drivers. They are simple and being understandable in their context.

Andy Shevchenko (6):
of: dma: protect list write operation by spin_lock dmaengine.h: remove redundant else keyword
dma: coh901318_lli: avoid unbalanced locking
dma: coh901318_lli: set residue only if dma is in progress
edma: do not waste memory for dma_mask
dma: tegra20-apb-dma: remove unnecessary assignment

 drivers/dma/coh901318.c       |    4 +++-
 drivers/dma/coh901318_lli.c   |    2 +-
 drivers/dma/edma.c            |    6 ++++--
 drivers/dma/tegra20-apb-dma.c |    1 -
 drivers/of/dma.c              |    2 ++
 include/linux/dmaengine.h     |    3 +--
 6 files changed, 11 insertions(+), 7 deletions(-)
Signature · 1 line
1.7.10.4
#3 lore raw

Re: [PATCH 2/6] dmaengine.h: remove redundant else keyword

In reply to Andy Shevchenko
Quoted 13 lines · Andy Shevchenko

dmaengine_device_control returns -ENOSYS in case the dma driver doesn't have such functionality.

---
 include/linux/dmaengine.h |    3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
include/linux/dmaengine.h +0 -0
index bfcdecb..b760b38 100644

include/linux/dmaengine.h static inline int dmaengine_device_control(struct dma_chan *chan, · line 613

Quoted 6 lines
include/linux/dmaengine.h +1 -2
@@ -610,8 +610,7 @@ static inline int dmaengine_device_control(struct dma_chan *chan,
 {
        if (chan->device->device_control)
                return chan->device->device_control(chan, cmd, arg);
-       else
-               return -ENOSYS;
+       return -ENOSYS;

I don't know really which one to prefer here :)

Anyway, if you want this one, then get a blank line before your return code.

#5 lore raw

Re: [PATCH 3/6] dma: coh901318_lli: avoid unbalanced locking

In reply to Andy Shevchenko
Quoted 2 lines · Andy Shevchenko

I have not checked the code but there is a possibility that custom pool->lock is not needed at all due to dma_pool contains it's own lock.

Your viewpoint is fine, but we wanted the reason behind this patch here. Please add appropriate stuff in only in logs.

Quoted 23 lines
Cc Linus Walleij <[email protected]>
Cc linux-arm-kernel at lists.infradead.org
---
 drivers/dma/coh901318_lli.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/dma/coh901318_lli.c +1 -2
index 3e96610..702112d 100644
@@ -61,7 +61,7 @@ coh901318_lli_alloc(struct coh901318_pool *pool, unsigned int len)
        dma_addr_t phy;
 
        if (len == 0)
-               goto err;
+               return NULL;
 
        spin_lock(&pool->lock);
 
--

1.7.10.4

#6 lore raw

Re: [PATCH 3/6] dma: coh901318_lli: avoid unbalanced locking

In reply to Andy Shevchenko
Quoted 2 lines · Andy Shevchenko

I have not checked the code but there is a possibility that custom pool->lock is not needed at all due to dma_pool contains it's own lock.

Can you please change the description to something like:

"The coh901318_lli allocator releases a lock on the exit path without taking it first".

Which is what the patch is actually fixing.

After that it's Acked-by: Linus Walleij <[email protected]>

Yours,
Linus Walleij

#7 lore raw

Re: [PATCH 3/6] dma: coh901318_lli: avoid unbalanced locking

In reply to Linus Walleij
Quoted 10 lines · Linus Walleij
Quoted 2 lines · Andy Shevchenko

I have not checked the code but there is a possibility that custom pool->lock is not needed at all due to dma_pool contains it's own lock.

Can you please change the description to something like:

"The coh901318_lli allocator releases a lock on the exit path without taking it first".

In v2 (that by fact already applied) I put following description:

In case the len is 0 we must return without trying to unlock the
lock that was
not locked.

Does it fit your suggestion?

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#8 lore raw

Re: [PATCH 3/6] dma: coh901318_lli: avoid unbalanced locking

Quoted 12 lines · Andy Shevchenko
Quoted 10 lines · Linus Walleij
Quoted 2 lines · Andy Shevchenko

I have not checked the code but there is a possibility that custom pool->lock is not needed at all due to dma_pool contains it's own lock.

Can you please change the description to something like:

"The coh901318_lli allocator releases a lock on the exit path without taking it first".

Quoted 7 lines

In v2 (that by fact already applied) I put following description:

In case the len is 0 we must return without trying to unlock the
lock that was
not locked.

Does it fit your suggestion?

Sure, acked-by.

Thanks,
Linus Walleij