From 4ed3c0e713adac46dcca8a9ee668221399b7b659 Mon Sep 17 00:00:00 2001 From: "Pedro F. Giffuni" Date: Sat, 30 Apr 2016 14:41:18 +0000 Subject: [PATCH] sys: Make use of our rounddown() macro when sys/param.h is available. No functional change. --- sys/arm/at91/at91_pmc.c | 2 +- sys/ddb/db_output.c | 3 +-- sys/dev/acpi_support/acpi_hp.c | 3 ++- sys/dev/cxgbe/t4_netmap.c | 2 +- sys/dev/fb/fb.c | 2 +- sys/dev/fb/vesa.c | 2 +- sys/dev/fb/vga.c | 2 +- sys/dev/iwn/if_iwn.c | 2 +- sys/dev/kbd/kbd.c | 2 +- sys/dev/syscons/scmouse.c | 6 +++--- sys/dev/syscons/scvgarndr.c | 2 +- sys/dev/vt/hw/vga/vt_vga.c | 2 +- sys/dev/vt/vt_core.c | 4 ++-- sys/dev/wpi/if_wpi.c | 2 +- sys/fs/nandfs/nandfs_vfsops.c | 4 ++-- sys/geom/virstor/g_virstor.c | 11 +++++------ sys/libkern/crc32.c | 2 +- sys/mips/atheros/ar934x_chip.c | 2 +- sys/mips/atheros/qca953x_chip.c | 2 +- sys/mips/atheros/qca955x_chip.c | 2 +- sys/rpc/clnt_dg.c | 4 ++-- 21 files changed, 31 insertions(+), 32 deletions(-) diff --git a/sys/arm/at91/at91_pmc.c b/sys/arm/at91/at91_pmc.c index a97849b2f31d..88810a6cdebd 100644 --- a/sys/arm/at91/at91_pmc.c +++ b/sys/arm/at91/at91_pmc.c @@ -506,7 +506,7 @@ at91_pmc_sense_main_clock(void) * AT91C_MAIN_CLOCK in the kernel config file. */ if (ckgr_val >= 21000000) - return ((ckgr_val + 250) / 500 * 500); + return (rounddown(ckgr_val + 250, 500)); /* * Try to find the standard frequency that match best. diff --git a/sys/ddb/db_output.c b/sys/ddb/db_output.c index a2afb6aba8e0..109c7a50e1d9 100644 --- a/sys/ddb/db_output.c +++ b/sys/ddb/db_output.c @@ -71,8 +71,7 @@ struct dbputchar_arg { static int db_output_position = 0; /* output column */ static int db_last_non_space = 0; /* last non-space character */ db_expr_t db_tab_stop_width = 8; /* how wide are tab stops? */ -#define NEXT_TAB(i) \ - ((((i) + db_tab_stop_width) / db_tab_stop_width) * db_tab_stop_width) +#define NEXT_TAB(i) rounddown((i) + db_tab_stop_width, db_tab_stop_width) db_expr_t db_max_width = 79; /* output line width */ db_expr_t db_lines_per_page = 20; /* lines per page */ volatile int db_pager_quit; /* user requested quit */ diff --git a/sys/dev/acpi_support/acpi_hp.c b/sys/dev/acpi_support/acpi_hp.c index 282803814dc5..ec8589659438 100644 --- a/sys/dev/acpi_support/acpi_hp.c +++ b/sys/dev/acpi_support/acpi_hp.c @@ -1033,7 +1033,8 @@ acpi_hp_hex_decode(char* buffer) UINT8 *uin; UINT8 uout; - if (((int)length/2)*2 == length || length < 10) return; + if (rounddown((int)length, 2) == length || length < 10) + return; for (i = 0; iqsize_rxq / 8) * 8; + na.num_rx_desc = rounddown(vi->qsize_rxq, 8); na.nm_txsync = cxgbe_netmap_txsync; na.nm_rxsync = cxgbe_netmap_rxsync; na.nm_register = cxgbe_netmap_reg; diff --git a/sys/dev/fb/fb.c b/sys/dev/fb/fb.c index aa2d30005f41..183abdc3bfcb 100644 --- a/sys/dev/fb/fb.c +++ b/sys/dev/fb/fb.c @@ -86,7 +86,7 @@ vid_realloc_array(void) return ENOMEM; s = spltty(); - newsize = ((adapters + ARRAY_DELTA)/ARRAY_DELTA)*ARRAY_DELTA; + newsize = rounddown(adapters + ARRAY_DELTA, ARRAY_DELTA); new_adp = malloc(sizeof(*new_adp)*newsize, M_DEVBUF, M_WAITOK | M_ZERO); new_vidsw = malloc(sizeof(*new_vidsw)*newsize, M_DEVBUF, M_WAITOK | M_ZERO); diff --git a/sys/dev/fb/vesa.c b/sys/dev/fb/vesa.c index cdd836cd3d3c..4ab83c30ff4b 100644 --- a/sys/dev/fb/vesa.c +++ b/sys/dev/fb/vesa.c @@ -1581,7 +1581,7 @@ vesa_set_origin(video_adapter_t *adp, off_t offset) regs.R_DX = offset / adp->va_window_gran; x86bios_intr(®s, 0x10); - adp->va_window_orig = (offset/adp->va_window_gran)*adp->va_window_gran; + adp->va_window_orig = rounddown(offset, adp->va_window_gran); return (0); /* XXX */ } diff --git a/sys/dev/fb/vga.c b/sys/dev/fb/vga.c index d0239b3a18b8..83b969470b5e 100644 --- a/sys/dev/fb/vga.c +++ b/sys/dev/fb/vga.c @@ -1252,7 +1252,7 @@ set_line_length(video_adapter_t *adp, int pixel) break; case V_INFO_MM_PACKED: count = (pixel + 7)/8; - bpl = ((pixel + 7)/8)*8; + bpl = rounddown(pixel + 7, 8); break; case V_INFO_MM_TEXT: count = (pixel + 7)/8; /* columns */ diff --git a/sys/dev/iwn/if_iwn.c b/sys/dev/iwn/if_iwn.c index bffa8de35fb9..01f28a00e98d 100644 --- a/sys/dev/iwn/if_iwn.c +++ b/sys/dev/iwn/if_iwn.c @@ -6335,7 +6335,7 @@ iwn_set_pslevel(struct iwn_softc *sc, int dtim, int level, int async) if (max == (uint32_t)-1) max = dtim * (skip_dtim + 1); else if (max > dtim) - max = (max / dtim) * dtim; + max = rounddown(max, dtim); } else max = dtim; for (i = 0; i < 5; i++) diff --git a/sys/dev/kbd/kbd.c b/sys/dev/kbd/kbd.c index 45f483ac1a23..985a96040405 100644 --- a/sys/dev/kbd/kbd.c +++ b/sys/dev/kbd/kbd.c @@ -96,7 +96,7 @@ kbd_realloc_array(void) int s; s = spltty(); - newsize = ((keyboards + ARRAY_DELTA)/ARRAY_DELTA)*ARRAY_DELTA; + newsize = rounddown(keyboards + ARRAY_DELTA, ARRAY_DELTA); new_kbd = malloc(sizeof(*new_kbd)*newsize, M_DEVBUF, M_NOWAIT|M_ZERO); if (new_kbd == NULL) { splx(s); diff --git a/sys/dev/syscons/scmouse.c b/sys/dev/syscons/scmouse.c index 589506643622..db26787c264e 100644 --- a/sys/dev/syscons/scmouse.c +++ b/sys/dev/syscons/scmouse.c @@ -495,7 +495,7 @@ mouse_cut_start(scr_stat *scp) i = skip_spc_left(scp, scp->mouse_pos) + 1; s = spltty(); scp->mouse_cut_start = - (scp->mouse_pos / scp->xsize) * scp->xsize + i; + rounddown(scp->mouse_pos, scp->xsize) + i; scp->mouse_cut_end = (scp->mouse_pos / scp->xsize + 1) * scp->xsize - 1; splx(s); @@ -540,7 +540,7 @@ mouse_cut_word(scr_stat *scp) * unless user specified SC_CUT_SEPCHARS in his kernel config file. */ if (scp->status & MOUSE_VISIBLE) { - sol = (scp->mouse_pos / scp->xsize) * scp->xsize; + sol = rounddown(scp->mouse_pos, scp->xsize); eol = sol + scp->xsize; c = sc_vtb_getc(&scp->vtb, scp->mouse_pos); if (IS_SEP_CHAR(c)) { @@ -589,7 +589,7 @@ mouse_cut_line(scr_stat *scp) int from; if (scp->status & MOUSE_VISIBLE) { - from = (scp->mouse_pos / scp->xsize) * scp->xsize; + from = rounddown(scp->mouse_pos, scp->xsize); mouse_do_cut(scp, from, from + scp->xsize - 1); len = strlen(cut_buffer); if (cut_buffer[len - 1] == '\r') diff --git a/sys/dev/syscons/scvgarndr.c b/sys/dev/syscons/scvgarndr.c index fc7f02f58fef..2d2651746004 100644 --- a/sys/dev/syscons/scvgarndr.c +++ b/sys/dev/syscons/scvgarndr.c @@ -1035,7 +1035,7 @@ draw_pxlmouse_planar(scr_stat *scp, int x, int y) line_width = scp->sc->adp->va_line_width; xoff = (x - scp->xoff*8)%8; - yoff = y - (y/line_width)*line_width; + yoff = y - rounddown(y, line_width); ymax = imin(y + 16, scp->ypixel); outw(GDCIDX, 0x0805); /* read mode 1, write mode 0 */ diff --git a/sys/dev/vt/hw/vga/vt_vga.c b/sys/dev/vt/hw/vga/vt_vga.c index e81dcba7663a..9788b7e67265 100644 --- a/sys/dev/vt/hw/vga/vt_vga.c +++ b/sys/dev/vt/hw/vga/vt_vga.c @@ -912,7 +912,7 @@ vga_bitblt_bitmap(struct vt_device *vd, const struct vt_window *vw, uint8_t pattern_2colors; /* Align coordinates with the 8-pxels grid. */ - x1 = x / VT_VGA_PIXELS_BLOCK * VT_VGA_PIXELS_BLOCK; + x1 = rounddown(x, VT_VGA_PIXELS_BLOCK); y1 = y; x2 = roundup(x + width, VT_VGA_PIXELS_BLOCK); diff --git a/sys/dev/vt/vt_core.c b/sys/dev/vt/vt_core.c index 2884c57d0358..a90ab9f45adc 100644 --- a/sys/dev/vt/vt_core.c +++ b/sys/dev/vt/vt_core.c @@ -640,9 +640,9 @@ vt_compute_drawable_area(struct vt_window *vw) if (vt_draw_logo_cpus) vw->vw_draw_area.tr_begin.tp_row += vt_logo_sprite_height; vw->vw_draw_area.tr_end.tp_col = vw->vw_draw_area.tr_begin.tp_col + - vd->vd_width / vf->vf_width * vf->vf_width; + rounddown(vd->vd_width, vf->vf_width); vw->vw_draw_area.tr_end.tp_row = vw->vw_draw_area.tr_begin.tp_row + - height / vf->vf_height * vf->vf_height; + rounddown(height, vf->vf_height); } static void diff --git a/sys/dev/wpi/if_wpi.c b/sys/dev/wpi/if_wpi.c index 897b986eec36..acaa8212c804 100644 --- a/sys/dev/wpi/if_wpi.c +++ b/sys/dev/wpi/if_wpi.c @@ -3814,7 +3814,7 @@ wpi_set_pslevel(struct wpi_softc *sc, uint8_t dtim, int level, int async) if (max == (uint32_t)-1) max = dtim * (skip_dtim + 1); else if (max > dtim) - max = (max / dtim) * dtim; + max = rounddown(max, dtim); } else max = dtim; diff --git a/sys/fs/nandfs/nandfs_vfsops.c b/sys/fs/nandfs/nandfs_vfsops.c index 7132635efdca..97d2273d4ba8 100644 --- a/sys/fs/nandfs/nandfs_vfsops.c +++ b/sys/fs/nandfs/nandfs_vfsops.c @@ -331,8 +331,8 @@ nandfs_write_superblock_at(struct nandfs_device *fsdev, super->s_last_pseg, super->s_last_cno, super->s_last_seq, super->s_wtime, index)); - read_block = btodb(offset + ((index / sb_per_sector) * sb_per_sector) - * sizeof(struct nandfs_super_block)); + read_block = btodb(offset + rounddown(index, sb_per_sector) * + sizeof(struct nandfs_super_block)); DPRINTF(SYNC, ("%s: read_block %#x\n", __func__, read_block)); diff --git a/sys/geom/virstor/g_virstor.c b/sys/geom/virstor/g_virstor.c index 7393c10c984a..72d042d60592 100644 --- a/sys/geom/virstor/g_virstor.c +++ b/sys/geom/virstor/g_virstor.c @@ -1257,7 +1257,7 @@ virstor_check_and_run(struct g_virstor_softc *sc) bs = MIN(MAXPHYS, sc->map_size - count); if (bs % sc->sectorsize != 0) { /* Check for alignment errors */ - bs = (bs / sc->sectorsize) * sc->sectorsize; + bs = rounddown(bs, sc->sectorsize); if (bs == 0) break; LOG_MSG(LVL_ERROR, "Trouble: map is not sector-aligned " @@ -1723,13 +1723,12 @@ g_virstor_start(struct bio *b) * sc_offset will end up pointing to the drive * sector. */ s_offset = chunk_index * sizeof *me; - s_offset = (s_offset / sc->sectorsize) * - sc->sectorsize; + s_offset = rounddown(s_offset, sc->sectorsize); /* data_me points to map entry sector - * in memory (analoguos to offset) */ - data_me = &sc->map[(chunk_index / - sc->me_per_sector) * sc->me_per_sector]; + * in memory (analogous to offset) */ + data_me = &sc->map[rounddown(chunk_index, + sc->me_per_sector)]; /* Commit sector with map entry to storage */ cb->bio_to = sc->components[0].gcons->provider; diff --git a/sys/libkern/crc32.c b/sys/libkern/crc32.c index c0b464cee388..65331ce2fde3 100644 --- a/sys/libkern/crc32.c +++ b/sys/libkern/crc32.c @@ -684,7 +684,7 @@ crc32c_sb8_64_bit(uint32_t crc, uint32_t running_length; uint32_t end_bytes; - running_length = ((length - init_bytes) / 8) * 8; + running_length = rounddown(length - init_bytes, 8); end_bytes = length - init_bytes - running_length; for (li = 0; li < init_bytes; li++) diff --git a/sys/mips/atheros/ar934x_chip.c b/sys/mips/atheros/ar934x_chip.c index b5b804f000d7..f59d4aaa5285 100644 --- a/sys/mips/atheros/ar934x_chip.c +++ b/sys/mips/atheros/ar934x_chip.c @@ -437,7 +437,7 @@ ar934x_chip_gpio_output_configure(int gpio, uint8_t func) if (gpio > AR934X_GPIO_COUNT) return; - reg = AR934X_GPIO_REG_OUT_FUNC0 + 4 * (gpio / 4); + reg = AR934X_GPIO_REG_OUT_FUNC0 + rounddown(gpio, 4); s = 8 * (gpio % 4); /* read-modify-write */ diff --git a/sys/mips/atheros/qca953x_chip.c b/sys/mips/atheros/qca953x_chip.c index a262a9f8b078..88127b4ac691 100644 --- a/sys/mips/atheros/qca953x_chip.c +++ b/sys/mips/atheros/qca953x_chip.c @@ -360,7 +360,7 @@ qca953x_chip_gpio_output_configure(int gpio, uint8_t func) if (gpio > QCA953X_GPIO_COUNT) return; - reg = QCA953X_GPIO_REG_OUT_FUNC0 + 4 * (gpio / 4); + reg = QCA953X_GPIO_REG_OUT_FUNC0 + rounddown(gpio, 4); s = 8 * (gpio % 4); /* read-modify-write */ diff --git a/sys/mips/atheros/qca955x_chip.c b/sys/mips/atheros/qca955x_chip.c index b4d54fa87334..d963cc6f2b68 100644 --- a/sys/mips/atheros/qca955x_chip.c +++ b/sys/mips/atheros/qca955x_chip.c @@ -369,7 +369,7 @@ qca955x_chip_gpio_output_configure(int gpio, uint8_t func) if (gpio > QCA955X_GPIO_COUNT) return; - reg = QCA955X_GPIO_REG_OUT_FUNC0 + 4 * (gpio / 4); + reg = QCA955X_GPIO_REG_OUT_FUNC0 + rounddown(gpio, 4); s = 8 * (gpio % 4); /* read-modify-write */ diff --git a/sys/rpc/clnt_dg.c b/sys/rpc/clnt_dg.c index 36e63c674673..d9d5e41422ab 100644 --- a/sys/rpc/clnt_dg.c +++ b/sys/rpc/clnt_dg.c @@ -219,8 +219,8 @@ clnt_dg_create( /* * Should be multiple of 4 for XDR. */ - sendsz = ((sendsz + 3) / 4) * 4; - recvsz = ((recvsz + 3) / 4) * 4; + sendsz = rounddown(sendsz + 3, 4); + recvsz = rounddown(recvsz + 3, 4); cu = mem_alloc(sizeof (*cu)); cu->cu_threads = 0; cu->cu_closing = FALSE;