dma: at_hdmac: fix invalid remaining bytes detection
authorAlexandre Belloni <alexandre.belloni@free-electrons.com>
Fri, 1 Aug 2014 16:51:46 +0000 (18:51 +0200)
committerVinod Koul <vinod.koul@intel.com>
Thu, 7 Aug 2014 16:22:27 +0000 (21:52 +0530)
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>
drivers/dma/at_hdmac.c

index d20ab1b73a3a2b530cd6cf89d4ac5dd3be1fbe80..ca9dd261328357d079466b9d0659e43d57a0da4c 100644 (file)
@@ -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