From 9cd93b3aecdc2272aaff51808129066e8e34281d Mon Sep 17 00:00:00 2001 From: Bruce Evans Date: Sun, 25 Oct 1998 19:24:04 +0000 Subject: [PATCH] Don't follow null bdevsw pointers. The `major(dev) < nblkdev' test rotted when bdevsw[] became sparse. We still depend on magic to avoid having to check that (v_rdev) device numbers in vnodes are not NODEV. Removed a redundant `major(dev) < nblkdev' test instead of updating it. Don't follow a garbage bdevsw pointer for attempts to swap on empty regular files. This case currently can't happen. Swapping on regular files is ifdefed out in swapon() and isn't attempted for empty files in nfs_mountroot(). --- sys/vm/vm_swap.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/sys/vm/vm_swap.c b/sys/vm/vm_swap.c index 10488d9a2184..bfcebdc028c9 100644 --- a/sys/vm/vm_swap.c +++ b/sys/vm/vm_swap.c @@ -31,7 +31,7 @@ * SUCH DAMAGE. * * @(#)vm_swap.c 8.5 (Berkeley) 2/17/94 - * $Id: vm_swap.c,v 1.55 1998/07/04 20:45:42 julian Exp $ + * $Id: vm_swap.c,v 1.56 1998/07/04 22:30:26 julian Exp $ */ #include "opt_devfs.h" @@ -203,8 +203,8 @@ swapon(p, uap) switch (vp->v_type) { case VBLK: - dev = (dev_t) vp->v_rdev; - if (major(dev) >= nblkdev) { + dev = vp->v_rdev; + if (major(dev) >= nblkdev || bdevsw[major(dev)] == NULL) { error = ENXIO; break; } @@ -264,14 +264,11 @@ swaponvp(p, vp, dev, nblks) } return EINVAL; found: - if (dev != NODEV && (major(dev) >= nblkdev)) - return (ENXIO); - error = VOP_OPEN(vp, FREAD | FWRITE, p->p_ucred, p); if (error) return (error); - if (nblks == 0 && (bdevsw[major(dev)]->d_psize == 0 || + if (nblks == 0 && dev != NODEV && (bdevsw[major(dev)]->d_psize == 0 || (nblks = (*bdevsw[major(dev)]->d_psize) (dev)) == -1)) { (void) VOP_CLOSE(vp, FREAD | FWRITE, p->p_ucred, p); return (ENXIO);