mirror of
https://github.com/hardkernel/linux.git
synced 2026-06-05 18:41:58 +09:00
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:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user