From: Alexandre Belloni Date: Fri, 1 Aug 2014 16:51:46 +0000 (+0200) Subject: dma: at_hdmac: fix invalid remaining bytes detection X-Git-Tag: firefly_0821_release~176^2~3413^2~1 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=6758ddafad55fc8e665bb03ff103d3e410483fe9;p=firefly-linux-kernel-4.4.55.git 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 Signed-off-by: Vinod Koul --- diff --git a/drivers/dma/at_hdmac.c b/drivers/dma/at_hdmac.c index d20ab1b73a3a..ca9dd2613283 100644 --- a/drivers/dma/at_hdmac.c +++ b/drivers/dma/at_hdmac.c @@ -294,14 +294,16 @@ static int atc_get_bytes_left(struct dma_chan *chan) ret = -EINVAL; goto out; } - atchan->remain_desc -= (desc_cur->lli.ctrla & ATC_BTSIZE_MAX) - << (desc_first->tx_width); - if (atchan->remain_desc < 0) { + + count = (desc_cur->lli.ctrla & ATC_BTSIZE_MAX) + << desc_first->tx_width; + if (atchan->remain_desc < count) { ret = -EINVAL; goto out; - } else { - ret = atchan->remain_desc; } + + atchan->remain_desc -= count; + ret = atchan->remain_desc; } else { /* * Get residual bytes when current