summaryrefslogtreecommitdiffstats
path: root/sys/kern/subr_bus.c
diff options
context:
space:
mode:
authorbde <bde@FreeBSD.org>2000-06-11 07:19:20 +0000
committerbde <bde@FreeBSD.org>2000-06-11 07:19:20 +0000
commitd6f5631720a1dee82d7e3f72f32e741d01cdac56 (patch)
treebe50720a0427d81de0e803f4bd9218730c736633 /sys/kern/subr_bus.c
parent423e9563878f579d365a6cd05d272784bd92edc4 (diff)
downloadFreeBSD-src-d6f5631720a1dee82d7e3f72f32e741d01cdac56.zip
FreeBSD-src-d6f5631720a1dee82d7e3f72f32e741d01cdac56.tar.gz
Fixed allocation of unit numbers. Allocate the amount of space actually
required (rounded up a little) instead of twice the previous amount (or a fixed amount for the first allocation). The bug caused memory corruption when a new unit number for a devclass was more than about twice the previous maximum one (or more than 3 for the first one), so it corrupted memory (which happened to be the atkbdc port resource list) in the reporter's configuration with sio unit numbers { 0, 25, 1, 2, ... }. Reviewed by: dfr Reported by: Leonid Lukiyanets <stalwar78@hotmail.com>
Diffstat (limited to 'sys/kern/subr_bus.c')
-rw-r--r--sys/kern/subr_bus.c3
1 files changed, 1 insertions, 2 deletions
diff --git a/sys/kern/subr_bus.c b/sys/kern/subr_bus.c
index ffade19..03abd48 100644
--- a/sys/kern/subr_bus.c
+++ b/sys/kern/subr_bus.c
@@ -376,8 +376,7 @@ devclass_alloc_unit(devclass_t dc, int *unitp)
device_t *newlist;
int newsize;
- newsize = (dc->maxunit ? 2 * dc->maxunit
- : MINALLOCSIZE / sizeof(device_t));
+ newsize = roundup((unit + 1), MINALLOCSIZE / sizeof(device_t));
newlist = malloc(sizeof(device_t) * newsize, M_BUS, M_NOWAIT);
if (!newlist)
return ENOMEM;
OpenPOWER on IntegriCloud