Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit dfa5ec79 authored by Julia Lawall's avatar Julia Lawall Committed by Greg Kroah-Hartman
Browse files

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: default avatarJulia Lawall <julia@diku.dk>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
parent 3d71fe0b
Loading
Loading
Loading
Loading
+3 −3
Original line number Original line Diff line number Diff line
@@ -960,9 +960,9 @@ static void prepare_packet_read(struct r8a66597 *r8a66597,
				r8a66597_write(r8a66597, TRCLR,
				r8a66597_write(r8a66597, TRCLR,
						td->pipe->pipetre);
						td->pipe->pipetre);
				r8a66597_write(r8a66597,
				r8a66597_write(r8a66597,
						(urb->transfer_buffer_length
						DIV_ROUND_UP
						+ td->maxpacket - 1)
						  (urb->transfer_buffer_length,
						/ td->maxpacket,
						   td->maxpacket),
						td->pipe->pipetrn);
						td->pipe->pipetrn);
				r8a66597_bset(r8a66597, TRENB,
				r8a66597_bset(r8a66597, TRENB,
						td->pipe->pipetre);
						td->pipe->pipetre);
+1 −1
Original line number Original line Diff line number Diff line
@@ -1404,7 +1404,7 @@ static struct urb *iso_alloc_urb (
		return NULL;
		return NULL;
	maxp = 0x7ff & le16_to_cpu(desc->wMaxPacketSize);
	maxp = 0x7ff & le16_to_cpu(desc->wMaxPacketSize);
	maxp *= 1 + (0x3 & (le16_to_cpu(desc->wMaxPacketSize) >> 11));
	maxp *= 1 + (0x3 & (le16_to_cpu(desc->wMaxPacketSize) >> 11));
	packets = (bytes + maxp - 1) / maxp;
	packets = DIV_ROUND_UP(bytes, maxp);


	urb = usb_alloc_urb (packets, GFP_KERNEL);
	urb = usb_alloc_urb (packets, GFP_KERNEL);
	if (!urb)
	if (!urb)
+2 −2
Original line number Original line Diff line number Diff line
@@ -1406,7 +1406,7 @@ static void ftdi_write_bulk_callback (struct urb *urb)
	data_offset = priv->write_offset;
	data_offset = priv->write_offset;
	if (data_offset > 0) {
	if (data_offset > 0) {
		/* Subtract the control bytes */
		/* Subtract the control bytes */
		countback -= (data_offset * ((countback + (PKTSZ - 1)) / PKTSZ));
		countback -= (data_offset * DIV_ROUND_UP(countback, PKTSZ));
	}
	}
	spin_lock_irqsave(&priv->tx_lock, flags);
	spin_lock_irqsave(&priv->tx_lock, flags);
	--priv->tx_outstanding_urbs;
	--priv->tx_outstanding_urbs;
@@ -1506,7 +1506,7 @@ static void ftdi_read_bulk_callback (struct urb *urb)


	/* count data bytes, but not status bytes */
	/* count data bytes, but not status bytes */
	countread = urb->actual_length;
	countread = urb->actual_length;
	countread -= 2 * ((countread + (PKTSZ - 1)) / PKTSZ);
	countread -= 2 * DIV_ROUND_UP(countread, PKTSZ);
	spin_lock_irqsave(&priv->rx_lock, flags);
	spin_lock_irqsave(&priv->rx_lock, flags);
	priv->rx_bytes += countread;
	priv->rx_bytes += countread;
	spin_unlock_irqrestore(&priv->rx_lock, flags);
	spin_unlock_irqrestore(&priv->rx_lock, flags);
+1 −1
Original line number Original line Diff line number Diff line
@@ -654,7 +654,7 @@ static void TIChasePort(struct edgeport_port *port, unsigned long timeout, int f
	/* (TIIsTxActive doesn't seem to wait for the last byte) */
	/* (TIIsTxActive doesn't seem to wait for the last byte) */
	if ((baud_rate=port->baud_rate) == 0)
	if ((baud_rate=port->baud_rate) == 0)
		baud_rate = 50;
		baud_rate = 50;
	msleep(max(1,(10000+baud_rate-1)/baud_rate));
	msleep(max(1, DIV_ROUND_UP(10000, baud_rate)));
}
}


static int TIChooseConfiguration (struct usb_device *dev)
static int TIChooseConfiguration (struct usb_device *dev)