Skip to content

Commit eb46485

Browse files
Jeffrey HugoLee Jones
authored andcommitted
dmaengine: qcom: bam_dma: Fix resource leak
commit 7667819 upstream. bam_dma_terminate_all() will leak resources if any of the transactions are committed to the hardware (present in the desc fifo), and not complete. Since bam_dma_terminate_all() does not cause the hardware to be updated, the hardware will still operate on any previously committed transactions. This can cause memory corruption if the memory for the transaction has been reassigned, and will cause a sync issue between the BAM and its client(s). Fix this by properly updating the hardware in bam_dma_terminate_all(). Fixes: e7c0fe2 ("dmaengine: add Qualcomm BAM dma driver") Signed-off-by: Jeffrey Hugo <jeffrey.l.hugo@gmail.com> Cc: stable@vger.kernel.org Link: https://lore.kernel.org/r/20191017152606.34120-1-jeffrey.l.hugo@gmail.com Signed-off-by: Vinod Koul <vkoul@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Signed-off-by: Lee Jones <lee.jones@linaro.org> Change-Id: I86ec467696b28aa777f24105a5d28bcb8ea784a8
1 parent 44ec5f4 commit eb46485

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

drivers/dma/qcom_bam_dma.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -552,7 +552,21 @@ static void bam_dma_terminate_all(struct bam_chan *bchan)
552552

553553
/* remove all transactions, including active transaction */
554554
spin_lock_irqsave(&bchan->vc.lock, flag);
555+
/*
556+
* If we have transactions queued, then some might be committed to the
557+
* hardware in the desc fifo. The only way to reset the desc fifo is
558+
* to do a hardware reset (either by pipe or the entire block).
559+
* bam_chan_init_hw() will trigger a pipe reset, and also reinit the
560+
* pipe. If the pipe is left disabled (default state after pipe reset)
561+
* and is accessed by a connected hardware engine, a fatal error in
562+
* the BAM will occur. There is a small window where this could happen
563+
* with bam_chan_init_hw(), but it is assumed that the caller has
564+
* stopped activity on any attached hardware engine. Make sure to do
565+
* this first so that the BAM hardware doesn't cause memory corruption
566+
* by accessing freed resources.
567+
*/
555568
if (bchan->curr_txd) {
569+
bam_chan_init_hw(bchan, bchan->curr_txd->dir);
556570
list_add(&bchan->curr_txd->vd.node, &bchan->vc.desc_issued);
557571
bchan->curr_txd = NULL;
558572
}

0 commit comments

Comments
 (0)