git: 648ce75c3b55 - stable/13 - netgraph: Remove the rethook parameter from NG_NODE_FOREACH_HOOK.

From: John Baldwin <jhb_at_FreeBSD.org>
Date: Fri, 13 May 2022 22:54:53 UTC
The branch stable/13 has been updated by jhb:

URL: https://cgit.FreeBSD.org/src/commit/?id=648ce75c3b55c7afc0e56e76e9a6aa9f2370bae1

commit 648ce75c3b55c7afc0e56e76e9a6aa9f2370bae1
Author:     John Baldwin <jhb@FreeBSD.org>
AuthorDate: 2022-04-12 21:58:59 +0000
Commit:     John Baldwin <jhb@FreeBSD.org>
CommitDate: 2022-05-13 20:13:49 +0000

    netgraph: Remove the rethook parameter from NG_NODE_FOREACH_HOOK.
    
    This parameter was set to the hook that terminated the iteration
    early.  However, none of the remaining callers used this argument and
    it was always set to an otherwise-unused variable.
    
    (cherry picked from commit 6d5f002ed1187547b0b40f8b46a3db38bf89c6dc)
---
 sys/netgraph/netgraph.h  | 22 ++++++++--------------
 sys/netgraph/ng_bpf.c    |  6 ++----
 sys/netgraph/ng_bridge.c | 11 +++--------
 sys/netgraph/ng_l2tp.c   |  3 +--
 4 files changed, 14 insertions(+), 28 deletions(-)

diff --git a/sys/netgraph/netgraph.h b/sys/netgraph/netgraph.h
index 9cc298b38236..d63ea6116fc9 100644
--- a/sys/netgraph/netgraph.h
+++ b/sys/netgraph/netgraph.h
@@ -429,13 +429,11 @@ void	ng_unref_node(node_p node); /* don't move this */
  * iterator will stop and return a pointer to the hook that returned 0.
  */
 typedef	int	ng_fn_eachhook(hook_p hook, void* arg);
