public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 2/6] fs/direct-io.c: Use DIV_ROUND_UP
@ 2008-02-14 15:14 Julia Lawall
  2008-02-14 17:25 ` Zach Brown
  2008-02-14 17:38 ` Nishanth Aravamudan
  0 siblings, 2 replies; 7+ messages in thread
From: Julia Lawall @ 2008-02-14 15:14 UTC (permalink / raw)
  To: 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/fs/direct-io.c b/fs/direct-io.c
--- a/fs/direct-io.c 2008-02-08 08:58:17.000000000 +0100
+++ b/fs/direct-io.c 2008-02-13 20:58:53.000000000 +0100
@@ -976,7 +976,7 @@ direct_io_worker(int rw, struct kiocb *i
 	for (seg = 0; seg < nr_segs; seg++) {
 		user_addr = (unsigned long)iov[seg].iov_base;
 		dio->pages_in_io +=
-			((user_addr+iov[seg].iov_len +PAGE_SIZE-1)/PAGE_SIZE
+			(DIV_ROUND_UP(user_addr + iov[seg].iov_len, PAGE_SIZE)
 				- user_addr/PAGE_SIZE);
 	}

@@ -998,7 +998,7 @@ direct_io_worker(int rw, struct kiocb *i
 			dio->total_pages++;
 			bytes -= PAGE_SIZE - (user_addr & (PAGE_SIZE - 1));
 		}
-		dio->total_pages += (bytes + PAGE_SIZE - 1) / PAGE_SIZE;
+		dio->total_pages += DIV_ROUND_UP(bytes, PAGE_SIZE);
 		dio->curr_user_address = user_addr;

 		ret = do_direct_IO(dio);

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

end of thread, other threads:[~2008-02-14 23:38 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-02-14 15:14 [PATCH 2/6] fs/direct-io.c: Use DIV_ROUND_UP Julia Lawall
2008-02-14 17:25 ` Zach Brown
2008-02-14 17:38 ` Nishanth Aravamudan
2008-02-14 18:18   ` Pekka Enberg
2008-02-14 19:50     ` Julia Lawall
2008-02-14 22:16       ` Mariusz Kozlowski
2008-02-14 23:37         ` Nishanth Aravamudan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox