lkml.org 
[lkml]   [2009]   [Aug]   [1]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Subject[PATCH] treewide: Use DIV_ROUND_UP
From
Date
On Sat, 2009-08-01 at 21:48 +0200, Julia Lawall wrote:
> The kernel.h macro DIV_ROUND_CLOSEST performs the computation (x + d/2)/d
> but is perhaps more readable.

Similarly, DIV_ROUND_UP does ((n + d - 1) / d)

Signed-off-by: Joe Perches <joe@perches.com>

arch/alpha/boot/tools/objstrip.c | 2 +-
arch/sh/kernel/early_printk.c | 2 +-
arch/um/include/asm/pgtable-2level.h | 2 +-
arch/um/include/asm/pgtable-3level.h | 2 +-
drivers/md/raid1.c | 2 +-
drivers/md/raid10.c | 2 +-
drivers/media/video/cx2341x.c | 4 ++--
drivers/mtd/tests/mtd_stresstest.c | 2 +-
drivers/net/s2io.c | 2 +-
drivers/scsi/advansys.c | 2 +-
drivers/scsi/cxgb3i/cxgb3i.h | 2 +-
drivers/serial/sh-sci.c | 2 +-
drivers/staging/winbond/mds.c | 2 +-
drivers/xen/grant-table.c | 3 +--
kernel/posix-cpu-timers.c | 2 +-
lib/radix-tree.c | 2 +-
sound/pci/ctxfi/ctresource.c | 2 +-
sound/pci/hda/hda_intel.c | 3 +--
18 files changed, 19 insertions(+), 21 deletions(-)

diff --git a/arch/alpha/boot/tools/objstrip.c b/arch/alpha/boot/tools/objstrip.c
index ef18382..786e736 100644
--- a/arch/alpha/boot/tools/objstrip.c
+++ b/arch/alpha/boot/tools/objstrip.c
@@ -253,7 +253,7 @@ main (int argc, char *argv[])
}

if (pad) {
- mem_size = ((mem_size + pad - 1) / pad) * pad;
+ mem_size = DIV_ROUND_UP(mem_size, pad) * pad;
}

tocopy = mem_size - fil_size;
diff --git a/arch/sh/kernel/early_printk.c b/arch/sh/kernel/early_printk.c
index a952dcf..9fda893 100644
--- a/arch/sh/kernel/early_printk.c
+++ b/arch/sh/kernel/early_printk.c
@@ -174,7 +174,7 @@ static void scif_sercon_init(char *s)
/* Set baud rate */
sci_out(port, SCBRR, (CONFIG_SH_PCLK_FREQ + 16 * baud) /
(32 * baud) - 1);
- udelay((1000000+(baud-1)) / baud); /* Wait one bit interval */
+ udelay(DIV_ROUND_UP(1000000, baud)); /* Wait one bit interval */

sci_out(port, SCSPTR, 0);
sci_out(port, SCxSR, 0x60);
diff --git a/arch/um/include/asm/pgtable-2level.h b/arch/um/include/asm/pgtable-2level.h
index f534b73..7df789e 100644
--- a/arch/um/include/asm/pgtable-2level.h
+++ b/arch/um/include/asm/pgtable-2level.h
@@ -21,7 +21,7 @@
* we don't really have any PMD directory physically.
*/
#define PTRS_PER_PTE 1024
-#define USER_PTRS_PER_PGD ((TASK_SIZE + (PGDIR_SIZE - 1)) / PGDIR_SIZE)
+#define USER_PTRS_PER_PGD DIV_ROUND_UP(TASK_SIZE, PGDIR_SIZE)
#define PTRS_PER_PGD 1024
#define FIRST_USER_ADDRESS 0

diff --git a/arch/um/include/asm/pgtable-3level.h b/arch/um/include/asm/pgtable-3level.h
index 084de4a..c03a94a 100644
--- a/arch/um/include/asm/pgtable-3level.h
+++ b/arch/um/include/asm/pgtable-3level.h
@@ -40,7 +40,7 @@
#define PTRS_PER_PGD 1024
#endif

