usbip: fix off-by-one frame number calculation
authorArnd Bergmann <arnd@arndb.de>
Tue, 7 Nov 2017 10:39:56 +0000 (11:39 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 7 Nov 2017 14:34:08 +0000 (15:34 +0100)
vgadget_get_frame returns a frame number from 0 to 2046, which
may require an expensive division operation to wrap at one lower
than the usual number.

I can't see any reason for this, and all other drivers wrap at
a power-of-two number. My best explanation is that it was a simple
typo, so I'm changing the % modulo operator into a cheaper bitmask
that the other drivers use, to make it wrap after 0x7ff rather than
before it.

Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Reviewed-by: Krzysztof Opasiak <k.opasiak@samsung.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/usb/usbip/vudc_dev.c

index 0c07348820ea750ddc28ccf52f17531320e09396..16fb4f85a6f62b529849ab67d209cfa9b7f5bb88 100644 (file)
@@ -145,7 +145,7 @@ static int vgadget_get_frame(struct usb_gadget *_gadget)
        do_gettimeofday(&now);
        return ((now.tv_sec - udc->start_time.tv_sec) * 1000 +
                        (now.tv_usec - udc->start_time.tv_usec) / 1000)
-                       % 0x7FF;
+                       & 0x7FF;
 }
 
 static int vgadget_set_selfpowered(struct usb_gadget *_gadget, int value)