summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--sys/compat/common/vfs_syscalls_43.c10
-rw-r--r--sys/compat/freebsd/freebsd_file.c13
-rw-r--r--sys/compat/hpux/hpux_compat.c10
-rw-r--r--sys/compat/hpux/hpux_tty.c9
-rw-r--r--sys/compat/ibcs2/ibcs2_fcntl.c4
-rw-r--r--sys/compat/linux/linux_blkio.c4
-rw-r--r--sys/compat/linux/linux_fdio.c4
-rw-r--r--sys/compat/linux/linux_file.c9
-rw-r--r--sys/compat/linux/linux_hdio.c10
-rw-r--r--sys/compat/netbsd/netbsd_stat.c4
-rw-r--r--sys/compat/osf1/osf1_descrip.c4
-rw-r--r--sys/compat/sunos/sunos_misc.c4
-rw-r--r--sys/compat/svr4/svr4_fcntl.c19
-rw-r--r--sys/compat/svr4/svr4_ioctl.c14
-rw-r--r--sys/compat/svr4/svr4_stream.c8
-rw-r--r--sys/compat/ultrix/ultrix_pathname.c4
-rw-r--r--sys/kern/kern_descrip.c50
-rw-r--r--sys/kern/sys_generic.c25
-rw-r--r--sys/miscfs/fdesc/fdesc_vnops.c4
19 files changed, 139 insertions, 70 deletions
diff --git a/sys/compat/common/vfs_syscalls_43.c b/sys/compat/common/vfs_syscalls_43.c
index e9ccc4c1e83..4f4be76bb5c 100644
--- a/sys/compat/common/vfs_syscalls_43.c
+++ b/sys/compat/common/vfs_syscalls_43.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: vfs_syscalls_43.c,v 1.17 2002/02/12 18:41:20 art Exp $ */
+/* $OpenBSD: vfs_syscalls_43.c,v 1.18 2002/02/13 19:08:06 art Exp $ */
/* $NetBSD: vfs_syscalls_43.c,v 1.4 1996/03/14 19:31:52 christos Exp $ */
/*
@@ -185,20 +185,22 @@ compat_43_sys_fstat(p, v, retval)
void *v;
register_t *retval;
{
- register struct compat_43_sys_fstat_args /* {
+ struct compat_43_sys_fstat_args /* {
syscallarg(int) fd;
syscallarg(struct ostat *) sb;
} */ *uap = v;
int fd = SCARG(uap, fd);
- register struct filedesc *fdp = p->p_fd;
- register struct file *fp;
+ struct filedesc *fdp = p->p_fd;
+ struct file *fp;
struct stat ub;
struct ostat oub;
int error;
if ((fp = fd_getfile(fdp, fd)) == NULL)
return (EBADF);
+ FREF(fp);
error = (*fp->f_ops->fo_stat)(fp, &ub, p);
+ FRELE(fp);
cvtstat(&ub, &oub);
if (error == 0)
error = copyout((caddr_t)&oub, (caddr_t)SCARG(uap, sb),
diff --git a/sys/compat/freebsd/freebsd_file.c b/sys/compat/freebsd/freebsd_file.c
index 483dc4d94ba..e32bfa00755 100644
--- a/sys/compat/freebsd/freebsd_file.c
+++ b/sys/compat/freebsd/freebsd_file.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: freebsd_file.c,v 1.12 2002/02/12 18:41:20 art Exp $ */
+/* $OpenBSD: freebsd_file.c,v 1.13 2002/02/13 19:08:06 art Exp $ */
/* $NetBSD: freebsd_file.c,v 1.3 1996/05/03 17:03:09 christos Exp $ */
/*
@@ -799,7 +799,7 @@ freebsd_sys_fcntl(p, v, retval)
syscallarg(int) cmd;
syscallarg(void *) arg;
} */ *uap = v;
- int fd, cmd;
+ int fd, cmd, error;
struct filedesc *fdp;
struct file *fp;
@@ -813,10 +813,13 @@ freebsd_sys_fcntl(p, v, retval)
fdp = p->p_fd;
if ((fp = fd_getfile(fdp, fd)) == NULL)
return (EBADF);
- if (fp->f_type == DTYPE_PIPE)
- return ((*fp->f_ops->fo_ioctl)(fp,
+ if (fp->f_type == DTYPE_PIPE) {
+ FREF(fp);
+ error = (*fp->f_ops->fo_ioctl)(fp,
cmd == F_GETOWN ? SIOCGPGRP : SIOCSPGRP,
- (caddr_t)&SCARG(uap, arg), p));
+ (caddr_t)&SCARG(uap, arg), p);
+ FRELE(fp);
+ }
break;
}
diff --git a/sys/compat/hpux/hpux_compat.c b/sys/compat/hpux/hpux_compat.c
index 2de912da51c..38ea2345357 100644
--- a/sys/compat/hpux/hpux_compat.c
+++ b/sys/compat/hpux/hpux_compat.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: hpux_compat.c,v 1.15 2001/11/05 19:47:03 art Exp $ */
+/* $OpenBSD: hpux_compat.c,v 1.16 2002/02/13 19:08:06 art Exp $ */
/* $NetBSD: hpux_compat.c,v 1.35 1997/05/08 16:19:48 mycroft Exp $ */
/*
@@ -839,6 +839,7 @@ hpux_sys_ioctl(p, v, retval)
size = IOCPARM_LEN(com);
if (size > IOCPARM_MAX)
return (ENOTTY);
+ FREF(fp);
if (size > sizeof (stkbuf)) {
memp = (caddr_t)malloc((u_long)size, M_IOCTLOPS, M_WAITOK);
dt = memp;
@@ -847,9 +848,7 @@ hpux_sys_ioctl(p, v, retval)
if (size) {
error = copyin(SCARG(uap, data), dt, (u_int)size);
if (error) {
- if (memp)
- free(memp, M_IOCTLOPS);
- return (error);
+ goto out;
}
} else
*(caddr_t *)dt = SCARG(uap, data);
@@ -937,6 +936,9 @@ hpux_sys_ioctl(p, v, retval)
*/
if (error == 0 && (com&IOC_OUT) && size)
error = copyout(dt, SCARG(uap, data), (u_int)size);
+
+out:
+ FRELE(fp);
if (memp)
free(memp, M_IOCTLOPS);
return (error);
diff --git a/sys/compat/hpux/hpux_tty.c b/sys/compat/hpux/hpux_tty.c
index e87ebb6298d..2bff4d874e6 100644
--- a/sys/compat/hpux/hpux_tty.c
+++ b/sys/compat/hpux/hpux_tty.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: hpux_tty.c,v 1.6 2002/02/02 16:05:58 art Exp $ */
+/* $OpenBSD: hpux_tty.c,v 1.7 2002/02/13 19:08:06 art Exp $ */
/* $NetBSD: hpux_tty.c,v 1.14 1997/04/01 19:59:05 scottr Exp $ */
/*
@@ -85,6 +85,7 @@ hpux_termio(fd, com, data, p)
if ((fp = fd_getfile(p->p_fd, fd)) == NULL)
return (EBADF);
+ FREF(fp);
ioctlrout = fp->f_ops->fo_ioctl;
switch (com) {
case HPUXTCGETATTR:
@@ -377,6 +378,7 @@ hpux_termio(fd, com, data, p)
error = EINVAL;
break;
}
+ FRELE(fp);
return(error);
}
@@ -522,9 +524,10 @@ getsettty(p, fdes, com, cmarg)
return (EBADF);
if ((fp->f_flag & (FREAD|FWRITE)) == 0)
return (EBADF);
+ FREF(fp);
if (com == HPUXTIOCSETP) {
if ((error = copyin(cmarg, (caddr_t)&hsb, sizeof hsb)))
- return (error);
+ goto bad;
sb.sg_ispeed = hsb.sg_ispeed;
sb.sg_ospeed = hsb.sg_ospeed;
sb.sg_erase = hsb.sg_erase;
@@ -551,5 +554,7 @@ getsettty(p, fdes, com, cmarg)
hsb.sg_flags |= V7_XTABS;
error = copyout((caddr_t)&hsb, cmarg, sizeof hsb);
}
+bad:
+ FRELE(fp);
return (error);
}
diff --git a/sys/compat/ibcs2/ibcs2_fcntl.c b/sys/compat/ibcs2/ibcs2_fcntl.c
index dcdb6d1bdad..7022a953a60 100644
--- a/sys/compat/ibcs2/ibcs2_fcntl.c
+++ b/sys/compat/ibcs2/ibcs2_fcntl.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ibcs2_fcntl.c,v 1.7 2002/02/02 16:05:58 art Exp $ */
+/* $OpenBSD: ibcs2_fcntl.c,v 1.8 2002/02/13 19:08:06 art Exp $ */
/* $NetBSD: ibcs2_fcntl.c,v 1.6 1996/05/03 17:05:20 christos Exp $ */
/*
@@ -189,8 +189,10 @@ ibcs2_sys_open(p, v, retval)
if ((fp = fd_getfile(fdp, *retval)) == NULL)
return EBADF;
+ FREF(fp);
if (fp->f_type == DTYPE_VNODE)
(fp->f_ops->fo_ioctl)(fp, TIOCSCTTY, (caddr_t) 0, p);
+ FRELE(fp);
}
return ret;
}
diff --git a/sys/compat/linux/linux_blkio.c b/sys/compat/linux/linux_blkio.c
index 71bf8fb9f56..321afe91058 100644
--- a/sys/compat/linux/linux_blkio.c
+++ b/sys/compat/linux/linux_blkio.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: linux_blkio.c,v 1.3 2002/02/08 00:03:46 art Exp $ */
+/* $OpenBSD: linux_blkio.c,v 1.4 2002/02/13 19:08:06 art Exp $ */
/* $NetBSD: linux_blkio.c,v 1.3 2001/01/18 17:48:04 tv Exp $ */
/*
@@ -71,6 +71,7 @@ linux_ioctl_blkio(struct proc *p, struct linux_sys_ioctl_args *uap,
fdp = p->p_fd;
if ((fp = fd_getfile(fdp, SCARG(uap, fd))) == NULL)
return (EBADF);
+ FREF(fp);
error = 0;
ioctlf = fp->f_ops->fo_ioctl;
com = SCARG(uap, com);
@@ -115,5 +116,6 @@ linux_ioctl_blkio(struct proc *p, struct linux_sys_ioctl_args *uap,
error = ENOTTY;
}
+ FRELE(fp);
return error;
}
diff --git a/sys/compat/linux/linux_fdio.c b/sys/compat/linux/linux_fdio.c
index 9363f9583be..cb711c9e13e 100644
--- a/sys/compat/linux/linux_fdio.c
+++ b/sys/compat/linux/linux_fdio.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: linux_fdio.c,v 1.4 2002/02/08 00:03:46 art Exp $ */
+/* $OpenBSD: linux_fdio.c,v 1.5 2002/02/13 19:08:06 art Exp $ */
/* $NetBSD: linux_fdio.c,v 1.1 2000/12/10 14:12:16 fvdl Exp $ */
/*
@@ -78,6 +78,7 @@ linux_ioctl_fdio(struct proc *p, struct linux_sys_ioctl_args *uap,
if ((fp = fd_getfile(fdp, SCARG(uap, fd))) == NULL)
return (EBADF);
+ FREF(fp);
com = SCARG(uap, com);
ioctlf = fp->f_ops->fo_ioctl;
@@ -144,5 +145,6 @@ linux_ioctl_fdio(struct proc *p, struct linux_sys_ioctl_args *uap,
error = EINVAL;
}
+ FRELE(fp);
return 0;
}
diff --git a/sys/compat/linux/linux_file.c b/sys/compat/linux/linux_file.c
index 9b2e3b49e8e..cd20ed709f8 100644
--- a/sys/compat/linux/linux_file.c
+++ b/sys/compat/linux/linux_file.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: linux_file.c,v 1.19 2002/02/02 16:05:58 art Exp $ */
+/* $OpenBSD: linux_file.c,v 1.20 2002/02/13 19:08:06 art Exp $ */
/* $NetBSD: linux_file.c,v 1.15 1996/05/20 01:59:09 fvdl Exp $ */
/*
@@ -196,8 +196,10 @@ linux_sys_open(p, v, retval)
if ((fp = fd_getfile(fdp, *retval)) == NULL)
return (EBADF);
+ FREF(fp);
if (fp->f_type == DTYPE_VNODE)
(fp->f_ops->fo_ioctl) (fp, TIOCSCTTY, (caddr_t) 0, p);
+ FRELE(fp);
}
return 0;
}
@@ -400,7 +402,10 @@ linux_sys_fcntl(p, v, retval)
vp = (struct vnode *)fp->f_data;
if (vp->v_type != VCHR)
return EINVAL;
- if ((error = VOP_GETATTR(vp, &va, p->p_ucred, p)))
+ FREF(fp);
+ error = VOP_GETATTR(vp, &va, p->p_ucred, p);
+ FRELE(fp);
+ if (error)
return error;
d_tty = cdevsw[major(va.va_rdev)].d_tty;
if (!d_tty || (!(tp = (*d_tty)(va.va_rdev))))
diff --git a/sys/compat/linux/linux_hdio.c b/sys/compat/linux/linux_hdio.c
index 746d070822a..6ec57f064e6 100644
--- a/sys/compat/linux/linux_hdio.c
+++ b/sys/compat/linux/linux_hdio.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: linux_hdio.c,v 1.3 2002/02/08 00:03:46 art Exp $ */
+/* $OpenBSD: linux_hdio.c,v 1.4 2002/02/13 19:08:06 art Exp $ */
/* $NetBSD: linux_hdio.c,v 1.1 2000/12/10 14:12:17 fvdl Exp $ */
/*
@@ -80,6 +80,7 @@ linux_ioctl_hdio(struct proc *p, struct linux_sys_ioctl_args *uap,
if ((fp = fd_getfile(fdp, SCARG(uap, fd))) == NULL)
return (EBADF);
+ FREF(fp);
com = SCARG(uap, com);
ioctlf = fp->f_ops->fo_ioctl;
retval[0] = error = 0;
@@ -104,8 +105,10 @@ linux_ioctl_hdio(struct proc *p, struct linux_sys_ioctl_args *uap,
error = ioctlf(fp, ATAIOCCOMMAND, (caddr_t)&req, p);
if (error != 0)
break;
- if (req.retsts != ATACMD_OK)
- return EIO;
+ if (req.retsts != ATACMD_OK) {
+ error = EIO;
+ break;
+ }
error = copyin(atap, &ata, sizeof ata);
if (error != 0)
break;
@@ -175,5 +178,6 @@ linux_ioctl_hdio(struct proc *p, struct linux_sys_ioctl_args *uap,
error = EINVAL;
}
+ FRELE(fp);
return error;
}
diff --git a/sys/compat/netbsd/netbsd_stat.c b/sys/compat/netbsd/netbsd_stat.c
index dbd8c41ab1c..7921a2710f9 100644
--- a/sys/compat/netbsd/netbsd_stat.c
+++ b/sys/compat/netbsd/netbsd_stat.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: netbsd_stat.c,v 1.12 2001/10/26 12:03:27 art Exp $ */
+/* $OpenBSD: netbsd_stat.c,v 1.13 2002/02/13 19:08:06 art Exp $ */
/*
* Copyright (c) 1989, 1993
* The Regents of the University of California. All rights reserved.
@@ -195,7 +195,9 @@ netbsd_sys___fstat13(p, v, retval)
if ((fp = fd_getfile(fdp, fd)) == NULL)
return (EBADF);
+ FREF(fp);
error = (*fp->f_ops->fo_stat)(fp, &sb, p);
+ FRELE(fp);
if (error)
return (error);
openbsd_to_netbsd_stat(&sb, &nsb);
diff --git a/sys/compat/osf1/osf1_descrip.c b/sys/compat/osf1/osf1_descrip.c
index ea2b3ae3839..4dfabbd2e8b 100644
--- a/sys/compat/osf1/osf1_descrip.c
+++ b/sys/compat/osf1/osf1_descrip.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: osf1_descrip.c,v 1.7 2001/10/26 12:03:27 art Exp $ */
+/* $OpenBSD: osf1_descrip.c,v 1.8 2002/02/13 19:08:06 art Exp $ */
/* $NetBSD: osf1_descrip.c,v 1.5 1999/06/26 01:24:41 cgd Exp $ */
/*
@@ -246,7 +246,9 @@ osf1_sys_fstat(p, v, retval)
if ((fp = fd_getfile(fdp, SCARG(uap, fd))) == NULL)
return (EBADF);
+ FREF(fp);
error = (*fp->f_ops->fo_stat)(fp, &ub, p);
+ FRELE(fp);
osf1_cvt_stat_from_native(&ub, &oub);
if (error == 0)
error = copyout((caddr_t)&oub, (caddr_t)SCARG(uap, sb),
diff --git a/sys/compat/sunos/sunos_misc.c b/sys/compat/sunos/sunos_misc.c
index 939288415d7..4efd5a60136 100644
--- a/sys/compat/sunos/sunos_misc.c
+++ b/sys/compat/sunos/sunos_misc.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: sunos_misc.c,v 1.33 2002/02/12 18:41:21 art Exp $ */
+/* $OpenBSD: sunos_misc.c,v 1.34 2002/02/13 19:08:06 art Exp $ */
/* $NetBSD: sunos_misc.c,v 1.65 1996/04/22 01:44:31 christos Exp $ */
/*
@@ -704,9 +704,11 @@ sunos_sys_open(p, v, retval)
if ((fp = fd_getfile(fdp, *retval)) == NULL)
return (EBADF);
+ FREF(fp);
/* ignore any error, just give it a try */
if (fp->f_type == DTYPE_VNODE)
(fp->f_ops->fo_ioctl)(fp, TIOCSCTTY, (caddr_t)0, p);
+ FRELE(fp);
}
return ret;
}
diff --git a/sys/compat/svr4/svr4_fcntl.c b/sys/compat/svr4/svr4_fcntl.c
index 189e3744886..c8badb3394a 100644
--- a/sys/compat/svr4/svr4_fcntl.c
+++ b/sys/compat/svr4/svr4_fcntl.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: svr4_fcntl.c,v 1.20 2002/02/02 16:05:58 art Exp $ */
+/* $OpenBSD: svr4_fcntl.c,v 1.21 2002/02/13 19:08:06 art Exp $ */
/* $NetBSD: svr4_fcntl.c,v 1.14 1995/10/14 20:24:24 christos Exp $ */
/*
@@ -272,8 +272,10 @@ fd_truncate(p, fd, flp, retval)
if (fp->f_type != DTYPE_VNODE || vp->v_type == VFIFO)
return ESPIPE;
+ FREF(fp);
+
if ((error = VOP_GETATTR(vp, &vattr, p->p_ucred, p)) != 0)
- return error;
+ goto out;
length = vattr.va_size;
@@ -291,18 +293,23 @@ fd_truncate(p, fd, flp, retval)
break;
default:
- return EINVAL;
+ error = EINVAL;
+ goto out;
}
if (start + flp->l_len < length) {
/* We don't support free'ing in the middle of the file */
- return EINVAL;
+ error = EINVAL;
+ goto out;
}
SCARG(&ft, fd) = fd;
SCARG(&ft, length) = start;
- return sys_ftruncate(p, &ft, retval);
+ error = sys_ftruncate(p, &ft, retval);
+out:
+ FRELE(fp);
+ return (error);
}
int
@@ -338,9 +345,11 @@ svr4_sys_open(p, v, retval)
if ((fp = fd_getfile(fdp, *retval)) == NULL)
return (EBADF);
+ FREF(fp);
/* ignore any error, just give it a try */
if (fp->f_type == DTYPE_VNODE)
(fp->f_ops->fo_ioctl) (fp, TIOCSCTTY, (caddr_t) 0, p);
+ FRELE(fp);
}
return 0;
}
diff --git a/sys/compat/svr4/svr4_ioctl.c b/sys/compat/svr4/svr4_ioctl.c
index f70b03d6f36..5586be3f055 100644
--- a/sys/compat/svr4/svr4_ioctl.c
+++ b/sys/compat/svr4/svr4_ioctl.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: svr4_ioctl.c,v 1.9 2001/10/26 12:03:27 art Exp $ */
+/* $OpenBSD: svr4_ioctl.c,v 1.10 2002/02/13 19:08:06 art Exp $ */
/* $NetBSD: svr4_ioctl.c,v 1.16 1996/04/11 12:54:41 christos Exp $ */
/*
@@ -95,6 +95,7 @@ svr4_sys_ioctl(p, v, retval)
u_long cmd;
int (*fun) __P((struct file *, struct proc *, register_t *,
int, u_long, caddr_t));
+ int error = 0;
#ifdef DEBUG_SVR4
char dir[4];
char c;
@@ -142,11 +143,16 @@ svr4_sys_ioctl(p, v, retval)
case SVR4_XIOC:
/* We do not support those */
- return (EINVAL);
+ error = EINVAL;
+ goto out;
default:
DPRINTF(("Unimplemented ioctl %lx\n", cmd));
- return (0); /* XXX: really ENOSYS */
+ error = 0; /* XXX: really ENOSYS */
+ goto out;
}
- return (*fun)(fp, p, retval, SCARG(uap, fd), cmd, SCARG(uap, data));
+ error = (*fun)(fp, p, retval, SCARG(uap, fd), cmd, SCARG(uap, data));
+out:
+ FRELE(fp);
+ return (error);
}
diff --git a/sys/compat/svr4/svr4_stream.c b/sys/compat/svr4/svr4_stream.c
index fce64e4a0c1..2f3cd8e7d32 100644
--- a/sys/compat/svr4/svr4_stream.c
+++ b/sys/compat/svr4/svr4_stream.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: svr4_stream.c,v 1.14 2001/10/26 12:03:27 art Exp $ */
+/* $OpenBSD: svr4_stream.c,v 1.15 2002/02/13 19:08:06 art Exp $ */
/* $NetBSD: svr4_stream.c,v 1.19 1996/12/22 23:00:03 fvdl Exp $ */
/*
@@ -1421,9 +1421,6 @@ svr4_sys_putmsg(p, v, retval)
int error;
caddr_t sg;
- if ((fp = fd_getfile(fdp, SCARG(uap, fd))) == NULL)
- return EBADF;
-
#ifdef DEBUG_SVR4
show_msg(">putmsg", SCARG(uap, fd), SCARG(uap, ctl),
SCARG(uap, dat), SCARG(uap, flags));
@@ -1570,9 +1567,6 @@ svr4_sys_getmsg(p, v, retval)
int fl;
caddr_t sg;
- if ((fp = fd_getfile(fdp, SCARG(uap, fd))) == NULL)
- return EBADF;
-
bzero(&sc, sizeof(sc));
#ifdef DEBUG_SVR4
diff --git a/sys/compat/ultrix/ultrix_pathname.c b/sys/compat/ultrix/ultrix_pathname.c
index 1073053c24c..ce2a88ea869 100644
--- a/sys/compat/ultrix/ultrix_pathname.c
+++ b/sys/compat/ultrix/ultrix_pathname.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ultrix_pathname.c,v 1.6 2002/02/12 18:41:21 art Exp $ */
+/* $OpenBSD: ultrix_pathname.c,v 1.7 2002/02/13 19:08:06 art Exp $ */
/* $NetBSD: ultrix_pathname.c,v 1.2 1996/04/07 17:23:07 jonathan Exp $ */
/*
@@ -189,9 +189,11 @@ ultrix_sys_open(p, v, retval)
if ((fd = fd_getfile(fdp, *retval)) == NULL)
return (EBADF);
+ FREF(fp);
/* ignore any error, just give it a try */
if (fp->f_type == DTYPE_VNODE)
(fp->f_ops->fo_ioctl)(fp, TIOCSCTTY, (caddr_t)0, p);
+ FRELE(fp);
}
return ret;
}
diff --git a/sys/kern/kern_descrip.c b/sys/kern/kern_descrip.c
index b7e1f7c48a0..363d4be0a4f 100644
--- a/sys/kern/kern_descrip.c
+++ b/sys/kern/kern_descrip.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kern_descrip.c,v 1.52 2002/02/09 00:27:49 art Exp $ */
+/* $OpenBSD: kern_descrip.c,v 1.53 2002/02/13 19:08:06 art Exp $ */
/* $NetBSD: kern_descrip.c,v 1.42 1996/03/30 22:24:38 christos Exp $ */
/*
@@ -577,7 +577,7 @@ sys_close(p, v, retval)
syscallarg(int) fd;
} */ *uap = v;
int fd = SCARG(uap, fd);
- register struct filedesc *fdp = p->p_fd;
+ struct filedesc *fdp = p->p_fd;
if (fd_getfile(fdp, fd) == NULL)
return (EBADF);
@@ -606,7 +606,9 @@ sys_fstat(p, v, retval)
if ((fp = fd_getfile(fdp, fd)) == NULL)
return (EBADF);
+ FREF(fp);
error = (*fp->f_ops->fo_stat)(fp, &ub, p);
+ FRELE(fp);
if (error == 0) {
/* Don't let non-root see generation numbers
(for NFS security) */
@@ -628,7 +630,7 @@ sys_fpathconf(p, v, retval)
void *v;
register_t *retval;
{
- register struct sys_fpathconf_args /* {
+ struct sys_fpathconf_args /* {
syscallarg(int) fd;
syscallarg(int) name;
} */ *uap = v;
@@ -636,25 +638,34 @@ sys_fpathconf(p, v, retval)
struct filedesc *fdp = p->p_fd;
struct file *fp;
struct vnode *vp;
+ int error;
if ((fp = fd_getfile(fdp, fd)) == NULL)
return (EBADF);
+ FREF(fp);
switch (fp->f_type) {
case DTYPE_PIPE:
case DTYPE_SOCKET:
- if (SCARG(uap, name) != _PC_PIPE_BUF)
- return (EINVAL);
+ if (SCARG(uap, name) != _PC_PIPE_BUF) {
+ error = EINVAL;
+ break;
+ }
*retval = PIPE_BUF;
+ error = 0;
+ break;
return (0);
case DTYPE_VNODE:
vp = (struct vnode *)fp->f_data;
- return (VOP_PATHCONF(vp, SCARG(uap, name), retval));
+ error = VOP_PATHCONF(vp, SCARG(uap, name), retval);
+ break;
default:
- return (EOPNOTSUPP);
+ error = EOPNOTSUPP;
+ break;
}
- /*NOTREACHED*/
+ FRELE(fp);
+ return (error);
}
/*
@@ -1111,16 +1122,17 @@ sys_flock(p, v, retval)
void *v;
register_t *retval;
{
- register struct sys_flock_args /* {
+ struct sys_flock_args /* {
syscallarg(int) fd;
syscallarg(int) how;
} */ *uap = v;
int fd = SCARG(uap, fd);
int how = SCARG(uap, how);
- register struct filedesc *fdp = p->p_fd;
- register struct file *fp;
+ struct filedesc *fdp = p->p_fd;
+ struct file *fp;
struct vnode *vp;
struct flock lf;
+ int error;
if ((fp = fd_getfile(fdp, fd)) == NULL)
return (EBADF);
@@ -1133,18 +1145,24 @@ sys_flock(p, v, retval)
if (how & LOCK_UN) {
lf.l_type = F_UNLCK;
fp->f_flag &= ~FHASLOCK;
- return (VOP_ADVLOCK(vp, (caddr_t)fp, F_UNLCK, &lf, F_FLOCK));
+ error = VOP_ADVLOCK(vp, (caddr_t)fp, F_UNLCK, &lf, F_FLOCK);
+ goto out;
}
if (how & LOCK_EX)
lf.l_type = F_WRLCK;
else if (how & LOCK_SH)
lf.l_type = F_RDLCK;
- else
- return (EINVAL);
+ else {
+ error = EINVAL;
+ goto out;
+ }
fp->f_flag |= FHASLOCK;
if (how & LOCK_NB)
- return (VOP_ADVLOCK(vp, (caddr_t)fp, F_SETLK, &lf, F_FLOCK));
- return (VOP_ADVLOCK(vp, (caddr_t)fp, F_SETLK, &lf, F_FLOCK|F_WAIT));
+ error = VOP_ADVLOCK(vp, (caddr_t)fp, F_SETLK, &lf, F_FLOCK);
+ else
+ error = VOP_ADVLOCK(vp, (caddr_t)fp, F_SETLK, &lf, F_FLOCK|F_WAIT);
+out:
+ return (error);
}
/*
diff --git a/sys/kern/sys_generic.c b/sys/kern/sys_generic.c
index 08c3776d51e..de65194f32a 100644
--- a/sys/kern/sys_generic.c
+++ b/sys/kern/sys_generic.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: sys_generic.c,v 1.36 2002/02/08 19:58:03 art Exp $ */
+/* $OpenBSD: sys_generic.c,v 1.37 2002/02/13 19:08:06 art Exp $ */
/* $NetBSD: sys_generic.c,v 1.24 1996/03/29 00:25:32 cgd Exp $ */
/*
@@ -504,16 +504,16 @@ sys_ioctl(p, v, retval)
void *v;
register_t *retval;
{
- register struct sys_ioctl_args /* {
+ struct sys_ioctl_args /* {
syscallarg(int) fd;
syscallarg(u_long) com;
syscallarg(caddr_t) data;
} */ *uap = v;
- register struct file *fp;
- register struct filedesc *fdp;
- register u_long com;
- register int error;
- register u_int size;
+ struct file *fp;
+ struct filedesc *fdp;
+ u_long com;
+ int error;
+ u_int size;
caddr_t data, memp;
int tmp;
#define STK_PARAMS 128
@@ -542,6 +542,7 @@ sys_ioctl(p, v, retval)
size = IOCPARM_LEN(com);
if (size > IOCPARM_MAX)
return (ENOTTY);
+ FREF(fp);
memp = NULL;
if (size > sizeof (stkbuf)) {
memp = (caddr_t)malloc((u_long)size, M_IOCTLOPS, M_WAITOK);
@@ -552,9 +553,7 @@ sys_ioctl(p, v, retval)
if (size) {
error = copyin(SCARG(uap, data), data, (u_int)size);
if (error) {
- if (memp)
- free(memp, M_IOCTLOPS);
- return (error);
+ goto out;
}
} else
*(caddr_t *)data = SCARG(uap, data);
@@ -630,6 +629,8 @@ sys_ioctl(p, v, retval)
error = copyout(data, SCARG(uap, data), (u_int)size);
break;
}
+out:
+ FRELE(fp);
if (memp)
free(memp, M_IOCTLOPS);
return (error);
@@ -789,10 +790,12 @@ selscan(p, ibits, obits, nfd, retval)
bits &= ~(1 << j);
if ((fp = fd_getfile(fdp, fd)) == NULL)
return (EBADF);
+ FREF(fp);
if ((*fp->f_ops->fo_select)(fp, flag[msk], p)) {
FD_SET(fd, pobits);
n++;
}
+ FRELE(fp);
}
}
}
@@ -892,6 +895,7 @@ pollscan(p, pl, nfd, retval)
n++;
continue;
}
+ FREF(fp);
for (x = msk = 0; msk < 3; msk++) {
if (pl[i].events & pflag[msk]) {
if ((*fp->f_ops->fo_select)(fp, flag[msk], p)) {
@@ -901,6 +905,7 @@ pollscan(p, pl, nfd, retval)
}
}
}
+ FRELE(fp);
if (x)
n++;
}
diff --git a/sys/miscfs/fdesc/fdesc_vnops.c b/sys/miscfs/fdesc/fdesc_vnops.c
index b120fe7da96..a4f7c849543 100644
--- a/sys/miscfs/fdesc/fdesc_vnops.c
+++ b/sys/miscfs/fdesc/fdesc_vnops.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: fdesc_vnops.c,v 1.29 2002/02/12 18:41:21 art Exp $ */
+/* $OpenBSD: fdesc_vnops.c,v 1.30 2002/02/13 19:08:06 art Exp $ */
/* $NetBSD: fdesc_vnops.c,v 1.32 1996/04/11 11:24:29 mrg Exp $ */
/*
@@ -483,7 +483,9 @@ fdesc_getattr(v)
if ((fp = fd_getfile(fdp, fd)) == NULL)
return (EBADF);
memset(&stb, 0, sizeof(stb));
+ FREF(fp);
error = (*fp->f_ops->fo_stat)(fp, &stb, ap->a_p);
+ FRELE(fp);
if (error != 0)
break;
vattr_null(vap);