LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* [PATCH 6/6] drivers/hid: Use DIV_ROUND_UP
@ 2008-02-14 15:16 Julia Lawall
  2008-02-15 12:48 ` Jiri Kosina
  0 siblings, 1 reply; 2+ messages in thread
From: Julia Lawall @ 2008-02-14 15:16 UTC (permalink / raw)
  To: jkosina, linux-kernel, kernel-janitors

From: Julia Lawall <julia@diku.dk>

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>

---

diff -u -p a/drivers/hid/usbhid/hid-core.c b/drivers/hid/usbhid/hid-core.c
--- a/drivers/hid/usbhid/hid-core.c 2007-11-08 18:33:32.000000000 +0100
+++ b/drivers/hid/usbhid/hid-core.c 2008-02-13 20:51:00.000000000 +0100
@@ -278,7 +278,7 @@ static int hid_submit_ctrl(struct hid_de
 		usbhid->urbctrl->pipe = usb_rcvctrlpipe(hid_to_usb_dev(hid), 0);
 		maxpacket = usb_maxpacket(hid_to_usb_dev(hid), usbhid->urbctrl->pipe, 0);
 		if (maxpacket > 0) {
-			padlen = (len + maxpacket - 1) / maxpacket;
+			padlen = DIV_ROUND_UP(len, maxpacket);
 			padlen *= maxpacket;
 			if (padlen > usbhid->bufsize)
 				padlen = usbhid->bufsize;

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH 6/6] drivers/hid: Use DIV_ROUND_UP
  2008-02-14 15:16 [PATCH 6/6] drivers/hid: Use DIV_ROUND_UP Julia Lawall
@ 2008-02-15 12:48 ` Jiri Kosina
  0 siblings, 0 replies; 2+ messages in thread
From: Jiri Kosina @ 2008-02-15 12:48 UTC (permalink / raw)
  To: Julia Lawall; +Cc: linux-kernel, kernel-janitors

On Thu, 14 Feb 2008, Julia Lawall wrote:

> -			padlen = (len + maxpacket - 1) / maxpacket;
> +			padlen = DIV_ROUND_UP(len, maxpacket);

Applied, thanks.

-- 
Jiri Kosina

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2008-02-15 12:48 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-02-14 15:16 [PATCH 6/6] drivers/hid: Use DIV_ROUND_UP Julia Lawall
2008-02-15 12:48 ` Jiri Kosina

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).