summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpfg <pfg@FreeBSD.org>2016-04-26 15:38:17 +0000
committerpfg <pfg@FreeBSD.org>2016-04-26 15:38:17 +0000
commitfc01419148d065603607b1008d536431465f3bc3 (patch)
tree1bff72784c0591a61e4e16e97fae48d0614891dc
parent3a3f015eb3ae533a46cf30b5262d15cb4b5db097 (diff)
downloadFreeBSD-src-fc01419148d065603607b1008d536431465f3bc3.zip
FreeBSD-src-fc01419148d065603607b1008d536431465f3bc3.tar.gz
sys: extend use of the howmany() macro when available.
We have a howmany() macro in the <sys/param.h> header that is convenient to re-use as it makes things easier to read.
-rw-r--r--sys/cam/ata/ata_da.c11
-rw-r--r--sys/cam/scsi/scsi_da.c2
-rw-r--r--sys/compat/ndis/subr_ntoskrnl.c2
-rw-r--r--sys/fs/msdosfs/msdosfs_vfsops.c5
-rw-r--r--sys/geom/part/g_part_gpt.c17
-rw-r--r--sys/geom/part/g_part_ldm.c3
-rw-r--r--sys/geom/raid/md_ddf.c62
-rw-r--r--sys/geom/raid/md_intel.c2
-rw-r--r--sys/geom/uzip/g_uzip.c7
-rw-r--r--sys/kern/kern_clock.c5
-rw-r--r--sys/kern/kern_synch.c2
-rw-r--r--sys/kern/kern_time.c2
-rw-r--r--sys/kern/kern_timeout.c6
-rw-r--r--sys/kern/subr_pctrie.c2
-rw-r--r--sys/kern/sys_pipe.c2
-rw-r--r--sys/kern/sysv_msg.c2
-rw-r--r--sys/kern/uipc_shm.c2
-rw-r--r--sys/kern/vfs_subr.c2
-rw-r--r--sys/kgssapi/krb5/kcrypto.c3
-rw-r--r--sys/net/if_arcsubr.c2
-rw-r--r--sys/netgraph/ng_pptpgre.c4
21 files changed, 68 insertions, 77 deletions
diff --git a/sys/cam/ata/ata_da.c b/sys/cam/ata/ata_da.c
index 535258e..76b87f1 100644
--- a/sys/cam/ata/ata_da.c
+++ b/sys/cam/ata/ata_da.c
@@ -1699,12 +1699,10 @@ ada_dsmtrim(struct ada_softc *softc, struct bio *bp, struct ccb_ataio *ataio)
CAM_DIR_OUT,
0,
req->data,
- ((ranges + ATA_DSM_BLK_RANGES - 1) /
- ATA_DSM_BLK_RANGES) * ATA_DSM_BLK_SIZE,
+ howmany(ranges, ATA_DSM_BLK_RANGES) * ATA_DSM_BLK_SIZE,
ada_default_timeout * 1000);
ata_48bit_cmd(ataio, ATA_DATA_SET_MANAGEMENT,
- ATA_DSM_TRIM, 0, (ranges + ATA_DSM_BLK_RANGES -
- 1) / ATA_DSM_BLK_RANGES);
+ ATA_DSM_TRIM, 0, howmany(ranges, ATA_DSM_BLK_RANGES));
}
static void
@@ -1720,13 +1718,12 @@ ada_ncq_dsmtrim(struct ada_softc *softc, struct bio *bp, struct ccb_ataio *ataio
CAM_DIR_OUT,
0,
req->data,
- ((ranges + ATA_DSM_BLK_RANGES - 1) /
- ATA_DSM_BLK_RANGES) * ATA_DSM_BLK_SIZE,
+ howmany(ranges, ATA_DSM_BLK_RANGES) * ATA_DSM_BLK_SIZE,
ada_default_timeout * 1000);
ata_ncq_cmd(ataio,
ATA_SEND_FPDMA_QUEUED,
0,
- (ranges + ATA_DSM_BLK_RANGES - 1) / ATA_DSM_BLK_RANGES);
+ howmany(ranges, ATA_DSM_BLK_RANGES));
ataio->cmd.sector_count_exp = ATA_SFPDMA_DSM;
ataio->ata_flags |= ATA_FLAG_AUX;
ataio->aux = 1;
diff --git a/sys/cam/scsi/scsi_da.c b/sys/cam/scsi/scsi_da.c
index 5652c67..2157676 100644
--- a/sys/cam/scsi/scsi_da.c
+++ b/sys/cam/scsi/scsi_da.c
@@ -2868,7 +2868,7 @@ da_delete_trim(struct cam_periph *periph, union ccb *ccb, struct bio *bp)
}
} while (1);
- block_count = (ranges + ATA_DSM_BLK_RANGES - 1) / ATA_DSM_BLK_RANGES;
+ block_count = howmany(ranges, ATA_DSM_BLK_RANGES);
scsi_ata_trim(&ccb->csio,
/*retries*/da_retry_count,
/*cbfcnp*/dadone,
diff --git a/sys/compat/ndis/subr_ntoskrnl.c b/sys/compat/ndis/subr_ntoskrnl.c
index 95670ba..f6d5ac4 100644
--- a/sys/compat/ndis/subr_ntoskrnl.c
+++ b/sys/compat/ndis/subr_ntoskrnl.c
@@ -4207,7 +4207,7 @@ KeQueryInterruptTime(void)
ticks = tvtohz(&tv);
- return ticks * ((10000000 + hz - 1) / hz);
+ return ticks * howmany(10000000, hz);
}
static struct thread *
diff --git a/sys/fs/msdosfs/msdosfs_vfsops.c b/sys/fs/msdosfs/msdosfs_vfsops.c
index 7c6d3ed..d4b6a02 100644
--- a/sys/fs/msdosfs/msdosfs_vfsops.c
+++ b/sys/fs/msdosfs/msdosfs_vfsops.c
@@ -606,9 +606,8 @@ mountmsdosfs(struct vnode *devvp, struct mount *mp)
} else {
pmp->pm_rootdirblk = pmp->pm_fatblk +
(pmp->pm_FATs * pmp->pm_FATsecs);
- pmp->pm_rootdirsize = (pmp->pm_RootDirEnts * sizeof(struct direntry)
- + DEV_BSIZE - 1)
- / DEV_BSIZE; /* in blocks */
+ pmp->pm_rootdirsize = howmany(pmp->pm_RootDirEnts *
+ sizeof(struct direntry), DEV_BSIZE); /* in blocks */
pmp->pm_firstcluster = pmp->pm_rootdirblk + pmp->pm_rootdirsize;
}
diff --git a/sys/geom/part/g_part_gpt.c b/sys/geom/part/g_part_gpt.c
index 465bb5e..f9017ab 100644
--- a/sys/geom/part/g_part_gpt.c
+++ b/sys/geom/part/g_part_gpt.c
@@ -472,8 +472,7 @@ gpt_read_hdr(struct g_part_gpt_table *table, struct g_consumer *cp,
hdr->hdr_lba_table <= hdr->hdr_lba_end)
goto fail;
lba = hdr->hdr_lba_table +
- (hdr->hdr_entries * hdr->hdr_entsz + pp->sectorsize - 1) /
- pp->sectorsize - 1;
+ howmany(hdr->hdr_entries * hdr->hdr_entsz, pp->sectorsize) - 1;
if (lba >= last)
goto fail;
if (lba >= hdr->hdr_lba_start && lba <= hdr->hdr_lba_end)
@@ -515,7 +514,7 @@ gpt_read_tbl(struct g_part_gpt_table *table, struct g_consumer *cp,
table->state[elt] = GPT_STATE_MISSING;
tblsz = hdr->hdr_entries * hdr->hdr_entsz;
- sectors = (tblsz + pp->sectorsize - 1) / pp->sectorsize;
+ sectors = howmany(tblsz, pp->sectorsize);
buf = g_malloc(sectors * pp->sectorsize, M_WAITOK | M_ZERO);
for (idx = 0; idx < sectors; idx += MAXPHYS / pp->sectorsize) {
size = (sectors - idx > MAXPHYS / pp->sectorsize) ? MAXPHYS:
@@ -653,8 +652,8 @@ g_part_gpt_create(struct g_part_table *basetable, struct g_part_parms *gpp)
table = (struct g_part_gpt_table *)basetable;
pp = gpp->gpp_provider;
- tblsz = (basetable->gpt_entries * sizeof(struct gpt_ent) +
- pp->sectorsize - 1) / pp->sectorsize;
+ tblsz = howmany(basetable->gpt_entries * sizeof(struct gpt_ent),
+ pp->sectorsize);
if (pp->sectorsize < MBRSIZE ||
pp->mediasize < (3 + 2 * tblsz + basetable->gpt_entries) *
pp->sectorsize)
@@ -1134,8 +1133,8 @@ g_part_gpt_write(struct g_part_table *basetable, struct g_consumer *cp)
pp = cp->provider;
table = (struct g_part_gpt_table *)basetable;
- tblsz = (table->hdr->hdr_entries * table->hdr->hdr_entsz +
- pp->sectorsize - 1) / pp->sectorsize;
+ tblsz = howmany(table->hdr->hdr_entries * table->hdr->hdr_entsz,
+ pp->sectorsize);
/* Reconstruct the MBR from the GPT if under Boot Camp. */
if (table->bootcamp)
@@ -1239,8 +1238,8 @@ g_gpt_set_defaults(struct g_part_table *basetable, struct g_provider *pp)
table = (struct g_part_gpt_table *)basetable;
last = pp->mediasize / pp->sectorsize - 1;
- tblsz = (basetable->gpt_entries * sizeof(struct gpt_ent) +
- pp->sectorsize - 1) / pp->sectorsize;
+ tblsz = howmany(basetable->gpt_entries * sizeof(struct gpt_ent),
+ pp->sectorsize);
table->lba[GPT_ELT_PRIHDR] = 1;
table->lba[GPT_ELT_PRITBL] = 2;
diff --git a/sys/geom/part/g_part_ldm.c b/sys/geom/part/g_part_ldm.c
index 374a77a..33555ce 100644
--- a/sys/geom/part/g_part_ldm.c
+++ b/sys/geom/part/g_part_ldm.c
@@ -1013,8 +1013,7 @@ ldm_vmdb_parse(struct ldm_db *db, struct g_consumer *cp)
int error;
pp = cp->provider;
- size = (db->dh.last_seq * db->dh.size +
- pp->sectorsize - 1) / pp->sectorsize;
+ size = howmany(db->dh.last_seq * db->dh.size, pp->sectorsize);
size -= 1; /* one sector takes vmdb header */
for (n = 0; n < size; n += MAXPHYS / pp->sectorsize) {
offset = db->ph.db_offset + db->th.conf_offset + n + 1;
diff --git a/sys/geom/raid/md_ddf.c b/sys/geom/raid/md_ddf.c
index eed048d..686bd4d 100644
--- a/sys/geom/raid/md_ddf.c
+++ b/sys/geom/raid/md_ddf.c
@@ -593,35 +593,36 @@ ddf_meta_create(struct g_raid_disk *disk, struct ddf_meta *sample)
memcpy(meta->hdr, sample->hdr, sizeof(struct ddf_header));
if (ss != sample->sectorsize) {
SET32(meta, hdr->WorkSpace_Length,
- (GET32(sample, hdr->WorkSpace_Length) *
- sample->sectorsize + ss - 1) / ss);
+ howmany(GET32(sample, hdr->WorkSpace_Length) *
+ sample->sectorsize, ss));
SET16(meta, hdr->Configuration_Record_Length,
- (GET16(sample, hdr->Configuration_Record_Length) *
- sample->sectorsize + ss - 1) / ss);
+ howmany(GET16(sample,
+ hdr->Configuration_Record_Length) *
+ sample->sectorsize, ss));
SET32(meta, hdr->cd_length,
- (GET32(sample, hdr->cd_length) *
- sample->sectorsize + ss - 1) / ss);
+ howmany(GET32(sample, hdr->cd_length) *
+ sample->sectorsize, ss));
SET32(meta, hdr->pdr_length,
- (GET32(sample, hdr->pdr_length) *
- sample->sectorsize + ss - 1) / ss);
+ howmany(GET32(sample, hdr->pdr_length) *
+ sample->sectorsize, ss));
SET32(meta, hdr->vdr_length,
- (GET32(sample, hdr->vdr_length) *
- sample->sectorsize + ss - 1) / ss);
+ howmany(GET32(sample, hdr->vdr_length) *
+ sample->sectorsize, ss));
SET32(meta, hdr->cr_length,
- (GET32(sample, hdr->cr_length) *
- sample->sectorsize + ss - 1) / ss);
+ howmany(GET32(sample, hdr->cr_length) *
+ sample->sectorsize, ss));
SET32(meta, hdr->pdd_length,
- (GET32(sample, hdr->pdd_length) *
- sample->sectorsize + ss - 1) / ss);
+ howmany(GET32(sample, hdr->pdd_length) *
+ sample->sectorsize, ss));
SET32(meta, hdr->bbmlog_length,
- (GET32(sample, hdr->bbmlog_length) *
- sample->sectorsize + ss - 1) / ss);
+ howmany(GET32(sample, hdr->bbmlog_length) *
+ sample->sectorsize, ss));
SET32(meta, hdr->Diagnostic_Space,
- (GET32(sample, hdr->bbmlog_length) *
- sample->sectorsize + ss - 1) / ss);
+ howmany(GET32(sample, hdr->bbmlog_length) *
+ sample->sectorsize, ss));
SET32(meta, hdr->Vendor_Specific_Logs,
- (GET32(sample, hdr->bbmlog_length) *
- sample->sectorsize + ss - 1) / ss);
+ howmany(GET32(sample, hdr->bbmlog_length) *
+ sample->sectorsize, ss));
}
} else {
SET32(meta, hdr->Signature, DDF_HEADER_SIGNATURE);
@@ -635,24 +636,23 @@ ddf_meta_create(struct g_raid_disk *disk, struct ddf_meta *sample)
SET16(meta, hdr->Max_Partitions, DDF_MAX_PARTITIONS);
SET16(meta, hdr->Max_Primary_Element_Entries, DDF_MAX_DISKS);
SET16(meta, hdr->Configuration_Record_Length,
- (sizeof(struct ddf_vdc_record) +
- (4 + 8) * GET16(meta, hdr->Max_Primary_Element_Entries) +
- ss - 1) / ss);
+ howmany(sizeof(struct ddf_vdc_record) + (4 + 8) *
+ GET16(meta, hdr->Max_Primary_Element_Entries), ss));
SET32(meta, hdr->cd_length,
- (sizeof(struct ddf_cd_record) + ss - 1) / ss);
+ howmany(sizeof(struct ddf_cd_record), ss));
SET32(meta, hdr->pdr_length,
- (sizeof(struct ddf_pd_record) +
- sizeof(struct ddf_pd_entry) *
- GET16(meta, hdr->Max_PD_Entries) + ss - 1) / ss);
+ howmany(sizeof(struct ddf_pd_record) +
+ sizeof(struct ddf_pd_entry) * GET16(meta,
+ hdr->Max_PD_Entries), ss));
SET32(meta, hdr->vdr_length,
- (sizeof(struct ddf_vd_record) +
- sizeof(struct ddf_vd_entry) *
- GET16(meta, hdr->Max_VD_Entries) + ss - 1) / ss);
+ howmany(sizeof(struct ddf_vd_record) +
+ sizeof(struct ddf_vd_entry) *
+ GET16(meta, hdr->Max_VD_Entries), ss));
SET32(meta, hdr->cr_length,
GET16(meta, hdr->Configuration_Record_Length) *
(GET16(meta, hdr->Max_Partitions) + 1));
SET32(meta, hdr->pdd_length,
- (sizeof(struct ddf_pdd_record) + ss - 1) / ss);
+ howmany(sizeof(struct ddf_pdd_record), ss));
SET32(meta, hdr->bbmlog_length, 0);
SET32(meta, hdr->Diagnostic_Space_Length, 0);
SET32(meta, hdr->Vendor_Specific_Logs_Length, 0);
diff --git a/sys/geom/raid/md_intel.c b/sys/geom/raid/md_intel.c
index 6d12602..11c561c 100644
--- a/sys/geom/raid/md_intel.c
+++ b/sys/geom/raid/md_intel.c
@@ -773,7 +773,7 @@ intel_meta_write(struct g_consumer *cp, struct intel_raid_conf *meta)
meta->checksum = checksum;
/* Create and fill buffer. */
- sectors = (meta->config_size + pp->sectorsize - 1) / pp->sectorsize;
+ sectors = howmany(meta->config_size, pp->sectorsize);
buf = malloc(sectors * pp->sectorsize, M_MD_INTEL, M_WAITOK | M_ZERO);
if (sectors > 1) {
memcpy(buf, ((char *)meta) + pp->sectorsize,
diff --git a/sys/geom/uzip/g_uzip.c b/sys/geom/uzip/g_uzip.c
index 768a454..bbb31e4 100644
--- a/sys/geom/uzip/g_uzip.c
+++ b/sys/geom/uzip/g_uzip.c
@@ -195,9 +195,8 @@ g_uzip_cached(struct g_geom *gp, struct bio *bp)
#define TOFF_2_BOFF(sc, pp, bi) ((sc)->toc[(bi)].offset - \
(sc)->toc[(bi)].offset % (pp)->sectorsize)
-#define TLEN_2_BLEN(sc, pp, bp, ei) ((BLK_ENDS((sc), (ei)) - \
- (bp)->bio_offset + (pp)->sectorsize - 1) / \
- (pp)->sectorsize * (pp)->sectorsize)
+#define TLEN_2_BLEN(sc, pp, bp, ei) roundup(BLK_ENDS((sc), (ei)) - \
+ (bp)->bio_offset, (pp)->sectorsize)
static int
g_uzip_request(struct g_geom *gp, struct bio *bp)
@@ -220,7 +219,7 @@ g_uzip_request(struct g_geom *gp, struct bio *bp)
ofs = bp->bio_offset + bp->bio_completed;
start_blk = ofs / sc->blksz;
KASSERT(start_blk < sc->nblocks, ("start_blk out of range"));
- end_blk = (ofs + bp->bio_resid + sc->blksz - 1) / sc->blksz;
+ end_blk = howmany(ofs + bp->bio_resid, sc->blksz);
KASSERT(end_blk <= sc->nblocks, ("end_blk out of range"));
for (; BLK_IS_NIL(sc, start_blk) && start_blk < end_blk; start_blk++) {
diff --git a/sys/kern/kern_clock.c b/sys/kern/kern_clock.c
index 9312a24..1f4b129 100644
--- a/sys/kern/kern_clock.c
+++ b/sys/kern/kern_clock.c
@@ -625,11 +625,10 @@ tvtohz(tv)
#endif
ticks = 1;
} else if (sec <= LONG_MAX / 1000000)
- ticks = (sec * 1000000 + (unsigned long)usec + (tick - 1))
- / tick + 1;
+ ticks = howmany(sec * 1000000 + (unsigned long)usec, tick) + 1;
else if (sec <= LONG_MAX / hz)
ticks = sec * hz
- + ((unsigned long)usec + (tick - 1)) / tick + 1;
+ + howmany((unsigned long)usec, tick) + 1;
else
ticks = LONG_MAX;
if (ticks > INT_MAX)
diff --git a/sys/kern/kern_synch.c b/sys/kern/kern_synch.c
index c9932f56..b90caab 100644
--- a/sys/kern/kern_synch.c
+++ b/sys/kern/kern_synch.c
@@ -337,7 +337,7 @@ pause_sbt(const char *wmesg, sbintime_t sbt, sbintime_t pr, int flags)
sbt -= SBT_1S;
}
/* Do the delay remainder, if any */
- sbt = (sbt + SBT_1US - 1) / SBT_1US;
+ sbt = howmany(sbt, SBT_1US);
if (sbt > 0)
DELAY(sbt);
return (0);
diff --git a/sys/kern/kern_time.c b/sys/kern/kern_time.c
index 7705d9c..148da2b 100644
--- a/sys/kern/kern_time.c
+++ b/sys/kern/kern_time.c
@@ -453,7 +453,7 @@ kern_clock_getres(struct thread *td, clockid_t clock_id, struct timespec *ts)
case CLOCK_VIRTUAL:
case CLOCK_PROF:
/* Accurately round up here because we can do so cheaply. */
- ts->tv_nsec = (1000000000 + hz - 1) / hz;
+ ts->tv_nsec = howmany(1000000000, hz);
break;
case CLOCK_SECOND:
ts->tv_sec = 1;
diff --git a/sys/kern/kern_timeout.c b/sys/kern/kern_timeout.c
index b13a63f..c5ac4c1 100644
--- a/sys/kern/kern_timeout.c
+++ b/sys/kern/kern_timeout.c
@@ -1464,11 +1464,11 @@ adjust_timeout_calltodo(struct timeval *time_change)
if (time_change->tv_sec < 0)
return;
else if (time_change->tv_sec <= LONG_MAX / 1000000)
- delta_ticks = (time_change->tv_sec * 1000000 +
- time_change->tv_usec + (tick - 1)) / tick + 1;
+ delta_ticks = howmany(time_change->tv_sec * 1000000 +
+ time_change->tv_usec, tick) + 1;
else if (time_change->tv_sec <= LONG_MAX / hz)
delta_ticks = time_change->tv_sec * hz +
- (time_change->tv_usec + (tick - 1)) / tick + 1;
+ howmany(time_change->tv_usec, tick) + 1;
else
delta_ticks = LONG_MAX;
diff --git a/sys/kern/subr_pctrie.c b/sys/kern/subr_pctrie.c
index 2bbd16d..b538f5d 100644
--- a/sys/kern/subr_pctrie.c
+++ b/sys/kern/subr_pctrie.c
@@ -71,7 +71,7 @@ __FBSDID("$FreeBSD$");
#define PCTRIE_COUNT (1 << PCTRIE_WIDTH)
#define PCTRIE_MASK (PCTRIE_COUNT - 1)
-#define PCTRIE_LIMIT (howmany((sizeof(uint64_t) * NBBY), PCTRIE_WIDTH) - 1)
+#define PCTRIE_LIMIT (howmany(sizeof(uint64_t) * NBBY, PCTRIE_WIDTH) - 1)
/* Flag bits stored in node pointers. */
#define PCTRIE_ISLEAF 0x1
diff --git a/sys/kern/sys_pipe.c b/sys/kern/sys_pipe.c
index a81c9de..2032b38 100644
--- a/sys/kern/sys_pipe.c
+++ b/sys/kern/sys_pipe.c
@@ -1542,7 +1542,7 @@ pipe_stat(fp, ub, active_cred, td)
ub->st_size = pipe->pipe_map.cnt;
else
ub->st_size = pipe->pipe_buffer.cnt;
- ub->st_blocks = (ub->st_size + ub->st_blksize - 1) / ub->st_blksize;
+ ub->st_blocks = howmany(ub->st_size, ub->st_blksize);
ub->st_atim = pipe->pipe_atime;
ub->st_mtim = pipe->pipe_mtime;
ub->st_ctim = pipe->pipe_ctime;
diff --git a/sys/kern/sysv_msg.c b/sys/kern/sysv_msg.c
index a44afb2..b31dd41 100644
--- a/sys/kern/sysv_msg.c
+++ b/sys/kern/sysv_msg.c
@@ -842,7 +842,7 @@ kern_msgsnd(td, msqid, msgp, msgsz, msgflg, mtype)
}
#endif
- segs_needed = (msgsz + msginfo.msgssz - 1) / msginfo.msgssz;
+ segs_needed = howmany(msgsz, msginfo.msgssz);
DPRINTF(("msgsz=%zu, msgssz=%d, segs_needed=%d\n", msgsz,
msginfo.msgssz, segs_needed));
for (;;) {
diff --git a/sys/kern/uipc_shm.c b/sys/kern/uipc_shm.c
index 0657787..4503139 100644
--- a/sys/kern/uipc_shm.c
+++ b/sys/kern/uipc_shm.c
@@ -380,7 +380,7 @@ shm_stat(struct file *fp, struct stat *sb, struct ucred *active_cred,
bzero(sb, sizeof(*sb));
sb->st_blksize = PAGE_SIZE;
sb->st_size = shmfd->shm_size;
- sb->st_blocks = (sb->st_size + sb->st_blksize - 1) / sb->st_blksize;
+ sb->st_blocks = howmany(sb->st_size, sb->st_blksize);
mtx_lock(&shm_timestamp_lock);
sb->st_atim = shmfd->shm_atime;
sb->st_ctim = shmfd->shm_ctime;
diff --git a/sys/kern/vfs_subr.c b/sys/kern/vfs_subr.c
index 245adbc..36b9c2a 100644
--- a/sys/kern/vfs_subr.c
+++ b/sys/kern/vfs_subr.c
@@ -1745,7 +1745,7 @@ vtruncbuf(struct vnode *vp, struct ucred *cred, off_t length, int blksize)
/*
* Round up to the *next* lbn.
*/
- trunclbn = (length + blksize - 1) / blksize;
+ trunclbn = howmany(length, blksize);
ASSERT_VOP_LOCKED(vp, "vtruncbuf");
restart:
diff --git a/sys/kgssapi/krb5/kcrypto.c b/sys/kgssapi/krb5/kcrypto.c
index 27ee3ec..84c5b49 100644
--- a/sys/kgssapi/krb5/kcrypto.c
+++ b/sys/kgssapi/krb5/kcrypto.c
@@ -202,8 +202,7 @@ krb5_derive_key(struct krb5_key_state *inkey,
* Generate enough bytes for keybits rounded up to a multiple
* of blocklen.
*/
- randomlen = ((ec->ec_keybits/8 + ec->ec_blocklen - 1) / ec->ec_blocklen)
- * ec->ec_blocklen;
+ randomlen = roundup(ec->ec_keybits / 8, ec->ec_blocklen);
bytes = malloc(randomlen, M_GSSAPI, M_WAITOK);
MGET(m, M_WAITOK, MT_DATA);
m->m_len = ec->ec_blocklen;
diff --git a/sys/net/if_arcsubr.c b/sys/net/if_arcsubr.c
index 14026b4..271e652 100644
--- a/sys/net/if_arcsubr.c
+++ b/sys/net/if_arcsubr.c
@@ -274,7 +274,7 @@ arc_frag_next(struct ifnet *ifp)
return m;
++ac->ac_seqid; /* make the seqid unique */
- tfrags = (m->m_pkthdr.len + ARC_MAX_DATA - 1) / ARC_MAX_DATA;
+ tfrags = howmany(m->m_pkthdr.len, ARC_MAX_DATA);
ac->fsflag = 2 * tfrags - 3;
ac->sflag = 0;
ac->rsflag = ac->fsflag;
diff --git a/sys/netgraph/ng_pptpgre.c b/sys/netgraph/ng_pptpgre.c
index 83d3e0a..6dc5b2d 100644
--- a/sys/netgraph/ng_pptpgre.c
+++ b/sys/netgraph/ng_pptpgre.c
@@ -846,7 +846,7 @@ ng_pptpgre_start_recv_ack_timer(hpriv_p hpriv)
remain = 0;
/* Be conservative: timeout can happen up to 1 tick early */
- ticks = (((remain * hz) + PPTP_TIME_SCALE - 1) / PPTP_TIME_SCALE) + 1;
+ ticks = howmany(remain * hz, PPTP_TIME_SCALE) + 1;
ng_callout(&hpriv->rackTimer, hpriv->node, hpriv->hook,
ticks, ng_pptpgre_recv_ack_timeout, hpriv, 0);
}
@@ -894,7 +894,7 @@ ng_pptpgre_start_send_ack_timer(hpriv_p hpriv)
ackTimeout = PPTP_MAX_ACK_DELAY;
/* Be conservative: timeout can happen up to 1 tick early */
- ticks = (((ackTimeout * hz) + PPTP_TIME_SCALE - 1) / PPTP_TIME_SCALE);
+ ticks = howmany(ackTimeout * hz, PPTP_TIME_SCALE);
ng_callout(&hpriv->sackTimer, hpriv->node, hpriv->hook,
ticks, ng_pptpgre_send_ack_timeout, hpriv, 0);
}
OpenPOWER on IntegriCloud