-#define USER_PTRS_PER_PGD ((TASK_SIZE + (PGDIR_SIZE - 1)) / PGDIR_SIZE)
+#define USER_PTRS_PER_PGD DIV_ROUND_UP(TASK_SIZE, PGDIR_SIZE)
#define FIRST_USER_ADDRESS 0

#define pte_ERROR(e) \
diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
index 0569efb..94f6e6b 100644
--- a/drivers/md/raid1.c
+++ b/drivers/md/raid1.c
@@ -78,7 +78,7 @@ static void r1bio_pool_free(void *r1_bio, void *data)
#define RESYNC_BLOCK_SIZE (64*1024)
//#define RESYNC_BLOCK_SIZE PAGE_SIZE
#define RESYNC_SECTORS (RESYNC_BLOCK_SIZE >> 9)
-#define RESYNC_PAGES ((RESYNC_BLOCK_SIZE + PAGE_SIZE-1) / PAGE_SIZE)
+#define RESYNC_PAGES DIV_ROUND_UP(RESYNC_BLOCK_SIZE, PAGE_SIZE)
#define RESYNC_WINDOW (2048*1024)

static void * r1buf_pool_alloc(gfp_t gfp_flags, void *data)
diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
index 7298a5e..574ee02 100644
--- a/drivers/md/raid10.c
+++ b/drivers/md/raid10.c
@@ -81,7 +81,7 @@ static void r10bio_pool_free(void *r10_bio, void *data)

