aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJavi Merino <javi.merino@arm.com>2012-06-13 10:07:00 -0400
committerVinod Koul <vinod.koul@linux.intel.com>2012-06-13 23:09:52 -0400
commitfdec53d5203ee3d44be7c09d1524e3a6287d46a7 (patch)
tree75a88e99e26cce699c00ce95fb323dfc0e0ada1f
parent5a67ac572e102f7d877b8a3a18a59315186e3e99 (diff)
DMA: PL330: Fix racy mutex unlock
pl330_update() stores a pointer to the thrd->req that finished, which contains a pointer to the corresponding pl330_req. This is done with the pl330_lock held. Then, it iterates through the req_done list, calling the callback for each of the requests that are done. The problem is that the driver releases the lock before calling the callback for each of the callbacks. pl330_submit_req() running in another processor can then acquire the lock and insert another request in one of the thrd->req that hasn't been processed yet, replacing the pointer to pl330_req there. When the callback returns in pl330_update() and the next rqdone is popped from the list, it dereferences the pl330_req pointer to the just scheduled pl330_req, instead of the one that has finished, calling pl330 with the wrong r. This patch fixes this by storing the pointer to pl330_req directly in the list. Signed-off-by: Javi Merino <javi.merino@arm.com> Cc: Jassi Brar <jaswinder.singh@linaro.org> Acked-by: Jassi Brar <jaswinder.singh@linaro.org> Signed-off-by: Vinod Koul <vinod.koul@linux.intel.com>
-rw-r--r--drivers/dma/pl330.c26
1 files changed, 10 insertions, 16 deletions
diff --git a/drivers/dma/pl330.c b/drivers/dma/pl330.c
index 3ce7d553a746..e4feba6b03c0 100644
--- a/drivers/dma/pl330.c
+++ b/drivers/dma/pl330.c
@@ -392,6 +392,8 @@ struct pl330_req {
392 struct pl330_reqcfg *cfg; 392 struct pl330_reqcfg *cfg;
393 /* Pointer to first xfer in the request. */ 393 /* Pointer to first xfer in the request. */
394 struct pl330_xfer *x; 394 struct pl330_xfer *x;
395 /* Hook to attach to DMAC's list of reqs with due callback */
396 struct list_head rqd;
395}; 397};
396 398
397/* 399/*
@@ -461,8 +463,6 @@ struct _pl330_req {
461 /* Number of bytes taken to setup MC for the req */ 463 /* Number of bytes taken to setup MC for the req */
462 u32 mc_len; 464 u32 mc_len;
463 struct pl330_req *r; 465 struct pl330_req *r;
464 /* Hook to attach to DMAC's list of reqs with due callback */
465 struct list_head rqd;
466}; 466};
467 467
468/* ToBeDone for tasklet */ 468/* ToBeDone for tasklet */
@@ -1683,7 +1683,7 @@ static void pl330_dotask(unsigned long data)
1683/* Returns 1 if state was updated, 0 otherwise */ 1683/* Returns 1 if state was updated, 0 otherwise */
1684static int pl330_update(const struct pl330_info *pi) 1684static int pl330_update(const struct pl330_info *pi)
1685{ 1685{
1686 struct _pl330_req *rqdone; 1686 struct pl330_req *rqdone, *tmp;
1687 struct pl330_dmac *pl330; 1687 struct pl330_dmac *pl330;
1688 unsigned long flags; 1688 unsigned long flags;
1689 void __iomem *regs; 1689 void __iomem *regs;
@@ -1750,7 +1750,10 @@ static int pl330_update(const struct pl330_info *pi)
1750 if (active == -1) /* Aborted */ 1750 if (active == -1) /* Aborted */
1751 continue; 1751 continue;
1752 1752
1753 rqdone = &thrd->req[active]; 1753 /* Detach the req */
1754 rqdone = thrd->req[active].r;
1755 thrd->req[active].r = NULL;
1756
1754 mark_free(thrd, active); 1757 mark_free(thrd, active);
1755 1758
1756 /* Get going again ASAP */ 1759 /* Get going again ASAP */
@@ -1762,20 +1765,11 @@ static int pl330_update(const struct pl330_info *pi)
1762 } 1765 }
1763 1766
1764 /* Now that we are in no hurry, do the callbacks */ 1767 /* Now that we are in no hurry, do the callbacks */
1765 while (!list_empty(&pl330->req_done)) { 1768 list_for_each_entry_safe(rqdone, tmp, &pl330->req_done, rqd) {
1766 struct pl330_req *r; 1769 list_del(&rqdone->rqd);
1767
1768 rqdone = container_of(pl330->req_done.next,
1769 struct _pl330_req, rqd);
1770
1771 list_del_init(&rqdone->rqd);
1772
1773 /* Detach the req */
1774 r = rqdone->r;
1775 rqdone->r = NULL;
1776 1770
1777 spin_unlock_irqrestore(&pl330->lock, flags); 1771 spin_unlock_irqrestore(&pl330->lock, flags);
1778 _callback(r, PL330_ERR_NONE); 1772 _callback(rqdone, PL330_ERR_NONE);
1779 spin_lock_irqsave(&pl330->lock, flags); 1773 spin_lock_irqsave(&pl330->lock, flags);
1780 } 1774 }
1781 1775