Skip to content

Commit dfa5ec7

Browse files
Julia Lawallgregkh
authored andcommitted
USB: use DIV_ROUND_UP
The kernel.h macro DIV_ROUND_UP performs the computation (((n) + (d) - 1) / (d)) but is perhaps more readable. An extract of the semantic patch that makes this change is as follows: (http://www.emn.fr/x-info/coccinelle/) // <smpl> @haskernel@ @@ #include <linux/kernel.h> @Depends on haskernel@ expression n,d; @@ ( - (n + d - 1) / d + DIV_ROUND_UP(n,d) | - (n + (d - 1)) / d + DIV_ROUND_UP(n,d) ) @Depends on haskernel@ expression n,d; @@ - DIV_ROUND_UP((n),d) + DIV_ROUND_UP(n,d) @Depends on haskernel@ expression n,d; @@ - DIV_ROUND_UP(n,(d)) + DIV_ROUND_UP(n,d) // </smpl> Signed-off-by: Julia Lawall <julia@diku.dk> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
1 parent 3d71fe0 commit dfa5ec7

4 files changed

Lines changed: 7 additions & 7 deletions

File tree

‎drivers/usb/host/r8a66597-hcd.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -960,9 +960,9 @@ static void prepare_packet_read(struct r8a66597 *r8a66597,
960960
r8a66597_write(r8a66597, TRCLR,
961961
td->pipe->pipetre);
962962
r8a66597_write(r8a66597,
963-
(urb->transfer_buffer_length
964-
+ td->maxpacket - 1)
965-
/ td->maxpacket,
963+
DIV_ROUND_UP
964+
(urb->transfer_buffer_length,
965+
td->maxpacket),
966966
td->pipe->pipetrn);
967967
r8a66597_bset(r8a66597, TRENB,
968968
td->pipe->pipetre);

‎drivers/usb/misc/usbtest.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1404,7 +1404,7 @@ static struct urb *iso_alloc_urb (
14041404
return NULL;
14051405
maxp = 0x7ff & le16_to_cpu(desc->wMaxPacketSize);
14061406
maxp *= 1 + (0x3 & (le16_to_cpu(desc->wMaxPacketSize) >> 11));
1407-
packets = (bytes + maxp - 1) / maxp;
1407+
packets = DIV_ROUND_UP(bytes, maxp);
14081408

14091409
urb = usb_alloc_urb (packets, GFP_KERNEL);
14101410
if (!urb)

‎drivers/usb/serial/ftdi_sio.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1406,7 +1406,7 @@ static void ftdi_write_bulk_callback (struct urb *urb)
14061406
data_offset = priv->write_offset;
14071407
if (data_offset > 0) {
14081408
/* Subtract the control bytes */
1409-
countback -= (data_offset * ((countback + (PKTSZ - 1)) / PKTSZ));
1409+
countback -= (data_offset * DIV_ROUND_UP(countback, PKTSZ));
14101410
}
14111411
spin_lock_irqsave(&priv->tx_lock, flags);
14121412
--priv->tx_outstanding_urbs;
@@ -1506,7 +1506,7 @@ static void ftdi_read_bulk_callback (struct urb *urb)
15061506

15071507
/* count data bytes, but not status bytes */
15081508
countread = urb->actual_length;
1509-
countread -= 2 * ((countread + (PKTSZ - 1)) / PKTSZ);
1509+
countread -= 2 * DIV_ROUND_UP(countread, PKTSZ);
15101510
spin_lock_irqsave(&priv->rx_lock, flags);
15111511
priv->rx_bytes += countread;
15121512
spin_unlock_irqrestore(&priv->rx_lock, flags);

‎drivers/usb/serial/io_ti.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -654,7 +654,7 @@ static void TIChasePort(struct edgeport_port *port, unsigned long timeout, int f
654654
/* (TIIsTxActive doesn't seem to wait for the last byte) */
655655
if ((baud_rate=port->baud_rate) == 0)
656656
baud_rate = 50;
657-
msleep(max(1,(10000+baud_rate-1)/baud_rate));
657+
msleep(max(1, DIV_ROUND_UP(10000, baud_rate)));
658658
}
659659

660660
static int TIChooseConfiguration (struct usb_device *dev)

0 commit comments

Comments
 (0)