Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

dma: at_hdmac: fix invalid remaining bytes detection

Found using smatch:
drivers/dma/at_hdmac.c:299 atc_get_bytes_left() warn: unsigned
'atchan->remain_desc' is never less than zero.

Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
Signed-off-by: Vinod Koul <vinod.koul@intel.com>

authored by

Alexandre Belloni and committed by
Vinod Koul
6758ddaf cfc6abc3

+7 -5
+7 -5
drivers/dma/at_hdmac.c
··· 294 294 ret = -EINVAL; 295 295 goto out; 296 296 } 297 - atchan->remain_desc -= (desc_cur->lli.ctrla & ATC_BTSIZE_MAX) 298 - << (desc_first->tx_width); 299 - if (atchan->remain_desc < 0) { 297 + 298 + count = (desc_cur->lli.ctrla & ATC_BTSIZE_MAX) 299 + << desc_first->tx_width; 300 + if (atchan->remain_desc < count) { 300 301 ret = -EINVAL; 301 302 goto out; 302 - } else { 303 - ret = atchan->remain_desc; 304 303 } 304 + 305 + atchan->remain_desc -= count; 306 + ret = atchan->remain_desc; 305 307 } else { 306 308 /* 307 309 * Get residual bytes when current