dmaengine: PL08x: Refactor pl08x_getbytes_chan() to lower indentation
authorTomasz Figa <tomasz.figa@gmail.com>
Sun, 11 Aug 2013 17:59:13 +0000 (19:59 +0200)
committerVinod Koul <vinod.koul@intel.com>
Mon, 2 Sep 2013 06:19:56 +0000 (11:49 +0530)
Further patch will introduce support for PL080S, which requires some
things to be done conditionally, thus increasing indentation level of
some functions even more.

This patch reduces indentation level of pl08x_getbytes_chan() function
by inverting several conditions and returning from function wherever
possible.

Signed-off-by: Tomasz Figa <tomasz.figa@gmail.com>
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Vinod Koul <vinod.koul@intel.com>
drivers/dma/amba-pl08x.c

index 06fe45c74de57b3151e8520e9d7154f7ba7906e2..6a12392bfa98169d3d02674d96e0e7fc6b5cdda4 100644 (file)
@@ -469,47 +469,52 @@ static inline u32 get_bytes_in_cctl(u32 cctl)
 /* The channel should be paused when calling this */
 static u32 pl08x_getbytes_chan(struct pl08x_dma_chan *plchan)
 {
+       struct pl08x_lli *llis_va;
        struct pl08x_phy_chan *ch;
+       dma_addr_t llis_bus;
        struct pl08x_txd *txd;
-       size_t bytes = 0;
+       size_t bytes;
+       int index;
+       u32 clli;
 
        ch = plchan->phychan;
        txd = plchan->at;
 
+       if (!ch || !txd)
+               return 0;
+
        /*
         * Follow the LLIs to get the number of remaining
         * bytes in the currently active transaction.
         */
-       if (ch && txd) {
-               u32 clli = readl(ch->base + PL080_CH_LLI) & ~PL080_LLI_LM_AHB2;
+       clli = readl(ch->base + PL080_CH_LLI) & ~PL080_LLI_LM_AHB2;
 
-               /* First get the remaining bytes in the active transfer */
-               bytes = get_bytes_in_cctl(readl(ch->base + PL080_CH_CONTROL));
+       /* First get the remaining bytes in the active transfer */
+       bytes = get_bytes_in_cctl(readl(ch->base + PL080_CH_CONTROL));
 
-               if (clli) {
-                       struct pl08x_lli *llis_va = txd->llis_va;
-                       dma_addr_t llis_bus = txd->llis_bus;
-                       int index;
+       if (!clli)
+               return bytes;
 
-                       BUG_ON(clli < llis_bus || clli >= llis_bus +
+       llis_va = txd->llis_va;
+       llis_bus = txd->llis_bus;
+
+       BUG_ON(clli < llis_bus || clli >= llis_bus +
                                sizeof(struct pl08x_lli) * MAX_NUM_TSFR_LLIS);
 
-                       /*
-                        * Locate the next LLI - as this is an array,
-                        * it's simple maths to find.
-                        */
-                       index = (clli - llis_bus) / sizeof(struct pl08x_lli);
+       /*
+        * Locate the next LLI - as this is an array,
+        * it's simple maths to find.
+        */
+       index = (clli - llis_bus) / sizeof(struct pl08x_lli);
 
-                       for (; index < MAX_NUM_TSFR_LLIS; index++) {
-                               bytes += get_bytes_in_cctl(llis_va[index].cctl);
+       for (; index < MAX_NUM_TSFR_LLIS; index++) {
+               bytes += get_bytes_in_cctl(llis_va[index].cctl);
 
-                               /*
-                                * A LLI pointer of 0 terminates the LLI list
-                                */
-                               if (!llis_va[index].lli)
-                                       break;
-                       }
-               }
+               /*
+                * A LLI pointer of 0 terminates the LLI list
+                */
+               if (!llis_va[index].lli)
+                       break;
        }
 
        return bytes;