Commit 00fe8b7a authored by Julia Lawall's avatar Julia Lawall Committed by Bartlomiej Zolnierkiewicz
Browse files

ide: use DIV_ROUND_UP

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: default avatarJulia Lawall <julia@diku.dk>
Signed-off-by: default avatarBartlomiej Zolnierkiewicz <bzolnier@gmail.com>
parent 5e71d9c5
Loading
Loading
Loading
Loading
+12 −12
Original line number Diff line number Diff line
@@ -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;
+4 −4
Original line number Diff line number Diff line
@@ -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;