CVS commit: src/sys/rump/librump/rumpkern

2022-06-30 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Thu Jun 30 07:47:07 UTC 2022

Modified Files:
src/sys/rump/librump/rumpkern: sleepq.c

Log Message:
Fix rump build failure after sleepq.h:r1.35.


To generate a diff of this commit:
cvs rdiff -u -r1.22 -r1.23 src/sys/rump/librump/rumpkern/sleepq.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/rump/librump/rumpkern

2022-06-30 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Thu Jun 30 07:47:07 UTC 2022

Modified Files:
src/sys/rump/librump/rumpkern: sleepq.c

Log Message:
Fix rump build failure after sleepq.h:r1.35.


To generate a diff of this commit:
cvs rdiff -u -r1.22 -r1.23 src/sys/rump/librump/rumpkern/sleepq.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/rump/librump/rumpkern/sleepq.c
diff -u src/sys/rump/librump/rumpkern/sleepq.c:1.22 src/sys/rump/librump/rumpkern/sleepq.c:1.23
--- src/sys/rump/librump/rumpkern/sleepq.c:1.22	Sat Apr  9 23:45:23 2022
+++ src/sys/rump/librump/rumpkern/sleepq.c	Thu Jun 30 07:47:07 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: sleepq.c,v 1.22 2022/04/09 23:45:23 riastradh Exp $	*/
+/*	$NetBSD: sleepq.c,v 1.23 2022/06/30 07:47:07 knakahara Exp $	*/
 
 /*
  * Copyright (c) 2008 Antti Kantee.  All Rights Reserved.
@@ -26,7 +26,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sleepq.c,v 1.22 2022/04/09 23:45:23 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sleepq.c,v 1.23 2022/06/30 07:47:07 knakahara Exp $");
 
 #include 
 #include 
@@ -69,7 +69,7 @@ sleepq_enqueue(sleepq_t *sq, wchan_t wc,
 }
 
 int
-sleepq_block(int timo, bool catch)
+sleepq_block(int timo, bool catch, struct syncobj *syncobj __unused)
 {
 	struct lwp *l = curlwp;
 	int error = 0;



CVS commit: src/doc

2022-06-30 Thread Nia Alarie
Module Name:src
Committed By:   nia
Date:   Thu Jun 30 11:03:07 UTC 2022

Modified Files:
src/doc: CHANGES

Log Message:
doc: Various changes in the past week from various developers


To generate a diff of this commit:
cvs rdiff -u -r1.2888 -r1.2889 src/doc/CHANGES

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/doc/CHANGES
diff -u src/doc/CHANGES:1.2888 src/doc/CHANGES:1.2889
--- src/doc/CHANGES:1.2888	Wed Jun 22 08:31:06 2022
+++ src/doc/CHANGES	Thu Jun 30 11:03:07 2022
@@ -1,4 +1,4 @@
-# LIST OF CHANGES FROM LAST RELEASE:			<$Revision: 1.2888 $>
+# LIST OF CHANGES FROM LAST RELEASE:			<$Revision: 1.2889 $>
 #
 #
 # [Note: This file does not mention every change made to the NetBSD source tree.
@@ -609,3 +609,15 @@ Changes from NetBSD 9.0 to NetBSD 10.0:
 		[yamaguchi 20220620]
 	bridge(4): Support VLAN frames stripped by hardware tagging.
 		[yamaguchi 20220620]
+	urtwn(4): Support the TRENDnet TEW-648UBM. [brook 20220623]
+	powerpc: Add fma(3), fmaf(3), fmal(3) to libm. [he 20220623]
+	atari: Add box drawing character support to the ite(4) framebuffer
+		driver. [tsutsui 20220625]
+	x68k: Add box drawing character support to the ite(4) framebuffer
+		driver. [tsutsui 20220625]
+	arm: Improve performance of splx(9). [jmcneill 20220625]
+	rcp(1): Add SIGINFO support. [rin 20220626]
+	robots(6): Enable FANCY mode for debugging purposes.
+		[christos 20220627]
+	uintuos(4): Add a driver for Wacom Intuos drawing tablets.
+		[yhardy 20220630]



CVS commit: src/doc

2022-06-30 Thread Nia Alarie
Module Name:src
Committed By:   nia
Date:   Thu Jun 30 11:03:07 UTC 2022

Modified Files:
src/doc: CHANGES

Log Message:
doc: Various changes in the past week from various developers


To generate a diff of this commit:
cvs rdiff -u -r1.2888 -r1.2889 src/doc/CHANGES

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/dev/pci

2022-06-30 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Thu Jun 30 16:36:11 UTC 2022

Modified Files:
src/sys/dev/pci: if_bge.c

Log Message:
KNF


To generate a diff of this commit:
cvs rdiff -u -r1.354 -r1.355 src/sys/dev/pci/if_bge.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/pci/if_bge.c
diff -u src/sys/dev/pci/if_bge.c:1.354 src/sys/dev/pci/if_bge.c:1.355
--- src/sys/dev/pci/if_bge.c:1.354	Tue Jun 28 06:24:00 2022
+++ src/sys/dev/pci/if_bge.c	Thu Jun 30 16:36:11 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_bge.c,v 1.354 2022/06/28 06:24:00 skrll Exp $	*/
+/*	$NetBSD: if_bge.c,v 1.355 2022/06/30 16:36:11 skrll Exp $	*/
 
 /*
  * Copyright (c) 2001 Wind River Systems
@@ -79,19 +79,20 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_bge.c,v 1.354 2022/06/28 06:24:00 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_bge.c,v 1.355 2022/06/30 16:36:11 skrll Exp $");
 
 #include 
-#include 
+
 #include 
-#include 
-#include 
+#include 
 #include 
+#include 
 #include 
-#include 
+#include 
 #include 
+#include 
 #include 
-#include 
+#include 
 
 #include 
 #include 



CVS commit: src/sys/dev/pci

2022-06-30 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Thu Jun 30 16:36:11 UTC 2022

Modified Files:
src/sys/dev/pci: if_bge.c

Log Message:
KNF


To generate a diff of this commit:
cvs rdiff -u -r1.354 -r1.355 src/sys/dev/pci/if_bge.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/dev/pci

2022-06-30 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Thu Jun 30 16:49:55 UTC 2022

Modified Files:
src/sys/dev/pci: if_bge.c

Log Message:
Remove strange (duplicate) assignment.


To generate a diff of this commit:
cvs rdiff -u -r1.355 -r1.356 src/sys/dev/pci/if_bge.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/dev/pci

2022-06-30 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Thu Jun 30 16:49:55 UTC 2022

Modified Files:
src/sys/dev/pci: if_bge.c

Log Message:
Remove strange (duplicate) assignment.


To generate a diff of this commit:
cvs rdiff -u -r1.355 -r1.356 src/sys/dev/pci/if_bge.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/pci/if_bge.c
diff -u src/sys/dev/pci/if_bge.c:1.355 src/sys/dev/pci/if_bge.c:1.356
--- src/sys/dev/pci/if_bge.c:1.355	Thu Jun 30 16:36:11 2022
+++ src/sys/dev/pci/if_bge.c	Thu Jun 30 16:49:55 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_bge.c,v 1.355 2022/06/30 16:36:11 skrll Exp $	*/
+/*	$NetBSD: if_bge.c,v 1.356 2022/06/30 16:49:55 skrll Exp $	*/
 
 /*
  * Copyright (c) 2001 Wind River Systems
@@ -79,7 +79,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_bge.c,v 1.355 2022/06/30 16:36:11 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_bge.c,v 1.356 2022/06/30 16:49:55 skrll Exp $");
 
 #include 
 
@@ -5584,8 +5584,6 @@ bge_init(struct ifnet *ifp)
 		return error;
 	}
 
-	ifp = &sc->ethercom.ec_if;
-
 	/* 5718 step 25, 57XX step 54 */
 	/* Specify MTU. */
 	CSR_WRITE_4(sc, BGE_RX_MTU, ifp->if_mtu +



CVS commit: src/sys/dev/pci

2022-06-30 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Thu Jun 30 19:06:35 UTC 2022

Modified Files:
src/sys/dev/pci: if_bge.c

Log Message:
KNF some comments


To generate a diff of this commit:
cvs rdiff -u -r1.356 -r1.357 src/sys/dev/pci/if_bge.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/dev/pci

2022-06-30 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Thu Jun 30 19:06:35 UTC 2022

Modified Files:
src/sys/dev/pci: if_bge.c

Log Message:
KNF some comments


To generate a diff of this commit:
cvs rdiff -u -r1.356 -r1.357 src/sys/dev/pci/if_bge.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/pci/if_bge.c
diff -u src/sys/dev/pci/if_bge.c:1.356 src/sys/dev/pci/if_bge.c:1.357
--- src/sys/dev/pci/if_bge.c:1.356	Thu Jun 30 16:49:55 2022
+++ src/sys/dev/pci/if_bge.c	Thu Jun 30 19:06:35 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_bge.c,v 1.356 2022/06/30 16:49:55 skrll Exp $	*/
+/*	$NetBSD: if_bge.c,v 1.357 2022/06/30 19:06:35 skrll Exp $	*/
 
 /*
  * Copyright (c) 2001 Wind River Systems
@@ -79,7 +79,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_bge.c,v 1.356 2022/06/30 16:49:55 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_bge.c,v 1.357 2022/06/30 19:06:35 skrll Exp $");
 
 #include 
 
@@ -1255,7 +1255,8 @@ bge_set_thresh(struct ifnet *ifp, int lv
 	struct bge_softc * const sc = ifp->if_softc;
 	int s;
 
-	/* For now, just save the new Rx-intr thresholds and record
+	/*
+	 * For now, just save the new Rx-intr thresholds and record
 	 * that a threshold update is pending.  Updating the hardware
 	 * registers here (even at splhigh()) is observed to
 	 * occasionally cause glitches where Rx-interrupts are not
@@ -4664,7 +4665,8 @@ bge_intr(void *xsc)
 	if (BGE_IS_5717_PLUS(sc))
 		intrmask = 0;
 
-	/* It is possible for the interrupt to arrive before
+	/*
+	 * It is possible for the interrupt to arrive before
 	 * the status block is updated prior to the interrupt.
 	 * Reading the PCI State register will confirm whether the
 	 * interrupt is ours and will flush the status block.
@@ -4986,7 +4988,8 @@ bge_compact_dma_runt(struct mbuf *pkt)
 		if (mlen >= 8)
 			continue;
 
-		/* If we get here, mbuf data is too small for DMA engine.
+		/*
+		 * If we get here, mbuf data is too small for DMA engine.
 		 * Try to fix by shuffling data to prev or next in chain.
 		 * If that fails, do a compacting deep-copy of the whole chain.
 		 */
@@ -5011,7 +5014,8 @@ bge_compact_dma_runt(struct mbuf *pkt)
 			m->m_next->m_len -= shortfall;
 			m->m_next->m_data += shortfall;
 		} else if (m->m_next == NULL || 1) {
-			/* Got a runt at the very end of the packet.
+			/*
+			 * Got a runt at the very end of the packet.
 			 * borrow data from the tail of the preceding mbuf and
 			 * update its length in-place. (The original data is
 			 * still valid, so we can do this even if prev is not



CVS commit: src/sys/kern

2022-06-30 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Fri Jul  1 01:04:01 UTC 2022

Modified Files:
src/sys/kern: vfs_lockf.c

Log Message:
vfs(9): Avoid arithmetic overflow in lf_advlock.

syzbot+897abbbe59467cbf6...@syzkaller.appspotmail.com


To generate a diff of this commit:
cvs rdiff -u -r1.75 -r1.76 src/sys/kern/vfs_lockf.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/kern

2022-06-30 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Fri Jul  1 01:04:01 UTC 2022

Modified Files:
src/sys/kern: vfs_lockf.c

Log Message:
vfs(9): Avoid arithmetic overflow in lf_advlock.

syzbot+897abbbe59467cbf6...@syzkaller.appspotmail.com


To generate a diff of this commit:
cvs rdiff -u -r1.75 -r1.76 src/sys/kern/vfs_lockf.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/kern/vfs_lockf.c
diff -u src/sys/kern/vfs_lockf.c:1.75 src/sys/kern/vfs_lockf.c:1.76
--- src/sys/kern/vfs_lockf.c:1.75	Sat Apr 16 18:15:22 2022
+++ src/sys/kern/vfs_lockf.c	Fri Jul  1 01:04:01 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: vfs_lockf.c,v 1.75 2022/04/16 18:15:22 andvar Exp $	*/
+/*	$NetBSD: vfs_lockf.c,v 1.76 2022/07/01 01:04:01 riastradh Exp $	*/
 
 /*
  * Copyright (c) 1982, 1986, 1989, 1993
@@ -35,7 +35,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: vfs_lockf.c,v 1.75 2022/04/16 18:15:22 andvar Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vfs_lockf.c,v 1.76 2022/07/01 01:04:01 riastradh Exp $");
 
 #include 
 #include 
@@ -815,6 +815,8 @@ lf_advlock(struct vop_advlock_args *ap, 
 	off_t start, end;
 	int error = 0;
 
+	KASSERTMSG(size >= 0, "size=%jd", (intmax_t)size);
+
 	/*
 	 * Convert the flock structure into a start and end.
 	 */
@@ -829,6 +831,8 @@ lf_advlock(struct vop_advlock_args *ap, 
 		break;
 
 	case SEEK_END:
+		if (fl->l_start > __type_max(off_t) - size)
+			return EINVAL;
 		start = size + fl->l_start;
 		break;
 
@@ -839,10 +843,14 @@ lf_advlock(struct vop_advlock_args *ap, 
 	if (fl->l_len == 0)
 		end = -1;
 	else {
-		if (fl->l_len > 0)
+		if (fl->l_len >= 0) {
+			if (fl->l_len - 1 > __type_max(off_t) - start)
+return EINVAL;
 			end = start + fl->l_len - 1;
-		else {
+		} else {
 			/* lockf() allows -ve lengths */
+			if (start < 0)
+return EINVAL;
 			end = start - 1;
 			start += fl->l_len;
 		}



CVS commit: src/sys/dev

2022-06-30 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Fri Jul  1 01:04:59 UTC 2022

Modified Files:
src/sys/dev: sequencer.c

Log Message:
sequencer(4): Fix lock leak in ioctl(FIOASYNC).

Reported-by: syzbot+0bfe9054ab0e70ab0...@syzkaller.appspotmail.com
Reported-by: syzbot+f2c5459483e60dd2c...@syzkaller.appspotmail.com
Reported-by: syzbot+d932ddf0ec7e30784...@syzkaller.appspotmail.com

Note: The evidence from
https://syzkaller.appspot.com/bug?id=19e1c8779bb0e020188ca80a586e470b59d7525d
suggests in the stack trace that the syscall was 16, which is chown.
This is not accurate; it happens because the x86 syscall logic sets
rax in the trapframe to the return value (in this case, 16 is EBUSY)
_before_ calling userret which does the lockdebug checks, and ddb
uses the trapframe's rax to show what the syscall number was when
printing its stack trace:

[ 104.0605877] Mutex error: lwp_exit,1084: sleep lock held
[ 104.0605877] lock address : 0xd9801269e050 type : sleep/adaptive
...
[ 104.5005727] syscall() at netbsd:syscall+0x323 sys/arch/x86/x86/syscall.c:92
[ 104.5115909] --- syscall (number 16) ---

XXX Maybe we should record the syscall number elsewhere so this is
not so confusing -- second time in 24h I've been bitten by this, and
in a different way.


To generate a diff of this commit:
cvs rdiff -u -r1.80 -r1.81 src/sys/dev/sequencer.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/sequencer.c
diff -u src/sys/dev/sequencer.c:1.80 src/sys/dev/sequencer.c:1.81
--- src/sys/dev/sequencer.c:1.80	Sat Jun  4 03:31:10 2022
+++ src/sys/dev/sequencer.c	Fri Jul  1 01:04:59 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: sequencer.c,v 1.80 2022/06/04 03:31:10 pgoyette Exp $	*/
+/*	$NetBSD: sequencer.c,v 1.81 2022/07/01 01:04:59 riastradh Exp $	*/
 
 /*
  * Copyright (c) 1998, 2008 The NetBSD Foundation, Inc.
@@ -55,7 +55,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sequencer.c,v 1.80 2022/06/04 03:31:10 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sequencer.c,v 1.81 2022/07/01 01:04:59 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "midi.h"
@@ -744,8 +744,10 @@ sequencerioctl(dev_t dev, u_long cmd, vo
 
 	case FIOASYNC:
 		if (*(int *)addr) {
-			if (sc->async != 0)
-return EBUSY;
+			if (sc->async != 0) {
+error = EBUSY;
+break;
+			}
 			sc->async = curproc->p_pid;
 			DPRINTF(("%s: FIOASYNC %d\n", __func__,
 			sc->async));



CVS commit: src/sys/dev

2022-06-30 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Fri Jul  1 01:04:59 UTC 2022

Modified Files:
src/sys/dev: sequencer.c

Log Message:
sequencer(4): Fix lock leak in ioctl(FIOASYNC).

Reported-by: syzbot+0bfe9054ab0e70ab0...@syzkaller.appspotmail.com
Reported-by: syzbot+f2c5459483e60dd2c...@syzkaller.appspotmail.com
Reported-by: syzbot+d932ddf0ec7e30784...@syzkaller.appspotmail.com

Note: The evidence from
https://syzkaller.appspot.com/bug?id=19e1c8779bb0e020188ca80a586e470b59d7525d
suggests in the stack trace that the syscall was 16, which is chown.
This is not accurate; it happens because the x86 syscall logic sets
rax in the trapframe to the return value (in this case, 16 is EBUSY)
_before_ calling userret which does the lockdebug checks, and ddb
uses the trapframe's rax to show what the syscall number was when
printing its stack trace:

[ 104.0605877] Mutex error: lwp_exit,1084: sleep lock held
[ 104.0605877] lock address : 0xd9801269e050 type : sleep/adaptive
...
[ 104.5005727] syscall() at netbsd:syscall+0x323 sys/arch/x86/x86/syscall.c:92
[ 104.5115909] --- syscall (number 16) ---

XXX Maybe we should record the syscall number elsewhere so this is
not so confusing -- second time in 24h I've been bitten by this, and
in a different way.


To generate a diff of this commit:
cvs rdiff -u -r1.80 -r1.81 src/sys/dev/sequencer.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/kern

2022-06-30 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Fri Jul  1 01:05:21 UTC 2022

Modified Files:
src/sys/kern: kern_fork.c

Log Message:
fork(2): Plug leaks in proc_alloc error branch.


To generate a diff of this commit:
cvs rdiff -u -r1.227 -r1.228 src/sys/kern/kern_fork.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/kern

2022-06-30 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Fri Jul  1 01:05:21 UTC 2022

Modified Files:
src/sys/kern: kern_fork.c

Log Message:
fork(2): Plug leaks in proc_alloc error branch.


To generate a diff of this commit:
cvs rdiff -u -r1.227 -r1.228 src/sys/kern/kern_fork.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/kern/kern_fork.c
diff -u src/sys/kern/kern_fork.c:1.227 src/sys/kern/kern_fork.c:1.228
--- src/sys/kern/kern_fork.c:1.227	Sun Oct 10 18:07:51 2021
+++ src/sys/kern/kern_fork.c	Fri Jul  1 01:05:21 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: kern_fork.c,v 1.227 2021/10/10 18:07:51 thorpej Exp $	*/
+/*	$NetBSD: kern_fork.c,v 1.228 2022/07/01 01:05:21 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 1999, 2001, 2004, 2006, 2007, 2008, 2019
@@ -68,7 +68,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: kern_fork.c,v 1.227 2021/10/10 18:07:51 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_fork.c,v 1.228 2022/07/01 01:05:21 riastradh Exp $");
 
 #include "opt_ktrace.h"
 #include "opt_dtrace.h"
@@ -309,6 +309,13 @@ fork1(struct lwp *l1, int flags, int exi
 	p2 = proc_alloc();
 	if (p2 == NULL) {
 		/* We were unable to allocate a process ID. */
+		uvm_uarea_free(uaddr);
+		mutex_enter(p1->p_lock);
+		cred = p1->p_cred;
+		uid = kauth_cred_getuid(cred);
+		(void)chgproccnt(uid, -1);
+		mutex_exit(p1->p_lock);
+		atomic_dec_uint(&nprocs);
 		return EAGAIN;
 	}
 



CVS commit: src/sys/kern

2022-06-30 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Fri Jul  1 01:05:31 UTC 2022

Modified Files:
src/sys/kern: kern_exec.c

Log Message:
posix_spawn(2): Plug leak in proc_alloc error branch.


To generate a diff of this commit:
cvs rdiff -u -r1.517 -r1.518 src/sys/kern/kern_exec.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/kern

2022-06-30 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Fri Jul  1 01:05:31 UTC 2022

Modified Files:
src/sys/kern: kern_exec.c

Log Message:
posix_spawn(2): Plug leak in proc_alloc error branch.


To generate a diff of this commit:
cvs rdiff -u -r1.517 -r1.518 src/sys/kern/kern_exec.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/kern/kern_exec.c
diff -u src/sys/kern/kern_exec.c:1.517 src/sys/kern/kern_exec.c:1.518
--- src/sys/kern/kern_exec.c:1.517	Sat Apr  9 23:38:33 2022
+++ src/sys/kern/kern_exec.c	Fri Jul  1 01:05:31 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: kern_exec.c,v 1.517 2022/04/09 23:38:33 riastradh Exp $	*/
+/*	$NetBSD: kern_exec.c,v 1.518 2022/07/01 01:05:31 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2008, 2019, 2020 The NetBSD Foundation, Inc.
@@ -62,7 +62,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: kern_exec.c,v 1.517 2022/04/09 23:38:33 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_exec.c,v 1.518 2022/07/01 01:05:31 riastradh Exp $");
 
 #include "opt_exec.h"
 #include "opt_execfmt.h"
@@ -2568,7 +2568,7 @@ do_posix_spawn(struct lwp *l1, pid_t *pi
 	struct lwp *l2;
 	int error;
 	struct spawn_exec_data *spawn_data;
-	vaddr_t uaddr;
+	vaddr_t uaddr = 0;
 	pid_t pid;
 	bool have_exec_lock = false;
 
@@ -2852,6 +2852,8 @@ do_posix_spawn(struct lwp *l1, pid_t *pi
 	}
 	mutex_exit(&spawn_data->sed_mtx_child);
 	spawn_exec_data_release(spawn_data);
+	if (uaddr != 0)
+		uvm_uarea_free(uaddr);
 
 	return error;
 }



CVS commit: src/sys/kern

2022-06-30 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Fri Jul  1 01:06:04 UTC 2022

Modified Files:
src/sys/kern: kern_lwp.c

Log Message:
kern: Fix comment about precondition of lwp_update_creds.


To generate a diff of this commit:
cvs rdiff -u -r1.250 -r1.251 src/sys/kern/kern_lwp.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/kern

2022-06-30 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Fri Jul  1 01:06:04 UTC 2022

Modified Files:
src/sys/kern: kern_lwp.c

Log Message:
kern: Fix comment about precondition of lwp_update_creds.


To generate a diff of this commit:
cvs rdiff -u -r1.250 -r1.251 src/sys/kern/kern_lwp.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/kern/kern_lwp.c
diff -u src/sys/kern/kern_lwp.c:1.250 src/sys/kern/kern_lwp.c:1.251
--- src/sys/kern/kern_lwp.c:1.250	Sun May 22 11:27:36 2022
+++ src/sys/kern/kern_lwp.c	Fri Jul  1 01:06:04 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: kern_lwp.c,v 1.250 2022/05/22 11:27:36 andvar Exp $	*/
+/*	$NetBSD: kern_lwp.c,v 1.251 2022/07/01 01:06:04 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2001, 2006, 2007, 2008, 2009, 2019, 2020
@@ -217,7 +217,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: kern_lwp.c,v 1.250 2022/05/22 11:27:36 andvar Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_lwp.c,v 1.251 2022/07/01 01:06:04 riastradh Exp $");
 
 #include "opt_ddb.h"
 #include "opt_lockdebug.h"
@@ -1532,7 +1532,7 @@ lwp_find(struct proc *p, lwpid_t id)
  * This happens early in the syscall path, on user trap, and on LWP
  * creation.  A long-running LWP can also voluntarily choose to update
  * its credentials by calling this routine.  This may be called from
- * LWP_CACHE_CREDS(), which checks l->l_cred != p->p_cred beforehand.
+ * LWP_CACHE_CREDS(), which checks l->l_prflag & LPR_CRMOD beforehand.
  */
 void
 lwp_update_creds(struct lwp *l)



CVS commit: src/sys/dev/usb

2022-06-30 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Fri Jul  1 01:06:31 UTC 2022

Modified Files:
src/sys/dev/usb: uvideo.c

Log Message:
uvideo(4): Assert number of units can't overflow.

Not sure if this is true, but at least we'll trap instead of silently
undercount this way.


To generate a diff of this commit:
cvs rdiff -u -r1.81 -r1.82 src/sys/dev/usb/uvideo.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/dev/usb

2022-06-30 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Fri Jul  1 01:06:31 UTC 2022

Modified Files:
src/sys/dev/usb: uvideo.c

Log Message:
uvideo(4): Assert number of units can't overflow.

Not sure if this is true, but at least we'll trap instead of silently
undercount this way.


To generate a diff of this commit:
cvs rdiff -u -r1.81 -r1.82 src/sys/dev/usb/uvideo.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/usb/uvideo.c
diff -u src/sys/dev/usb/uvideo.c:1.81 src/sys/dev/usb/uvideo.c:1.82
--- src/sys/dev/usb/uvideo.c:1.81	Sat May 14 15:29:08 2022
+++ src/sys/dev/usb/uvideo.c	Fri Jul  1 01:06:31 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: uvideo.c,v 1.81 2022/05/14 15:29:08 riastradh Exp $	*/
+/*	$NetBSD: uvideo.c,v 1.82 2022/07/01 01:06:31 riastradh Exp $	*/
 
 /*
  * Copyright (c) 2008 Patrick Mahoney
@@ -42,7 +42,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: uvideo.c,v 1.81 2022/05/14 15:29:08 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uvideo.c,v 1.82 2022/07/01 01:06:31 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -811,6 +811,7 @@ uvideo_init_control(struct uvideo_softc 
 		if (uvdesc->bDescriptorSubtype < UDESC_INPUT_TERMINAL ||
 		uvdesc->bDescriptorSubtype > UDESC_EXTENSION_UNIT)
 			continue;
+		KASSERT(nunits < 255);
 		++nunits;
 	}
 
@@ -843,6 +844,7 @@ uvideo_init_control(struct uvideo_softc 
 		/* TODO: free other units before returning? */
 		if (sc->sc_unit[i] == NULL)
 			goto enomem;
+		KASSERT(i < 255);
 		++i;
 	}
 



CVS commit: src/sys/kern

2022-06-30 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Fri Jul  1 01:06:40 UTC 2022

Modified Files:
src/sys/kern: kern_proc.c

Log Message:
kern: Omit stale locking comment in proc_crmod_leave.


To generate a diff of this commit:
cvs rdiff -u -r1.267 -r1.268 src/sys/kern/kern_proc.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/kern

2022-06-30 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Fri Jul  1 01:06:40 UTC 2022

Modified Files:
src/sys/kern: kern_proc.c

Log Message:
kern: Omit stale locking comment in proc_crmod_leave.


To generate a diff of this commit:
cvs rdiff -u -r1.267 -r1.268 src/sys/kern/kern_proc.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/kern/kern_proc.c
diff -u src/sys/kern/kern_proc.c:1.267 src/sys/kern/kern_proc.c:1.268
--- src/sys/kern/kern_proc.c:1.267	Sat May  7 19:44:40 2022
+++ src/sys/kern/kern_proc.c	Fri Jul  1 01:06:40 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: kern_proc.c,v 1.267 2022/05/07 19:44:40 mrg Exp $	*/
+/*	$NetBSD: kern_proc.c,v 1.268 2022/07/01 01:06:40 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 1999, 2006, 2007, 2008, 2020 The NetBSD Foundation, Inc.
@@ -62,7 +62,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: kern_proc.c,v 1.267 2022/05/07 19:44:40 mrg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_proc.c,v 1.268 2022/07/01 01:06:40 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_kstack.h"
@@ -1826,8 +1826,7 @@ proc_crmod_enter(void)
 /*
  * Set in a new process credential, and drop the write lock.  The credential
  * must have a reference already.  Optionally, free a no-longer required
- * credential.  The scheduler also needs to inspect p_cred, so we also
- * briefly acquire the sched state mutex.
+ * credential.
  */
 void
 proc_crmod_leave(kauth_cred_t scred, kauth_cred_t fcred, bool sugid)



CVS commit: src/sys/dev/usb

2022-06-30 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Fri Jul  1 01:06:51 UTC 2022

Modified Files:
src/sys/dev/usb: uvideo.c

Log Message:
uvideo(4): Make alloc logic match free logic.

Reported-by: syzbot+57cdc1be653327f78...@syzkaller.appspotmail.com

PR kern/53734


To generate a diff of this commit:
cvs rdiff -u -r1.82 -r1.83 src/sys/dev/usb/uvideo.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/dev/usb

2022-06-30 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Fri Jul  1 01:06:51 UTC 2022

Modified Files:
src/sys/dev/usb: uvideo.c

Log Message:
uvideo(4): Make alloc logic match free logic.

Reported-by: syzbot+57cdc1be653327f78...@syzkaller.appspotmail.com

PR kern/53734


To generate a diff of this commit:
cvs rdiff -u -r1.82 -r1.83 src/sys/dev/usb/uvideo.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/usb/uvideo.c
diff -u src/sys/dev/usb/uvideo.c:1.82 src/sys/dev/usb/uvideo.c:1.83
--- src/sys/dev/usb/uvideo.c:1.82	Fri Jul  1 01:06:31 2022
+++ src/sys/dev/usb/uvideo.c	Fri Jul  1 01:06:51 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: uvideo.c,v 1.82 2022/07/01 01:06:31 riastradh Exp $	*/
+/*	$NetBSD: uvideo.c,v 1.83 2022/07/01 01:06:51 riastradh Exp $	*/
 
 /*
  * Copyright (c) 2008 Patrick Mahoney
@@ -42,7 +42,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: uvideo.c,v 1.82 2022/07/01 01:06:31 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uvideo.c,v 1.83 2022/07/01 01:06:51 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -300,11 +300,11 @@ static struct uvideo_unit *	uvideo_unit_
 static usbd_status		uvideo_unit_init(struct uvideo_unit *,
 		 const uvideo_descriptor_t *);
 static void			uvideo_unit_free(struct uvideo_unit *);
-static usbd_status		uvideo_unit_alloc_controls(struct uvideo_unit *,
+static void			uvideo_unit_alloc_controls(struct uvideo_unit *,
 			   uint8_t,
 			   const uint8_t *);
 static void			uvideo_unit_free_controls(struct uvideo_unit *);
-static usbd_status		uvideo_unit_alloc_sources(struct uvideo_unit *,
+static void			uvideo_unit_alloc_sources(struct uvideo_unit *,
 			  uint8_t,
 			  const uint8_t *);
 static void			uvideo_unit_free_sources(struct uvideo_unit *);
@@ -991,12 +991,12 @@ uvideo_unit_free(struct uvideo_unit *vu)
 	kmem_free(vu, sizeof(*vu));
 }
 
-static usbd_status
+static void
 uvideo_unit_alloc_sources(struct uvideo_unit *vu,
 			  uint8_t nsrcs, const uint8_t *src_ids)
 {
-	vu->vu_nsrcs = nsrcs;
 
+	vu->vu_nsrcs = nsrcs;
 	if (nsrcs == 0) {
 		/* do nothing */
 	} else if (nsrcs == 1) {
@@ -1006,41 +1006,43 @@ uvideo_unit_alloc_sources(struct uvideo_
 		kmem_alloc(sizeof(*vu->s.vu_src_id_ary) * nsrcs, KM_SLEEP);
 		memcpy(vu->s.vu_src_id_ary, src_ids, nsrcs);
 	}
-
-	return USBD_NORMAL_COMPLETION;
 }
 
 static void
 uvideo_unit_free_sources(struct uvideo_unit *vu)
 {
-	if (vu->vu_nsrcs == 1)
+
+	if (vu->vu_nsrcs <= 1)
 		return;
 
 	kmem_free(vu->s.vu_src_id_ary,
-		  sizeof(*vu->s.vu_src_id_ary) * vu->vu_nsrcs);
-	vu->vu_nsrcs = 0;
+	sizeof(*vu->s.vu_src_id_ary) * vu->vu_nsrcs);
 	vu->s.vu_src_id_ary = NULL;
+	vu->vu_nsrcs = 0;
 }
 
-static usbd_status
+static void
 uvideo_unit_alloc_controls(struct uvideo_unit *vu, uint8_t size,
 			   const uint8_t *controls)
 {
+
+	vu->vu_control_size = size;
 	if (size == 0)
-		return USBD_INVAL;
+		return;
 
 	vu->vu_controls = kmem_alloc(sizeof(*vu->vu_controls) * size, KM_SLEEP);
-	vu->vu_control_size = size;
 	memcpy(vu->vu_controls, controls, size);
-
-	return USBD_NORMAL_COMPLETION;
 }
 
 static void
 uvideo_unit_free_controls(struct uvideo_unit *vu)
 {
+
+	if (vu->vu_control_size == 0)
+		return;
+
 	kmem_free(vu->vu_controls,
-		  sizeof(*vu->vu_controls) * vu->vu_control_size);
+	sizeof(*vu->vu_controls) * vu->vu_control_size);
 	vu->vu_controls = NULL;
 	vu->vu_control_size = 0;
 }



