* [PATCH 1/5] drivers/media: Use DIV_ROUND_CLOSEST
@ 2009-08-01 19:48 Julia Lawall
2009-08-01 23:43 ` [PATCH] treewide: Use DIV_ROUND_UP Joe Perches
0 siblings, 1 reply; 5+ messages in thread
From: Julia Lawall @ 2009-08-01 19:48 UTC (permalink / raw)
To: mchehab, linux-media, linux-kernel, kernel-janitors
From: Julia Lawall <julia@diku.dk>
The kernel.h macro DIV_ROUND_CLOSEST performs the computation (x + d/2)/d
but is perhaps more readable.
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 x,__divisor;
@@
- (((x) + ((__divisor) / 2)) / (__divisor))
+ DIV_ROUND_CLOSEST(x,__divisor)
// </smpl>
Signed-off-by: Julia Lawall <julia@diku.dk>
---
drivers/media/dvb/frontends/dib7000p.c | 2 +-
drivers/media/dvb/frontends/stb6100.c | 4 +++-
drivers/media/dvb/frontends/tda10021.c | 2 +-
drivers/media/dvb/frontends/ves1820.c | 2 +-
drivers/media/dvb/pluto2/pluto2.c | 2 +-
drivers/media/video/tuner-core.c | 4 ++--
drivers/media/video/v4l1-compat.c | 5 ++---
7 files changed, 11 insertions(+), 10 deletions(-)
diff --git a/drivers/media/dvb/frontends/dib7000p.c b/drivers/media/dvb/frontends/dib7000p.c
index 8217e5b..d99ac65 100644
--- a/drivers/media/dvb/frontends/dib7000p.c
+++ b/drivers/media/dvb/frontends/dib7000p.c
@@ -883,7 +883,7 @@ static void dib7000p_spur_protect(struct dib7000p_state *state, u32 rf_khz, u32
255, 255, 255, 255, 255, 255};
u32 xtal = state->cfg.bw->xtal_hz / 1000;
- int f_rel = ( (rf_khz + xtal/2) / xtal) * xtal - rf_khz;
+ int f_rel = DIV_ROUND_CLOSEST(rf_khz, xtal) * xtal - rf_khz;
int k;
int coef_re[8],coef_im[8];
int bw_khz = bw;
diff --git a/drivers/media/dvb/frontends/stb6100.c b/drivers/media/dvb/frontends/stb6100.c
index 1ed5a7d..60ee18a 100644
--- a/drivers/media/dvb/frontends/stb6100.c
+++ b/drivers/media/dvb/frontends/stb6100.c
@@ -367,7 +367,9 @@ static int stb6100_set_frequency(struct dvb_frontend *fe, u32 frequency)
/* N(I) = floor(f(VCO) / (f(XTAL) * (PSD2 ? 2 : 1))) */
nint = fvco / (state->reference << psd2);
/* N(F) = round(f(VCO) / f(XTAL) * (PSD2 ? 2 : 1) - N(I)) * 2 ^ 9 */
- nfrac = (((fvco - (nint * state->reference << psd2)) << (9 - psd2)) + state->reference / 2) / state->reference;
+ nfrac = DIV_ROUND_CLOSEST((fvco - (nint * state->reference << psd2))
+ << (9 - psd2),
+ state->reference);
dprintk(verbose, FE_DEBUG, 1,
"frequency = %u, srate = %u, g = %u, odiv = %u, psd2 = %u, fxtal = %u, osm = %u, fvco = %u, N(I) = %u, N(F) = %u",
frequency, srate, (unsigned int)g, (unsigned int)odiv,
diff --git a/drivers/media/dvb/frontends/tda10021.c b/drivers/media/dvb/frontends/tda10021.c
index f648fdb..03fc6e7 100644
--- a/drivers/media/dvb/frontends/tda10021.c
+++ b/drivers/media/dvb/frontends/tda10021.c
@@ -176,7 +176,7 @@ static int tda10021_set_symbolrate (struct tda10021_state* state, u32 symbolrate
tmp = ((symbolrate << 4) % FIN) << 8;
ratio = (ratio << 8) + tmp / FIN;
tmp = (tmp % FIN) << 8;
- ratio = (ratio << 8) + (tmp + FIN/2) / FIN;
+ ratio = (ratio << 8) + DIV_ROUND_CLOSEST(tmp, FIN);
BDR = ratio;
BDRI = (((XIN << 5) / symbolrate) + 1) / 2;
diff --git a/drivers/media/dvb/frontends/ves1820.c b/drivers/media/dvb/frontends/ves1820.c
index a184597..c62a3ba 100644
--- a/drivers/media/dvb/frontends/ves1820.c
+++ b/drivers/media/dvb/frontends/ves1820.c
@@ -165,7 +165,7 @@ static int ves1820_set_symbolrate(struct ves1820_state *state, u32 symbolrate)
tmp = ((symbolrate << 4) % fin) << 8;
ratio = (ratio << 8) + tmp / fin;
tmp = (tmp % fin) << 8;
- ratio = (ratio << 8) + (tmp + fin / 2) / fin;
+ ratio = (ratio << 8) + DIV_ROUND_CLOSEST(tmp, fin);
BDR = ratio;
BDRI = (((state->config->xin << 5) / symbolrate) + 1) / 2;
diff --git a/drivers/media/dvb/pluto2/pluto2.c b/drivers/media/dvb/pluto2/pluto2.c
index 598eaf8..852f2b7 100644
--- a/drivers/media/dvb/pluto2/pluto2.c
+++ b/drivers/media/dvb/pluto2/pluto2.c
@@ -439,7 +439,7 @@ static inline u32 divide(u32 numerator, u32 denominator)
if (denominator == 0)
return ~0;
- return (numerator + denominator / 2) / denominator;
+ return DIV_ROUND_CLOSEST(numerator, denominator);
}
/* LG Innotek TDTE-E001P (Infineon TUA6034) */
diff --git a/drivers/media/video/tuner-core.c b/drivers/media/video/tuner-core.c
index 5375942..2801cdc 100644
--- a/drivers/media/video/tuner-core.c
+++ b/drivers/media/video/tuner-core.c
@@ -819,8 +819,8 @@ static int tuner_g_frequency(struct v4l2_subdev *sd, struct v4l2_frequency *f)
fe_tuner_ops->get_frequency(&t->fe, &abs_freq);
f->frequency = (V4L2_TUNER_RADIO == t->mode) ?
- (abs_freq * 2 + 125/2) / 125 :
- (abs_freq + 62500/2) / 62500;
+ DIV_ROUND_CLOSEST(abs_freq * 2, 125) :
+ DIV_ROUND_CLOSEST(abs_freq, 62500);
return 0;
}
f->frequency = (V4L2_TUNER_RADIO == t->mode) ?
diff --git a/drivers/media/video/v4l1-compat.c b/drivers/media/video/v4l1-compat.c
index 02f2a6d..761fbd6 100644
--- a/drivers/media/video/v4l1-compat.c
+++ b/drivers/media/video/v4l1-compat.c
@@ -76,9 +76,8 @@ get_v4l_control(struct file *file,
dprintk("VIDIOC_G_CTRL: %d\n", err);
return 0;
}
- return ((ctrl2.value - qctrl2.minimum) * 65535
- + (qctrl2.maximum - qctrl2.minimum) / 2)
- / (qctrl2.maximum - qctrl2.minimum);
+ return DIV_ROUND_CLOSEST((ctrl2.value-qctrl2.minimum) * 65535,
+ qctrl2.maximum - qctrl2.minimum);
}
return 0;
}
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH] treewide: Use DIV_ROUND_UP
2009-08-01 19:48 [PATCH 1/5] drivers/media: Use DIV_ROUND_CLOSEST Julia Lawall
@ 2009-08-01 23:43 ` Joe Perches
2009-08-02 0:10 ` Daniel Walker
0 siblings, 1 reply; 5+ messages in thread
From: Joe Perches @ 2009-08-01 23:43 UTC (permalink / raw)
To: Julia Lawall; +Cc: linux-kernel, kernel-janitors
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",
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] treewide: Use DIV_ROUND_UP
2009-08-01 23:43 ` [PATCH] treewide: Use DIV_ROUND_UP Joe Perches
@ 2009-08-02 0:10 ` Daniel Walker
2009-08-02 1:07 ` [PATCH v2 1/2] treewide: Use roundup Joe Perches
2009-08-02 1:07 ` [PATCH v2 2/2] treewide: Use DIV_ROUND_UP Joe Perches
0 siblings, 2 replies; 5+ messages in thread
From: Daniel Walker @ 2009-08-02 0:10 UTC (permalink / raw)
To: Joe Perches; +Cc: Julia Lawall, linux-kernel, kernel-janitors
On Sat, 2009-08-01 at 16:43 -0700, Joe Perches wrote:
> 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;
Doesn't this look more like,
#define roundup(x, y) ((((x) + ((y) - 1)) / (y)) * (y))
> --- 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);
Same here , roundup() ..
> /* 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);
and here..
Seems like there are a few more like this .. Could you either use
roundup() or merge the two macros .. Or explain why your not using it..
Daniel
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v2 1/2] treewide: Use roundup
2009-08-02 0:10 ` Daniel Walker
@ 2009-08-02 1:07 ` Joe Perches
2009-08-02 1:07 ` [PATCH v2 2/2] treewide: Use DIV_ROUND_UP Joe Perches
1 sibling, 0 replies; 5+ messages in thread
From: Joe Perches @ 2009-08-02 1:07 UTC (permalink / raw)
To: Daniel Walker; +Cc: Julia Lawall, linux-kernel, kernel-janitors
On Sat, 2009-08-01 at 17:10 -0700, Daniel Walker wrote:
> On Sat, 2009-08-01 at 16:43 -0700, Joe Perches wrote:
> > 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>
> > - mem_size = ((mem_size + pad - 1) / pad) * pad;
> > + mem_size = DIV_ROUND_UP(mem_size, pad) * pad;
> Doesn't this look more like,
> #define roundup(x, y) ((((x) + ((y) - 1)) / (y)) * (y))
Yes. Also, the first patch should not be applied because
it converts arch/alpha/boot/tools/objstrip.c which does
not include kernel.h.
Here's another pass at it.
Signed-off-by: Joe Perches <joe@perches.com>
---
drivers/media/video/cx2341x.c | 4 ++--
drivers/mtd/tests/mtd_stresstest.c | 2 +-
sound/pci/hda/hda_intel.c | 3 +--
3 files changed, 4 insertions(+), 5 deletions(-)
diff --git a/drivers/media/video/cx2341x.c b/drivers/media/video/cx2341x.c
index 4c8e958..3d40191 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 = roundup(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 = roundup(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..f146c81 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 = roundup(len, pgsize);
if (offs + len > mtd->erasesize) {
if (bbt[eb + 1])
len = mtd->erasesize - offs;
diff --git a/sound/pci/hda/hda_intel.c b/sound/pci/hda/hda_intel.c
index 77c1b84..1f015b0 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 = roundup(pos_adj, 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",
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH v2 2/2] treewide: Use DIV_ROUND_UP
2009-08-02 0:10 ` Daniel Walker
2009-08-02 1:07 ` [PATCH v2 1/2] treewide: Use roundup Joe Perches
@ 2009-08-02 1:07 ` Joe Perches
1 sibling, 0 replies; 5+ messages in thread
From: Joe Perches @ 2009-08-02 1:07 UTC (permalink / raw)
To: Daniel Walker; +Cc: Julia Lawall, linux-kernel, kernel-janitors
On Sat, 2009-08-01 at 17:10 -0700, Daniel Walker wrote:
> On Sat, 2009-08-01 at 16:43 -0700, Joe Perches wrote:
> > 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)
> Seems like there are a few more like this .. Could you either use
> roundup() or merge the two macros .. Or explain why your not using it..
Signed-off-by: Joe Perches <joe@perches.com>
---
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/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 +-
14 files changed, 14 insertions(+), 15 deletions(-)
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/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;
^ permalink raw reply related [flat|nested] 5+ messages in thread
end of thread, other threads:[~2009-08-02 1:07 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-08-01 19:48 [PATCH 1/5] drivers/media: Use DIV_ROUND_CLOSEST Julia Lawall
2009-08-01 23:43 ` [PATCH] treewide: Use DIV_ROUND_UP Joe Perches
2009-08-02 0:10 ` Daniel Walker
2009-08-02 1:07 ` [PATCH v2 1/2] treewide: Use roundup Joe Perches
2009-08-02 1:07 ` [PATCH v2 2/2] treewide: Use DIV_ROUND_UP Joe Perches
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox