diff mbox

[09/12] tegra20-apb-dma: remove useless use of lock

Message ID 1369656882-25241-10-git-send-email-andriy.shevchenko@linux.intel.com
State Not Applicable, archived
Headers show

Commit Message

Andy Shevchenko May 27, 2013, 12:14 p.m. UTC
Accordingly to dma_cookie_status() description locking is not required.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: Stephen Warren <swarren@wwwdotorg.org>
Cc: linux-tegra@vger.kernel.org
---
 drivers/dma/tegra20-apb-dma.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

Comments

Laxman Dewangan May 29, 2013, 10:56 a.m. UTC | #1
On Monday 27 May 2013 05:44 PM, Andy Shevchenko wrote:
> Accordingly to dma_cookie_status() description locking is not required.
>
I think we need lock here:
 From isr handler, we call dma_cookie_complete() which is in 
spin-locked. This function updates  tx->chan->completed_cookie = tx->cookie;
In tegra_dma_tx_status(), we check for dma_cookie_status() which access 
the chan->completed_cookie; and it decides status based on this

As the access of  chan->completed_cookie  are from different context, we 
need this locking.

But did not get why it is documented as locking is not require if shared 
variable is getting changed/access from different context simultaneously.

--
To unsubscribe from this list: send the line "unsubscribe linux-tegra" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Andy Shevchenko May 29, 2013, 1:42 p.m. UTC | #2
On Wed, May 29, 2013 at 1:56 PM, Laxman Dewangan <ldewangan@nvidia.com> wrote:
> On Monday 27 May 2013 05:44 PM, Andy Shevchenko wrote:
>>
>> Accordingly to dma_cookie_status() description locking is not required.
>>
> I think we need lock here:
> From isr handler, we call dma_cookie_complete() which is in spin-locked.
> This function updates  tx->chan->completed_cookie = tx->cookie;
> In tegra_dma_tx_status(), we check for dma_cookie_status() which access the
> chan->completed_cookie; and it decides status based on this
>
> As the access of  chan->completed_cookie  are from different context, we
> need this locking.

You need to have a consistent data in the cookies. This is guaranteed
by memory barrier if I got it correctly.
diff mbox

Patch

diff --git a/drivers/dma/tegra20-apb-dma.c b/drivers/dma/tegra20-apb-dma.c
index 33f59ec..019ccfa 100644
--- a/drivers/dma/tegra20-apb-dma.c
+++ b/drivers/dma/tegra20-apb-dma.c
@@ -767,13 +767,11 @@  static enum dma_status tegra_dma_tx_status(struct dma_chan *dc,
 	unsigned long flags;
 	unsigned int residual;
 
-	spin_lock_irqsave(&tdc->lock, flags);
-
 	ret = dma_cookie_status(dc, cookie, txstate);
-	if (ret == DMA_SUCCESS) {
-		spin_unlock_irqrestore(&tdc->lock, flags);
+	if (ret == DMA_SUCCESS)
 		return ret;
-	}
+
+	spin_lock_irqsave(&tdc->lock, flags);
 
 	/* Check on wait_ack desc status */
 	list_for_each_entry(dma_desc, &tdc->free_dma_desc, node) {