1
0
mirror of https://git.FreeBSD.org/src.git synced 2024-12-14 10:09:48 +00:00

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().
This commit is contained in:
Bruce Evans 1998-10-25 19:24:04 +00:00
parent 9c0619dace
commit 9cd93b3aec
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=40650

View File

@ -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);