CVS commit: src/sys/dev/usb

2022-06-30 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Fri Jul  1 01:07:32 UTC 2022

Modified Files:
src/sys/dev/usb: if_upgt.c

Log Message:
upgt(4): Make upgt_free_cmd match upgt_alloc_cmd.

Reported-by: syzbot+365e26863f286c667...@syzkaller.appspotmail.com


To generate a diff of this commit:
cvs rdiff -u -r1.32 -r1.33 src/sys/dev/usb/if_upgt.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/dev/usb

2022-06-30 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Fri Jul  1 01:07:32 UTC 2022

Modified Files:
src/sys/dev/usb: if_upgt.c

Log Message:
upgt(4): Make upgt_free_cmd match upgt_alloc_cmd.

Reported-by: syzbot+365e26863f286c667...@syzkaller.appspotmail.com


To generate a diff of this commit:
cvs rdiff -u -r1.32 -r1.33 src/sys/dev/usb/if_upgt.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/usb/if_upgt.c
diff -u src/sys/dev/usb/if_upgt.c:1.32 src/sys/dev/usb/if_upgt.c:1.33
--- src/sys/dev/usb/if_upgt.c:1.32	Sat Aug 21 11:55:25 2021
+++ src/sys/dev/usb/if_upgt.c	Fri Jul  1 01:07:32 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_upgt.c,v 1.32 2021/08/21 11:55:25 andvar Exp $	*/
+/*	$NetBSD: if_upgt.c,v 1.33 2022/07/01 01:07:32 riastradh Exp $	*/
 /*	$OpenBSD: if_upgt.c,v 1.49 2010/04/20 22:05:43 tedu Exp $ */
 
 /*
@@ -18,7 +18,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_upgt.c,v 1.32 2021/08/21 11:55:25 andvar Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_upgt.c,v 1.33 2022/07/01 01:07:32 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -2374,13 +2374,14 @@ upgt_free_cmd(struct upgt_softc *sc)
 {
 	struct upgt_data *data_cmd = &sc->cmd_data;
 
-	if (data_cmd->xfer != NULL) {
-		usbd_destroy_xfer(data_cmd->xfer);
-		data_cmd->xfer = NULL;
-	}
+	if (data_cmd->xfer == NULL)
+		return;
 
 	mutex_destroy(&sc->sc_mtx);
 	cv_destroy(&sc->sc_cv);
+
+	usbd_destroy_xfer(data_cmd->xfer);
+	data_cmd->xfer = NULL;
 }
 
 static int



CVS commit: src/sys/kern

2022-06-30 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Fri Jul  1 01:07:57 UTC 2022

Modified Files:
src/sys/kern: kern_ktrace.c

Log Message:
ktrace(9): Zero-initialize padding for ktr_psig records.

Reported-by: syzbot+03fbfa20e6c7a3919...@syzkaller.appspotmail.com


To generate a diff of this commit:
cvs rdiff -u -r1.181 -r1.182 src/sys/kern/kern_ktrace.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/kern

2022-06-30 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Fri Jul  1 01:07:57 UTC 2022

Modified Files:
src/sys/kern: kern_ktrace.c

Log Message:
ktrace(9): Zero-initialize padding for ktr_psig records.

Reported-by: syzbot+03fbfa20e6c7a3919...@syzkaller.appspotmail.com


To generate a diff of this commit:
cvs rdiff -u -r1.181 -r1.182 src/sys/kern/kern_ktrace.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/kern/kern_ktrace.c
diff -u src/sys/kern/kern_ktrace.c:1.181 src/sys/kern/kern_ktrace.c:1.182
--- src/sys/kern/kern_ktrace.c:1.181	Wed Jun 29 22:10:43 2022
+++ src/sys/kern/kern_ktrace.c	Fri Jul  1 01:07:56 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: kern_ktrace.c,v 1.181 2022/06/29 22:10:43 riastradh Exp $	*/
+/*	$NetBSD: kern_ktrace.c,v 1.182 2022/07/01 01:07:56 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2006, 2007, 2008, 2020 The NetBSD Foundation, Inc.
@@ -61,7 +61,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: kern_ktrace.c,v 1.181 2022/06/29 22:10:43 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_ktrace.c,v 1.182 2022/07/01 01:07:56 riastradh Exp $");
 
 #include 
 #include 
@@ -790,6 +790,7 @@ ktr_psig(int sig, sig_t action, const si
 	if (ktealloc(&kte, (void *)&kbuf, l, KTR_PSIG, sizeof(*kbuf)))
 		return;
 
+	memset(&kbuf->kp, 0, sizeof(kbuf->kp));
 	kbuf->kp.signo = (char)sig;
 	kbuf->kp.action = action;
 	kbuf->kp.mask = *mask;



CVS commit: src/sys/dev/usb

2022-06-30 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Fri Jul  1 01:08:06 UTC 2022

Modified Files:
src/sys/dev/usb: umidi.c

Log Message:
umidi(4): Clarify loops.  No functional change intended.


To generate a diff of this commit:
cvs rdiff -u -r1.88 -r1.89 src/sys/dev/usb/umidi.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/dev/usb

2022-06-30 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Fri Jul  1 01:08:06 UTC 2022

Modified Files:
src/sys/dev/usb: umidi.c

Log Message:
umidi(4): Clarify loops.  No functional change intended.


To generate a diff of this commit:
cvs rdiff -u -r1.88 -r1.89 src/sys/dev/usb/umidi.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/usb/umidi.c
diff -u src/sys/dev/usb/umidi.c:1.88 src/sys/dev/usb/umidi.c:1.89
--- src/sys/dev/usb/umidi.c:1.88	Mon Jun 27 18:56:56 2022
+++ src/sys/dev/usb/umidi.c	Fri Jul  1 01:08:06 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: umidi.c,v 1.88 2022/06/27 18:56:56 riastradh Exp $	*/
+/*	$NetBSD: umidi.c,v 1.89 2022/07/01 01:08:06 riastradh Exp $	*/
 
 /*
  * Copyright (c) 2001, 2012, 2014 The NetBSD Foundation, Inc.
@@ -32,7 +32,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: umidi.c,v 1.88 2022/06/27 18:56:56 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: umidi.c,v 1.89 2022/07/01 01:08:06 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -724,8 +724,7 @@ static usbd_status
 alloc_all_endpoints(struct umidi_softc *sc)
 {
 	usbd_status err;
-	struct umidi_endpoint *ep;
-	int i;
+	int i, n;
 
 	if (UMQ_ISTYPE(sc, UMQ_TYPE_FIXED_EP)) {
 		err = alloc_all_endpoints_fixed_ep(sc);
@@ -737,17 +736,16 @@ alloc_all_endpoints(struct umidi_softc *
 	if (err != USBD_NORMAL_COMPLETION)
 		return err;
 
-	ep = sc->sc_endpoints;
-	for (i = sc->sc_out_num_endpoints+sc->sc_in_num_endpoints; i > 0; i--) {
-		err = alloc_pipe(ep);
+	n = sc->sc_out_num_endpoints + sc->sc_in_num_endpoints;
+	for (i = 0; i < n; i++) {
+		err = alloc_pipe(&sc->sc_endpoints[i]);
 		if (err != USBD_NORMAL_COMPLETION) {
-			for (; ep != sc->sc_endpoints; ep--)
-free_pipe(ep-1);
+			while (i --> 0)
+free_pipe(&sc->sc_endpoints[i]);
 			kmem_free(sc->sc_endpoints, sc->sc_endpoints_len);
 			sc->sc_endpoints = sc->sc_out_ep = sc->sc_in_ep = NULL;
 			break;
 		}
-		ep++;
 	}
 	return err;
 }
@@ -755,14 +753,15 @@ alloc_all_endpoints(struct umidi_softc *
 static void
 free_all_endpoints(struct umidi_softc *sc)
 {
-	int i;
+	int i, n;
 
 	if (sc->sc_endpoints == NULL) {
 		/* nothing to free */
 		return;
 	}
 
-	for (i=0; isc_in_num_endpoints+sc->sc_out_num_endpoints; i++)
+	n = sc->sc_in_num_endpoints + sc->sc_out_num_endpoints;
+	for (i = 0; i < n; i++)
 		free_pipe(&sc->sc_endpoints[i]);
 	kmem_free(sc->sc_endpoints, sc->sc_endpoints_len);
 	sc->sc_endpoints = sc->sc_out_ep = sc->sc_in_ep = NULL;