Skip to contentSkip to conversation

net: pktgen: return bool from __pktgen_NN_threads()

PATCH Applied Chengfeng Ye 4 participants 4 messages Sep 27 – Sep 29

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 net: pktgen: return bool from __pktgen_NN_threads()

Callers of __pktgen_NN_threads() only check whether a pktgen_dev was found. Returning the pointer exposes it outside the helper even though neither caller uses the object itself.

Return bool instead and keep the pktgen_dev pointer internal to the helper.

---
Changes in v2:
- Rebase directly onto the current net-next tree, independently of the deferred RCU lifetime fix.
- Update the commit message for the current helper implementation.

---
 net/core/pktgen.c | 17 +++++++----------
 1 file changed, 7 insertions(+), 10 deletions(-)
net/core/pktgen.c +7 -10
index 7f81aed46672..a89cb0760821 100644
@@ -2024,11 +2024,11 @@ static const struct proc_ops pktgen_thread_proc_ops = {
 };
 
 /* Think find or remove for NN */
-static struct pktgen_dev *__pktgen_NN_threads(const struct pktgen_net *pn,
-					      const char *ifname, int remove)
+static bool __pktgen_NN_threads(const struct pktgen_net *pn,
+				const char *ifname, int remove)
 {
 	struct pktgen_thread *t;
-	struct pktgen_dev *pkt_dev = NULL;
+	struct pktgen_dev *pkt_dev;
 	bool exact = (remove == FIND);
 
 	list_for_each_entry(t, &pn->pktgen_threads, th_list) {
@@ -2038,10 +2038,10 @@ static struct pktgen_dev *__pktgen_NN_threads(const struct pktgen_net *pn,
 				pkt_dev->removal_mark = 1;
 				t->control |= T_REMDEV;
 			}
-			break;
+			return true;
 		}
 	}
-	return pkt_dev;
+	return false;
 }
 
 /*
@@ -2049,7 +2049,6 @@ static struct pktgen_dev *__pktgen_NN_threads(const struct pktgen_net *pn,
  */
 static void pktgen_mark_device(const struct pktgen_net *pn, const char *ifname)
 {
-	struct pktgen_dev *pkt_dev = NULL;
 	const int max_tries = 10, msec_per_try = 125;
 	int i = 0;
 
@@ -2058,8 +2057,7 @@ static void pktgen_mark_device(const struct pktgen_net *pn, const char *ifname)
 
 	while (1) {
 
-		pkt_dev = __pktgen_NN_threads(pn, ifname, REMOVE);
-		if (pkt_dev == NULL)
+		if (!__pktgen_NN_threads(pn, ifname, REMOVE))
 			break;	/* success */
 
 		mutex_unlock(&pktgen_thread_lock);
@@ -3835,8 +3833,7 @@ static int pktgen_add_device(struct pktgen_thread *t, const char *ifname)
 
 	/* We don't allow a device to be on several threads */
 
-	pkt_dev = __pktgen_NN_threads(t->net, ifname, FIND);
-	if (pkt_dev) {
+	if (__pktgen_NN_threads(t->net, ifname, FIND)) {
 		pr_err("ERROR: interface already used\n");
 		return -EBUSY;
 	}
Signature · 1 line
2.43.0
Reviewed-by on v2 1/1
#2 lore raw
In reply to Chengfeng Ye
Quoted 82 lines · Chengfeng Ye

Callers of __pktgen_NN_threads() only check whether a pktgen_dev was found. Returning the pointer exposes it outside the helper even though neither caller uses the object itself.

Return bool instead and keep the pktgen_dev pointer internal to the helper.

---
Changes in v2:
- Rebase directly onto the current net-next tree, independently of the deferred RCU lifetime fix.
- Update the commit message for the current helper implementation.

---
 net/core/pktgen.c | 17 +++++++----------
 1 file changed, 7 insertions(+), 10 deletions(-)
net/core/pktgen.c +7 -10
index 7f81aed46672..a89cb0760821 100644
@@ -2024,11 +2024,11 @@ static const struct proc_ops pktgen_thread_proc_ops = {
 };
 
 /* Think find or remove for NN */
-static struct pktgen_dev *__pktgen_NN_threads(const struct pktgen_net *pn,
-					      const char *ifname, int remove)
+static bool __pktgen_NN_threads(const struct pktgen_net *pn,
+				const char *ifname, int remove)
 {
 	struct pktgen_thread *t;
-	struct pktgen_dev *pkt_dev = NULL;
+	struct pktgen_dev *pkt_dev;
 	bool exact = (remove == FIND);
 
 	list_for_each_entry(t, &pn->pktgen_threads, th_list) {
@@ -2038,10 +2038,10 @@ static struct pktgen_dev *__pktgen_NN_threads(const struct pktgen_net *pn,
 				pkt_dev->removal_mark = 1;
 				t->control |= T_REMDEV;
 			}
-			break;
+			return true;
 		}
 	}
-	return pkt_dev;
+	return false;
 }
 
 /*
@@ -2049,7 +2049,6 @@ static struct pktgen_dev *__pktgen_NN_threads(const struct pktgen_net *pn,
  */
 static void pktgen_mark_device(const struct pktgen_net *pn, const char *ifname)
 {
-	struct pktgen_dev *pkt_dev = NULL;
 	const int max_tries = 10, msec_per_try = 125;
 	int i = 0;
 
@@ -2058,8 +2057,7 @@ static void pktgen_mark_device(const struct pktgen_net *pn, const char *ifname)
 
 	while (1) {
 
-		pkt_dev = __pktgen_NN_threads(pn, ifname, REMOVE);
-		if (pkt_dev == NULL)
+		if (!__pktgen_NN_threads(pn, ifname, REMOVE))
 			break;	/* success */
 
 		mutex_unlock(&pktgen_thread_lock);
@@ -3835,8 +3833,7 @@ static int pktgen_add_device(struct pktgen_thread *t, const char *ifname)
 
 	/* We don't allow a device to be on several threads */
 
-	pkt_dev = __pktgen_NN_threads(t->net, ifname, FIND);
-	if (pkt_dev) {
+	if (__pktgen_NN_threads(t->net, ifname, FIND)) {
 		pr_err("ERROR: interface already used\n");
 		return -EBUSY;
 	}
Signature · 1 line
2.43.0
#3 lore raw
In reply to Chengfeng Ye
This patch was applied to netdev/net-next.git (main) by Paolo Abeni <[email protected]>:

Hello:

This patch was applied to netdev/net-next.git (main) by Paolo Abeni <[email protected]>:

Quoted 8 lines · On Sun, 27 Sep 2026 21:54:05 +0800 you wrote:

Callers of __pktgen_NN_threads() only check whether a pktgen_dev was found. Returning the pointer exposes it outside the helper even though neither caller uses the object itself.

Return bool instead and keep the pktgen_dev pointer internal to the helper.

[...]

Here is the summary with links:
- [net-next,v2] net: pktgen: return bool from __pktgen_NN_threads()

    https://git.kernel.org/netdev/net-next/c/2a5043c8b7d0

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html