usb: dwc3: gadget: Fix truncated cast issue
authorJohn Youn <johnyoun@synopsys.com>
Mon, 23 May 2016 18:32:45 +0000 (11:32 -0700)
committerFelipe Balbi <felipe.balbi@linux.intel.com>
Mon, 20 Jun 2016 09:32:45 +0000 (12:32 +0300)
From sparse:
warning: cast truncates bits from constant value (100 becomes 0)

The DWC3_TRB_NUM constant is too big for u8. Do the calculation a
slightly different way that should still be optimized out for the case
where DWC3_TRB_NUM == 256.

Signed-off-by: John Youn <johnyoun@synopsys.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
drivers/usb/dwc3/gadget.c

index fbc7968..d0f7458 100644 (file)
@@ -882,7 +882,7 @@ static u32 dwc3_calc_trbs_left(struct dwc3_ep *dep)
        }
 
        trbs_left = dep->trb_dequeue - dep->trb_enqueue;
-       trbs_left %= DWC3_TRB_NUM;
+       trbs_left &= (DWC3_TRB_NUM - 1);
 
        if (dep->trb_dequeue < dep->trb_enqueue)
                trbs_left--;