dmaengine: rockchip-dma: Fix overflow in get_bytes_xfered calculation

The transferred bytes are calculated by subtracting first_lli.base from
current position (cur_pos). However, cur_pos remains 0 until the first
burst transfer completes, which could result in a negative value.
This leads to incorrect byte count reporting.

Fix the overflow by clamping the calculated bytes to 0 when negative,
ensuring the reported transfer position matches hardware state before
the first burst completion.

Signed-off-by: Sugar Zhang <sugar.zhang@rock-chips.com>
Change-Id: Ie9d14f514d2ebfe068b535b2f9892b319cb8a41b
This commit is contained in:
Sugar Zhang
2025-04-29 18:15:49 +08:00
parent 093b727416
commit d2c81f797c

View File

@@ -682,6 +682,19 @@ static int rk_dma_lch_get_bytes_xfered(struct rk_dma_lch *l)
else
bytes = ds->desc_hw[0].dar - ds->desc_hw[1].dar;
/*
* The transferred bytes are calculated by subtracting first_lli.base from
* current position (cur_pos). However, cur_pos remains 0 until the first
* burst transfer completes, which could result in a negative value.
* This leads to incorrect byte count reporting.
*
* Fix the overflow by clamping the calculated bytes to 0 when negative,
* ensuring the reported transfer position matches hardware state before
* the first burst completion.
*/
if (bytes < 0)
bytes = 0;
return bytes;
}