Sun Dec 8 10:30:31 2019 UTC ()
Pull up following revision(s) (requested by riastradh in ticket #1469):

	sys/dev/cons.c: revision 1.76
	sys/dev/cons.c: revision 1.77

Fix reference count leak in cons(4).
Don't forget to vrele after you're done, folks!
Restore historical $Hdr$ tag after git cvsexportcommit nixed it.


(martin)
diff -r1.75 -r1.75.10.1 src/sys/dev/cons.c

cvs diff -r1.75 -r1.75.10.1 src/sys/dev/cons.c (expand / switch to unified diff)

--- src/sys/dev/cons.c 2015/05/29 16:26:45 1.75
+++ src/sys/dev/cons.c 2019/12/08 10:30:31 1.75.10.1
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: cons.c,v 1.75 2015/05/29 16:26:45 macallan Exp $ */ 1/* $NetBSD: cons.c,v 1.75.10.1 2019/12/08 10:30:31 martin Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1988 University of Utah. 4 * Copyright (c) 1988 University of Utah.
5 * Copyright (c) 1990, 1993 5 * Copyright (c) 1990, 1993
6 * The Regents of the University of California. All rights reserved. 6 * The Regents of the University of California. All rights reserved.
7 * 7 *
8 * This code is derived from software contributed to Berkeley by 8 * This code is derived from software contributed to Berkeley by
9 * the Systems Programming Group of the University of Utah Computer 9 * the Systems Programming Group of the University of Utah Computer
10 * Science Department. 10 * Science Department.
11 * 11 *
12 * Redistribution and use in source and binary forms, with or without 12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions 13 * modification, are permitted provided that the following conditions
14 * are met: 14 * are met:
@@ -29,27 +29,27 @@ @@ -29,27 +29,27 @@
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * SUCH DAMAGE. 34 * SUCH DAMAGE.
35 * 35 *
36 * from: Utah $Hdr: cons.c 1.7 92/01/21$ 36 * from: Utah $Hdr: cons.c 1.7 92/01/21$
37 * 37 *
38 * @(#)cons.c 8.2 (Berkeley) 1/12/94 38 * @(#)cons.c 8.2 (Berkeley) 1/12/94
39 */ 39 */
40 40
41#include <sys/cdefs.h> 41#include <sys/cdefs.h>
42__KERNEL_RCSID(0, "$NetBSD: cons.c,v 1.75 2015/05/29 16:26:45 macallan Exp $"); 42__KERNEL_RCSID(0, "$NetBSD: cons.c,v 1.75.10.1 2019/12/08 10:30:31 martin Exp $");
43 43
44#include <sys/param.h> 44#include <sys/param.h>
45#include <sys/proc.h> 45#include <sys/proc.h>
46#include <sys/systm.h> 46#include <sys/systm.h>
47#include <sys/buf.h> 47#include <sys/buf.h>
48#include <sys/ioctl.h> 48#include <sys/ioctl.h>
49#include <sys/poll.h> 49#include <sys/poll.h>
50#include <sys/tty.h> 50#include <sys/tty.h>
51#include <sys/file.h> 51#include <sys/file.h>
52#include <sys/conf.h> 52#include <sys/conf.h>
53#include <sys/vnode.h> 53#include <sys/vnode.h>
54#include <sys/kauth.h> 54#include <sys/kauth.h>
55#include <sys/mutex.h> 55#include <sys/mutex.h>
@@ -148,26 +148,27 @@ cnclose(dev_t dev, int flag, int mode, s @@ -148,26 +148,27 @@ cnclose(dev_t dev, int flag, int mode, s
148 int unit, error; 148 int unit, error;
149 149
150 unit = minor(dev); 150 unit = minor(dev);
151 151
152 if (cn_tab == NULL) 152 if (cn_tab == NULL)
153 return (0); 153 return (0);
154 154
155 vp = cn_devvp[unit]; 155 vp = cn_devvp[unit];
156 cn_devvp[unit] = NULL; 156 cn_devvp[unit] = NULL;
157 error = vn_lock(vp, LK_EXCLUSIVE | LK_RETRY); 157 error = vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
158 if (error == 0) { 158 if (error == 0) {
159 error = VOP_CLOSE(vp, flag, kauth_cred_get()); 159 error = VOP_CLOSE(vp, flag, kauth_cred_get());
160 VOP_UNLOCK(vp); 160 VOP_UNLOCK(vp);
 161 vrele(vp);
161 } 162 }
162 return error; 163 return error;
163} 164}
164 165
165int 166int
166cnread(dev_t dev, struct uio *uio, int flag) 167cnread(dev_t dev, struct uio *uio, int flag)
167{ 168{
168 int error; 169 int error;
169 170
170 /* 171 /*
171 * If we would redirect input, punt. This will keep strange 172 * If we would redirect input, punt. This will keep strange
172 * things from happening to people who are using the real 173 * things from happening to people who are using the real
173 * console. Nothing should be using /dev/console for 174 * console. Nothing should be using /dev/console for