diff mbox

dmaengine: fix potential race condition in fsl raid

Message ID 1405322428-20461-1-git-send-email-xuelin.shi@freescale.com (mailing list archive)
State Not Applicable
Delegated to: Dan Williams
Headers show

Commit Message

Xuelin Shi July 14, 2014, 7:20 a.m. UTC
From: Xuelin Shi <xuelin.shi@freescale.com>

checking available slots in HW should be under the lock.

Signed-off-by: Xuelin Shi <b29237@freescale.com>
---
 drivers/dma/fsl_raid.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
diff mbox

Patch

diff --git a/drivers/dma/fsl_raid.c b/drivers/dma/fsl_raid.c
index 935d05a..fccad86 100644
--- a/drivers/dma/fsl_raid.c
+++ b/drivers/dma/fsl_raid.c
@@ -112,11 +112,11 @@  static void re_jr_issue_pending(struct dma_chan *chan)
 
 	jr = container_of(chan, struct re_jr, chan);
 
+	spin_lock_irqsave(&jr->desc_lock, flags);
 	avail = RE_JR_INB_SLOT_AVAIL(in_be32(&jr->jrregs->inbring_slot_avail));
 	if (!avail)
-		return;
+		goto out;
 
-	spin_lock_irqsave(&jr->desc_lock, flags);
 	list_for_each_entry_safe(desc, _desc, &jr->submit_q, node) {
 		if (!avail)
 			break;
@@ -132,6 +132,7 @@  static void re_jr_issue_pending(struct dma_chan *chan)
 		out_be32(&jr->jrregs->inbring_add_job, RE_JR_INB_JOB_ADD(1));
 		avail--;
 	}
+out:
 	spin_unlock_irqrestore(&jr->desc_lock, flags);
 }