diff --git a/sys/kern/subr_rman.c b/sys/kern/subr_rman.c index a76dbf020ee3..07d056c52845 100644 --- a/sys/kern/subr_rman.c +++ b/sys/kern/subr_rman.c @@ -449,6 +449,8 @@ rman_reserve_resource_bound(struct rman *rm, rman_res_t start, rman_res_t end, "length %#jx, flags %x, device %s\n", rm->rm_descr, start, end, count, flags, dev == NULL ? "" : device_get_nameunit(dev))); + KASSERT(count != 0, ("%s: attempted to allocate an empty range", + __func__)); KASSERT((flags & RF_FIRSTSHARE) == 0, ("invalid flags %#x", flags)); new_rflags = (flags & ~RF_FIRSTSHARE) | RF_ALLOCATED; @@ -524,7 +526,7 @@ rman_reserve_resource_bound(struct rman *rm, rman_res_t start, rman_res_t end, DPRINTF(("truncated region: [%#jx, %#jx]; size %#jx (requested %#jx)\n", rstart, rend, (rend - rstart + 1), count)); - if ((rend - rstart + 1) >= count) { + if ((rend - rstart) >= (count - 1)) { DPRINTF(("candidate region: [%#jx, %#jx], size %#jx\n", rstart, rend, (rend - rstart + 1))); if ((s->r_end - s->r_start + 1) == count) {