Skip to content

Commit e486df3

Browse files
bjdooks-ctvinodkoul
authored andcommitted
dmaengine: tegra: avoid overflow of byte tracking
The dma_desc->bytes_transferred counter tracks the number of bytes moved by the DMA channel. This is then used to calculate the information passed back in the in the tegra_dma_tx_status callback, which is usually fine. When the DMA channel is configured as continous, then the bytes_transferred counter will increase over time and eventually overflow to become negative so the residue count will become invalid and the ALSA sound-dma code will report invalid hardware pointer values to the application. This results in some users becoming confused about the playout position and putting audio data in the wrong place. To fix this issue, always ensure the bytes_transferred field is modulo the size of the request. We only do this for the case of the cyclic transfer done ISR as anyone attempting to move 2GiB of DMA data in one transfer is unlikely. Note, we don't fix the issue that we should /never/ transfer a negative number of bytes so we could make those fields unsigned. Reviewed-by: Dmitry Osipenko <digetx@gmail.com> Signed-off-by: Ben Dooks <ben.dooks@codethink.co.uk> Acked-by: Jon Hunter <jonathanh@nvidia.com> Signed-off-by: Vinod Koul <vkoul@kernel.org>
1 parent bfeffd1 commit e486df3

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

drivers/dma/tegra20-apb-dma.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -636,7 +636,10 @@ static void handle_cont_sngl_cycle_dma_done(struct tegra_dma_channel *tdc,
636636

637637
sgreq = list_first_entry(&tdc->pending_sg_req, typeof(*sgreq), node);
638638
dma_desc = sgreq->dma_desc;
639-
dma_desc->bytes_transferred += sgreq->req_len;
639+
/* if we dma for long enough the transfer count will wrap */
640+
dma_desc->bytes_transferred =
641+
(dma_desc->bytes_transferred + sgreq->req_len) %
642+
dma_desc->bytes_requested;
640643

641644
/* Callback need to be call */
642645
if (!dma_desc->cb_count)

0 commit comments

Comments
 (0)