-#define _NG_NODE_FOREACH_HOOK(node, fn, arg, rethook)			\
+#define _NG_NODE_FOREACH_HOOK(node, fn, arg)				\
 	do {								\
 		hook_p _hook;						\
-		(rethook) = NULL;					\
 		LIST_FOREACH(_hook, &((node)->nd_hooks), hk_hooks) {	\
 			if ((fn)(_hook, arg) == 0) {			\
-				(rethook) = _hook;			\
 				break;					\
 			}						\
 		}							\
@@ -456,7 +454,7 @@ static __inline int _ng_node_is_valid(node_p node, char *file, int line);
 static __inline int _ng_node_not_valid(node_p node, char *file, int line);
 static __inline int _ng_node_numhooks(node_p node, char *file, int line);
 static __inline void _ng_node_force_writer(node_p node, char *file, int line);
-static __inline hook_p _ng_node_foreach_hook(node_p node,
+static __inline void _ng_node_foreach_hook(node_p node,
 			ng_fn_eachhook *fn, void *arg, char *file, int line);
 static __inline void _ng_node_revive(node_p node, char *file, int line);
 
@@ -569,14 +567,12 @@ _ng_node_revive(node_p node, char *file, int line)
 	_NG_NODE_REVIVE(node);
 }
 
-static __inline hook_p
+static __inline void
 _ng_node_foreach_hook(node_p node, ng_fn_eachhook *fn, void *arg,
 						char *file, int line)
 {
-	hook_p hook;
 	_chknode(node, file, line);
-	_NG_NODE_FOREACH_HOOK(node, fn, arg, hook);
-	return (hook);
+	_NG_NODE_FOREACH_HOOK(node, fn, arg);
 }
 
 #define NG_NODE_NAME(node)		_ng_node_name(node, _NN_)	
@@ -593,10 +589,8 @@ _ng_node_foreach_hook(node_p node, ng_fn_eachhook *fn, void *arg,
 #define NG_NODE_REALLY_DIE(node) 	_ng_node_really_die(node, _NN_)
 #define NG_NODE_NUMHOOKS(node)		_ng_node_numhooks(node, _NN_)
 #define NG_NODE_REVIVE(node)		_ng_node_revive(node, _NN_)
-#define NG_NODE_FOREACH_HOOK(node, fn, arg, rethook)			      \
-	do {								      \
-		rethook = _ng_node_foreach_hook(node, fn, (void *)arg, _NN_); \
-	} while (0)
+#define NG_NODE_FOREACH_HOOK(node, fn, arg)				\
+	_ng_node_foreach_hook(node, fn, (void *)arg, _NN_)
 
 #else	/* NETGRAPH_DEBUG */ /*----------------------------------------------*/
 
@@ -614,8 +608,8 @@ _ng_node_foreach_hook(node_p node, ng_fn_eachhook *fn, void *arg,
 #define NG_NODE_REALLY_DIE(node) 	_NG_NODE_REALLY_DIE(node)
 #define NG_NODE_NUMHOOKS(node)		_NG_NODE_NUMHOOKS(node)	
 #define NG_NODE_REVIVE(node)		_NG_NODE_REVIVE(node)
-#define NG_NODE_FOREACH_HOOK(node, fn, arg, rethook)			\
-		_NG_NODE_FOREACH_HOOK(node, fn, arg, rethook)
+#define NG_NODE_FOREACH_HOOK(node, fn, arg)				\
+	_NG_NODE_FOREACH_HOOK(node, fn, arg)
 #endif	/* NETGRAPH_DEBUG */ /*----------------------------------------------*/
 
 /***********************************************************************
diff --git a/sys/netgraph/ng_bpf.c b/sys/netgraph/ng_bpf.c
index b9535c7c124d..26e4c1f64d5b 100644
--- a/sys/netgraph/ng_bpf.c
+++ b/sys/netgraph/ng_bpf.c
@@ -273,7 +273,6 @@ static int
 ng_bpf_newhook(node_p node, hook_p hook, const char *name)
 {
 	hinfo_p hip;
-	hook_p tmp;
 	int error;
 
 	/* Create hook private structure */
@@ -284,7 +283,7 @@ ng_bpf_newhook(node_p node, hook_p hook, const char *name)
 	NG_HOOK_SET_PRIVATE(hook, hip);
 
 	/* Add our reference into other hooks data. */
-	NG_NODE_FOREACH_HOOK(node, ng_bpf_addrefs, hook, tmp);
+	NG_NODE_FOREACH_HOOK(node, ng_bpf_addrefs, hook);
 
 	/* Attach the default BPF program */
 	if ((error = ng_bpf_setprog(hook, &ng_bpf_default_prog)) != 0) {
@@ -524,12 +523,11 @@ ng_bpf_disconnect(hook_p hook)
 {
 	const node_p node = NG_HOOK_NODE(hook);
 	const hinfo_p hip = NG_HOOK_PRIVATE(hook);
-	hook_p tmp;
 
 	KASSERT(hip != NULL, ("%s: null info", __func__));
 
 	/* Remove our reference from other hooks data. */
-	NG_NODE_FOREACH_HOOK(node, ng_bpf_remrefs, hook, tmp);
+	NG_NODE_FOREACH_HOOK(node, ng_bpf_remrefs, hook);
 
 	free(hip->prog, M_NETGRAPH_BPF);
 #ifdef BPF_JITTER
diff --git a/sys/netgraph/ng_bridge.c b/sys/netgraph/ng_bridge.c
index 9bcc7aac271b..07564ad1297e 100644
--- a/sys/netgraph/ng_bridge.c
+++ b/sys/netgraph/ng_bridge.c
@@ -601,14 +601,11 @@ ng_bridge_rcvmsg(node_p node, item_p item, hook_p lasthook)
 		    }
 		case NGM_BRIDGE_RESET:
 		    {
-			hook_p rethook;
-
 			/* Flush all entries in the hash table */
 			ng_bridge_remove_hosts(priv, NULL);
 
 			/* Reset all loop detection counters and stats */
-			NG_NODE_FOREACH_HOOK(node, ng_bridge_reset_link, NULL,
-			    rethook);
+			NG_NODE_FOREACH_HOOK(node, ng_bridge_reset_link, NULL);
 			break;
 		    }
 		case NGM_BRIDGE_GET_STATS:
@@ -844,7 +841,6 @@ ng_bridge_rcvdata(hook_p hook, item_p item)
 	struct ng_bridge_host *host;
 	struct ether_header *eh;
 	struct ng_bridge_send_ctx ctx = { 0 };
-	hook_p ret;
 
 	NGI_GET_M(item, ctx.m);
 
@@ -963,7 +959,7 @@ ng_bridge_rcvdata(hook_p hook, item_p item)
 	}
 
 	/* Distribute unknown, multicast, broadcast pkts to all other links */
-	NG_NODE_FOREACH_HOOK(node, ng_bridge_send_ctx, &ctx, ret);
+	NG_NODE_FOREACH_HOOK(node, ng_bridge_send_ctx, &ctx);
 
 	/* Finally send out on the first link found */
 	if (ctx.foundFirst != NULL) {
@@ -1235,7 +1231,6 @@ ng_bridge_timeout(node_p node, hook_p hook, void *arg1, int arg2)
 	const priv_p priv = NG_NODE_PRIVATE(node);
 	int bucket;
 	int counter = 0;
-	hook_p ret;
 
 	/* Update host time counters and remove stale entries */
 	for (bucket = 0; bucket < priv->numBuckets; bucket++) {
@@ -1265,7 +1260,7 @@ ng_bridge_timeout(node_p node, hook_p hook, void *arg1, int arg2)
 
 	/* Decrease loop counter on muted looped back links */
 	counter = 0;
-	NG_NODE_FOREACH_HOOK(node, ng_bridge_unmute, &counter, ret);
+	NG_NODE_FOREACH_HOOK(node, ng_bridge_unmute, &counter);
 	KASSERT(priv->numLinks == counter,
 	    ("%s: links: %d != %d", __func__, priv->numLinks, counter));
 
diff --git a/sys/netgraph/ng_l2tp.c b/sys/netgraph/ng_l2tp.c
index 94617fa4dad9..edb38e4540da 100644
--- a/sys/netgraph/ng_l2tp.c
+++ b/sys/netgraph/ng_l2tp.c
@@ -1263,7 +1263,6 @@ static void
 ng_l2tp_seq_reset(priv_p priv)
 {
 	struct l2tp_seq *const seq = &priv->seq;
-	hook_p hook;
 	int i;
 
 	SEQ_LOCK_ASSERT(seq);
@@ -1280,7 +1279,7 @@ ng_l2tp_seq_reset(priv_p priv)
 	}
 
 	/* Reset session hooks' sequence number states */
-	NG_NODE_FOREACH_HOOK(priv->node, ng_l2tp_reset_session, NULL, hook);
+	NG_NODE_FOREACH_HOOK(priv->node, ng_l2tp_reset_session, NULL);
 
 	/* Reset node's sequence number state */
 	seq->ns = 0;