/* Maximum size of each resync request */
#define RESYNC_BLOCK_SIZE (64*1024)
-#define RESYNC_PAGES ((RESYNC_BLOCK_SIZE + PAGE_SIZE-1) / PAGE_SIZE)
+#define RESYNC_PAGES DIV_ROUND_UP(RESYNC_BLOCK_SIZE, PAGE_SIZE)
/* amount of memory to reserve for resync requests */
#define RESYNC_WINDOW (1024*1024)
/* maximum number of concurrent requests, memory permitting */
diff --git a/drivers/media/video/cx2341x.c b/drivers/media/video/cx2341x.c
index 4c8e958..50626a2 100644
--- a/drivers/media/video/cx2341x.c
+++ b/drivers/media/video/cx2341x.c
@@ -304,7 +304,7 @@ static int cx2341x_set_ctrl(struct cx2341x_mpeg_params *params, int busy,
int b = ctrl->value + 1;
int gop = params->video_gop_size;
params->video_b_frames = ctrl->value;
- params->video_gop_size = b * ((gop + b - 1) / b);
+ params->video_gop_size = b * DIV_ROUND_UP(gop, b);
/* Max GOP size = 34 */
while (params->video_gop_size > 34)
params->video_gop_size -= b;
@@ -313,7 +313,7 @@ static int cx2341x_set_ctrl(struct cx2341x_mpeg_params *params, int busy,
case V4L2_CID_MPEG_VIDEO_GOP_SIZE: {
int b = params->video_b_frames + 1;
int gop = ctrl->value;
- params->video_gop_size = b * ((gop + b - 1) / b);
+ params->video_gop_size = b * DIV_ROUND_UP(gop, b);
/* Max GOP size = 34 */
while (params->video_gop_size > 34)
params->video_gop_size -= b;
diff --git a/drivers/mtd/tests/mtd_stresstest.c b/drivers/mtd/tests/mtd_stresstest.c
index 6392047..6ccf6a3 100644
--- a/drivers/mtd/tests/mtd_stresstest.c
+++ b/drivers/mtd/tests/mtd_stresstest.c
@@ -179,7 +179,7 @@ static int do_write(void)
offs = offsets[eb] = 0;
}
len = rand_len(offs);
- len = ((len + pgsize - 1) / pgsize) * pgsize;
+ len = DIV_ROUND_UP(len, pgsize) * pgsize;
if (offs + len > mtd->erasesize) {
if (bbt[eb + 1])
len = mtd->erasesize - offs;
diff --git a/drivers/net/s2io.c b/drivers/net/s2io.c
index 458daa0..23d1cf0 100644
--- a/drivers/net/s2io.c
+++ b/drivers/net/s2io.c
@@ -539,7 +539,7 @@ static struct pci_driver s2io_driver = {
};

/* A simplifier macro used both by init and free shared_mem Fns(). */
-#define TXD_MEM_PAGE_CNT(len, per_each) ((len+per_each - 1) / per_each)
+#define TXD_MEM_PAGE_CNT(len, per_each) DIV_ROUND_UP(len, per_each)

/* netqueue manipulation helper functions */
static inline void s2io_stop_all_tx_queue(struct s2io_nic *sp)
diff --git a/drivers/scsi/advansys.c b/drivers/scsi/advansys.c
index b756041..342ac83 100644
--- a/drivers/scsi/advansys.c
+++ b/drivers/scsi/advansys.c
@@ -2168,7 +2168,7 @@ do { \

#define ADV_SG_LIST_MAX_BYTE_SIZE \
(sizeof(ADV_SG_BLOCK) * \
- ((ADV_MAX_SG_LIST + (NO_OF_SG_PER_BLOCK - 1))/NO_OF_SG_PER_BLOCK))
+ DIV_ROUND_UP(ADV_MAX_SG_LIST, NO_OF_SG_PER_BLOCK))

/* struct asc_board flags */
#define ASC_IS_WIDE_BOARD 0x04 /* AdvanSys Wide Board */
diff --git a/drivers/scsi/cxgb3i/cxgb3i.h b/drivers/scsi/cxgb3i/cxgb3i.h
index e3133b5..7fd630c 100644
--- a/drivers/scsi/cxgb3i/cxgb3i.h
+++ b/drivers/scsi/cxgb3i/cxgb3i.h
@@ -127,7 +127,7 @@ struct cxgb3i_endpoint {
* @count: max. possible pdu payload
* @sgoffset: offset to the first sg entry for a given offset
*/
-#define MAX_PDU_FRAGS ((ULP2_MAX_PDU_PAYLOAD + 512 - 1) / 512)
+#define MAX_PDU_FRAGS DIV_ROUND_UP(ULP2_MAX_PDU_PAYLOAD, 512)
struct cxgb3i_task_data {
unsigned short nr_frags;
skb_frag_t frags[MAX_PDU_FRAGS];
diff --git a/drivers/serial/sh-sci.c b/drivers/serial/sh-sci.c
index 8e2feb5..ee1dac2 100644
--- a/drivers/serial/sh-sci.c
+++ b/drivers/serial/sh-sci.c
@@ -967,7 +967,7 @@ static void sci_set_termios(struct uart_port *port, struct ktermios *termios,
sci_out(port, SCSMR, sci_in(port, SCSMR) & ~3);

sci_out(port, SCBRR, t);
- udelay((1000000+(baud-1)) / baud); /* Wait one bit interval */
+ udelay(DIV_ROUND_UP(1000000, baud)); /* Wait one bit interval */
}

sci_init_pins(port, termios->c_cflag);
diff --git a/drivers/staging/winbond/mds.c b/drivers/staging/winbond/mds.c
index 59d6d67..b4042fa 100644
--- a/drivers/staging/winbond/mds.c
+++ b/drivers/staging/winbond/mds.c
@@ -119,7 +119,7 @@ static void Mds_DurationSet(struct wbsoft_priv *adapter, PDESCRIPTOR pDes, u8
else
Duration += SHORT_PREAMBLE_PLUS_PLCPHEADER_TIME;

- Duration += ( ((112 + Rate-1) / Rate) + DEFAULT_SIFSTIME );
+ Duration += ( DIV_ROUND_UP(112, Rate) + DEFAULT_SIFSTIME );
}
}

diff --git a/drivers/xen/grant-table.c b/drivers/xen/grant-table.c
index 7d8f531..8529e0e 100644
--- a/drivers/xen/grant-table.c
+++ b/drivers/xen/grant-table.c
@@ -491,8 +491,7 @@ static int gnttab_expand(unsigned int req_entries)
unsigned int cur, extra;

cur = nr_grant_frames;
- extra = ((req_entries + (GREFS_PER_GRANT_FRAME-1)) /
- GREFS_PER_GRANT_FRAME);
+ extra = DIV_ROUND_UP(req_entries, GREFS_PER_GRANT_FRAME);
if (cur + extra > max_nr_grant_frames())
return -ENOSPC;

diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c
index bece7c0..099d07b 100644
--- a/kernel/posix-cpu-timers.c
+++ b/kernel/posix-cpu-timers.c
@@ -181,7 +181,7 @@ int posix_cpu_clock_getres(const clockid_t which_clock, struct timespec *tp)
int error = check_clock(which_clock);
if (!error) {
tp->tv_sec = 0;
- tp->tv_nsec = ((NSEC_PER_SEC + HZ - 1) / HZ);
+ tp->tv_nsec = DIV_ROUND_UP(NSEC_PER_SEC, HZ);
if (CPUCLOCK_WHICH(which_clock) == CPUCLOCK_SCHED) {
/*
* If sched_clock is using a cycle counter, we
diff --git a/lib/radix-tree.c b/lib/radix-tree.c
index 23abbd9..d42ec49 100644
--- a/lib/radix-tree.c
+++ b/lib/radix-tree.c
@@ -44,7 +44,7 @@
#define RADIX_TREE_MAP_MASK (RADIX_TREE_MAP_SIZE-1)

#define RADIX_TREE_TAG_LONGS \
- ((RADIX_TREE_MAP_SIZE + BITS_PER_LONG - 1) / BITS_PER_LONG)
+ DIV_ROUND_UP(RADIX_TREE_MAP_SIZE, BITS_PER_LONG)

struct radix_tree_node {
unsigned int height; /* Height from the bottom */
diff --git a/sound/pci/ctxfi/ctresource.c b/sound/pci/ctxfi/ctresource.c
index 889c495..e430fad 100644
--- a/sound/pci/ctxfi/ctresource.c
+++ b/sound/pci/ctxfi/ctresource.c
@@ -215,7 +215,7 @@ int rsc_mgr_init(struct rsc_mgr *mgr, enum RSCTYP type,

mgr->type = NUM_RSCTYP;

- mgr->rscs = kzalloc(((amount + 8 - 1) / 8), GFP_KERNEL);
+ mgr->rscs = kzalloc(DIV_ROUND_UP(amount, 8), GFP_KERNEL);
if (NULL == mgr->rscs)
return -ENOMEM;

diff --git a/sound/pci/hda/hda_intel.c b/sound/pci/hda/hda_intel.c
index 77c1b84..5a214d2 100644
--- a/sound/pci/hda/hda_intel.c
+++ b/sound/pci/hda/hda_intel.c
@@ -1128,8 +1128,7 @@ static int azx_setup_periods(struct azx *chip,
if (!pos_adj)
pos_adj = pos_align;
else
- pos_adj = ((pos_adj + pos_align - 1) / pos_align) *
- pos_align;
+ pos_adj = DIV_ROUND_UP(pos_adj, pos_align) * pos_align;
pos_adj = frames_to_bytes(runtime, pos_adj);
if (pos_adj >= period_bytes) {
snd_printk(KERN_WARNING SFX "Too big adjustment %d\n",



\
 
 \ /
  Last update: 2009-08-02 01:45    [W:0.032 / U:1.696 seconds]
©2003-2018 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site