From a84315c055cf9ce84e6e40fd4beda5d39b6dc6ac Mon Sep 17 00:00:00 2001
From: Sascha Wildner <saw@online.de>
Date: Sun, 8 Jun 2014 11:35:56 +0200
Subject: [PATCH 2/2] kernel: Add more missing crit_exit, lwkt_reltoken, etc.

---
 sys/bus/firewire/firewire.c       | 1 +
 sys/dev/raid/aac/aac.c            | 5 +++--
 sys/dev/raid/dpt/dpt_pci.c        | 1 +
 sys/emulation/linux/linux_stats.c | 8 ++++++--
 sys/netinet/ip_input.c            | 1 +
 sys/netinet/sctp_output.c         | 6 +++++-
 sys/netproto/ipsec/xform_ah.c     | 7 +++++--
 sys/vfs/hammer2/hammer2_vfsops.c  | 2 ++
 8 files changed, 24 insertions(+), 7 deletions(-)

diff --git a/sys/bus/firewire/firewire.c b/sys/bus/firewire/firewire.c
index 81139fa..02204fa 100644
--- a/sys/bus/firewire/firewire.c
+++ b/sys/bus/firewire/firewire.c
@@ -1884,6 +1884,7 @@ fw_rcv(struct fw_rcv_buf *rb)
 			rb->xfer = STAILQ_FIRST(&bind->xferlist);
 			if (rb->xfer == NULL) {
 				kprintf("Discard packet for this bind\n");
+				crit_exit();
 				goto err;
 			}
 			STAILQ_REMOVE_HEAD(&bind->xferlist, link);
diff --git a/sys/dev/raid/aac/aac.c b/sys/dev/raid/aac/aac.c
index cc47779..2997d33 100644
--- a/sys/dev/raid/aac/aac.c
+++ b/sys/dev/raid/aac/aac.c
@@ -2953,16 +2953,17 @@ aac_filter_read(struct knote *kn, long hint)
 {
 	struct aac_softc *sc;
 	struct aac_fib_context *ctx;
+	int ret = 0;
 
 	sc = (struct aac_softc *)kn->kn_hook;
 
 	lockmgr(&sc->aac_aifq_lock, LK_EXCLUSIVE);
 	for (ctx = sc->fibctx; ctx; ctx = ctx->next)
 		if (ctx->ctx_idx != sc->aifq_idx || ctx->ctx_wrap)
-			return(1);
+			ret = 1;
 	lockmgr(&sc->aac_aifq_lock, LK_RELEASE);
 
-	return (0);
+	return(ret);
 }
 
 static void
diff --git a/sys/dev/raid/dpt/dpt_pci.c b/sys/dev/raid/dpt/dpt_pci.c
index f0bc443..0c46373 100644
--- a/sys/dev/raid/dpt/dpt_pci.c
+++ b/sys/dev/raid/dpt/dpt_pci.c
@@ -153,6 +153,7 @@ dpt_pci_attach (device_t dev)
 	if (dpt_init(dpt) != 0) {
 		dpt_free(dpt);
 		error = ENXIO;
+		crit_exit();
 		goto bad;
 	}
 
diff --git a/sys/emulation/linux/linux_stats.c b/sys/emulation/linux/linux_stats.c
index 3794e0b..f6ae2f5 100644
--- a/sys/emulation/linux/linux_stats.c
+++ b/sys/emulation/linux/linux_stats.c
@@ -311,10 +311,14 @@ sys_linux_fstatfs(struct linux_fstatfs_args *args)
 		kprintf(ARGS(fstatfs, "%d, *"), args->fd);
 #endif
 	get_mplock();
-	if ((error = kern_fstatfs(args->fd, &statfs)) != 0)
+	if ((error = kern_fstatfs(args->fd, &statfs)) != 0) {
+		rel_mplock();
 		return (error);
-	if ((error = holdvnode(p->p_fd, args->fd, &fp)) != 0)
+	}
+	if ((error = holdvnode(p->p_fd, args->fd, &fp)) != 0) {
+		rel_mplock();
 		return (error);
+	}
 	error = vn_get_namelen((struct vnode *)fp->f_data, &namelen);
 	rel_mplock();
 	fdrop(fp);
