]> err.no Git - linux-2.6/commitdiff
ide: use DIV_ROUND_UP
authorJulia Lawall <julia@diku.dk>
Sat, 26 Apr 2008 15:36:35 +0000 (17:36 +0200)
committerBartlomiej Zolnierkiewicz <bzolnier@gmail.com>
Sat, 26 Apr 2008 15:36:35 +0000 (17:36 +0200)
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>
Signed-off-by: Bartlomiej Zolnierkiewicz <bzolnier@gmail.com>
drivers/ide/arm/palm_bk3710.c
drivers/ide/pci/cmd640.c

index caa419404daa947b6b35a24a1074f7483ab14e33..666df779a5f46a119c1c2ff875eca5fb3d58e610 100644 (file)
@@ -96,11 +96,11 @@ static void palm_bk3710_setudmamode(void __iomem *base, unsigned int dev,
        u16 val16;
 
        /* DMA Data Setup */
-       t0 = (palm_bk3710_udmatimings[mode].cycletime + ide_palm_clk - 1)
-                       / ide_palm_clk - 1;
-       tenv = (20 + ide_palm_clk - 1) / ide_palm_clk - 1;
-       trp = (palm_bk3710_udmatimings[mode].rptime + ide_palm_clk - 1)
-                       / ide_palm_clk - 1;
+       t0 = DIV_ROUND_UP(palm_bk3710_udmatimings[mode].cycletime,
+                         ide_palm_clk) - 1;
+       tenv = DIV_ROUND_UP(20, ide_palm_clk) - 1;
+       trp = DIV_ROUND_UP(palm_bk3710_udmatimings[mode].rptime,
+                          ide_palm_clk) - 1;
 
        /* udmatim Register */
        val16 = readw(base + BK3710_UDMATIM) & (dev ? 0xFF0F : 0xFFF0);
@@ -141,8 +141,8 @@ static void palm_bk3710_setdmamode(void __iomem *base, unsigned int dev,
        cycletime = max_t(int, t->cycle, min_cycle);
 
        /* DMA Data Setup */
-       t0 = (cycletime + ide_palm_clk - 1) / ide_palm_clk;
-       td = (t->active + ide_palm_clk - 1) / ide_palm_clk;
+       t0 = DIV_ROUND_UP(cycletime, ide_palm_clk);
+       td = DIV_ROUND_UP(t->active, ide_palm_clk);
        tkw = t0 - td - 1;
        td -= 1;
 
@@ -168,9 +168,9 @@ static void palm_bk3710_setpiomode(void __iomem *base, ide_drive_t *mate,
        struct ide_timing *t;
 
        /* PIO Data Setup */
-       t0 = (cycletime + ide_palm_clk - 1) / ide_palm_clk;
-       t2 = (ide_timing_find_mode(XFER_PIO_0 + mode)->active +
-             ide_palm_clk - 1) / ide_palm_clk;
+       t0 = DIV_ROUND_UP(cycletime, ide_palm_clk);
+       t2 = DIV_ROUND_UP(ide_timing_find_mode(XFER_PIO_0 + mode)->active,
+                         ide_palm_clk);
 
        t2i = t0 - t2 - 1;
        t2 -= 1;
@@ -192,8 +192,8 @@ static void palm_bk3710_setpiomode(void __iomem *base, ide_drive_t *mate,
 
        /* TASKFILE Setup */
        t = ide_timing_find_mode(XFER_PIO_0 + mode);
-       t0 = (t->cyc8b + ide_palm_clk - 1) / ide_palm_clk;
-       t2 = (t->act8b + ide_palm_clk - 1) / ide_palm_clk;
+       t0 = DIV_ROUND_UP(t->cyc8b, ide_palm_clk);
+       t2 = DIV_ROUND_UP(t->act8b, ide_palm_clk);
 
        t2i = t0 - t2 - 1;
        t2 -= 1;
index fed93417d54ab43e81bb1e9cc521f119581a3e30..662099a98a72e24688c8e071f709c58328d72eb7 100644 (file)
@@ -561,15 +561,15 @@ static void cmd640_set_mode(ide_drive_t *drive, unsigned int index,
        active_time = ide_pio_timings[pio_mode].active_time;
        recovery_time = cycle_time - (setup_time + active_time);
        clock_time = 1000 / bus_speed;
-       cycle_count = (cycle_time + clock_time - 1) / clock_time;
+       cycle_count = DIV_ROUND_UP(cycle_time, clock_time);
 
-       setup_count = (setup_time + clock_time - 1) / clock_time;
+       setup_count = DIV_ROUND_UP(setup_time, clock_time);
 
-       active_count = (active_time + clock_time - 1) / clock_time;
+       active_count = DIV_ROUND_UP(active_time, clock_time);
        if (active_count < 2)
                active_count = 2; /* minimum allowed by cmd640 */
 
-       recovery_count = (recovery_time + clock_time - 1) / clock_time;
+       recovery_count = DIV_ROUND_UP(recovery_time, clock_time);
        recovery_count2 = cycle_count - (setup_count + active_count);
        if (recovery_count2 > recovery_count)
                recovery_count = recovery_count2;