]> git.baikalelectronics.ru Git - kernel.git/commit
dmaengine: tegra: avoid overflow of byte tracking
authorBen Dooks <ben.dooks@codethink.co.uk>
Wed, 21 Nov 2018 16:13:19 +0000 (16:13 +0000)
committerVinod Koul <vkoul@kernel.org>
Mon, 7 Jan 2019 04:22:41 +0000 (09:52 +0530)
commitfa96faef795964f03cb44a2d271b9114340c6616
treefc2547e6939871426e7fc8e075aad2ae0262ea63
parentf9bb4b753eb00c02014e4467a28609f4f6ac7f88
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>
drivers/dma/tegra20-apb-dma.c