diff --git a/sys/netinet/ip_input.c b/sys/netinet/ip_input.c
index 8682e19..ae30b42 100644
--- a/sys/netinet/ip_input.c
+++ b/sys/netinet/ip_input.c
@@ -924,6 +924,7 @@ ours:
 			/* XXX error stat??? */
 			error = EINVAL;
 DPRINTF(("ip_input: no SP, packet discarded\n"));/*XXX*/
+			crit_exit();
 			goto bad;
 		}
 		crit_exit();
diff --git a/sys/netinet/sctp_output.c b/sys/netinet/sctp_output.c
index d690300..177599d 100644
--- a/sys/netinet/sctp_output.c
+++ b/sys/netinet/sctp_output.c
@@ -9544,8 +9544,10 @@ sctp_copy_it_in(struct sctp_inpcb *inp,
 	/* lock the socket buf */
 	SOCKBUF_LOCK(&so->so_snd);
 	error = ssb_lock(&so->so_snd, SBLOCKWAIT(flags));
-	if (error)
+	if (error) {
+		crit_exit();
 		goto out_locked;
+	}
 
 	/* will it ever fit ? */
 	if (sndlen > so->so_snd.ssb_hiwat) {
@@ -9582,6 +9584,7 @@ sctp_copy_it_in(struct sctp_inpcb *inp,
 			if (flags & (MSG_FNONBLOCKING|MSG_DONTWAIT)) {
 				/* Non-blocking io in place */
 				error = EWOULDBLOCK;
+				crit_exit();
 				goto release;
 			}
 			inp->sctp_tcb_at_block = (void *)stcb;
@@ -9599,6 +9602,7 @@ sctp_copy_it_in(struct sctp_inpcb *inp,
 				/* Should I really unlock ? */
 				SCTP_INP_RUNLOCK(inp);
 				error = EFAULT;
+				crit_exit();
 				goto out_locked;
 			}
 			SCTP_TCB_LOCK(stcb);
diff --git a/sys/netproto/ipsec/xform_ah.c b/sys/netproto/ipsec/xform_ah.c
index f92e7ab..512211a 100644
--- a/sys/netproto/ipsec/xform_ah.c
+++ b/sys/netproto/ipsec/xform_ah.c
@@ -770,8 +770,11 @@ ah_input_cb(struct cryptop *crp)
 		if (sav->tdb_cryptoid != 0)
 			sav->tdb_cryptoid = crp->crp_sid;
 
-		if (crp->crp_etype == EAGAIN)
-			return crypto_dispatch(crp);
+		if (crp->crp_etype == EAGAIN) {
+			error = crypto_dispatch(crp);
+			crit_exit();
+			return(error);
+		}
 
 		ahstat.ahs_noxform++;
 		DPRINTF(("ah_input_cb: crypto error %d\n", crp->crp_etype));
diff --git a/sys/vfs/hammer2/hammer2_vfsops.c b/sys/vfs/hammer2/hammer2_vfsops.c
index fde2052..c2fdb42 100644
--- a/sys/vfs/hammer2/hammer2_vfsops.c
+++ b/sys/vfs/hammer2/hammer2_vfsops.c
@@ -578,6 +578,7 @@ hammer2_vfs_mount(struct mount *mp, char *path, caddr_t data,
 			++hmp->pmp_count;
 			hammer2_vfs_unmount_hmp1(mp, hmp);
 			hammer2_vfs_unmount_hmp2(mp, hmp);
+			lockmgr(&hammer2_mntlk, LK_RELEASE);
 			hammer2_vfs_unmount(mp, MNT_FORCE);
 			return error;
 		}
@@ -623,6 +624,7 @@ hammer2_vfs_mount(struct mount *mp, char *path, caddr_t data,
 			++hmp->pmp_count;
 			hammer2_vfs_unmount_hmp1(mp, hmp);
 			hammer2_vfs_unmount_hmp2(mp, hmp);
+			lockmgr(&hammer2_mntlk, LK_RELEASE);
 			hammer2_vfs_unmount(mp, MNT_FORCE);
 			return EINVAL;
 		}
-- 
1.9.3

