From: Chengfeng Ye <nicoyip.dev@gmail.com>
To: "David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Simon Horman <horms@kernel.org>
Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
Chengfeng Ye <nicoyip.dev@gmail.com>
Subject: [PATCH net-next] net: pktgen: return bool from __pktgen_NN_threads()
Date: Wed, 26 Aug 2026 02:53:13 +0800 [thread overview]
Message-ID: <20260825185313.239861-1-nicoyip.dev@gmail.com> (raw)
In-Reply-To: <20260824152331.216494-1-nicoyip.dev@gmail.com>
Callers of __pktgen_NN_threads() only check whether a pktgen_dev was
found. After the RCU lookup they never dereference the returned
pointer, so returning it past rcu_read_unlock() is confusing.
Return bool instead and keep the pktgen_dev pointer local to the
RCU critical section.
Suggested-by: Paolo Abeni <pabeni@redhat.com>
Signed-off-by: Chengfeng Ye <nicoyip.dev@gmail.com>
---
This is a net-next follow-up to
https://lore.kernel.org/netdev/20260824152331.216494-1-nicoyip.dev@gmail.com/
net/core/pktgen.c | 17 +++++++----------
1 file changed, 7 insertions(+), 10 deletions(-)
diff --git a/net/core/pktgen.c b/net/core/pktgen.c
index 4fb1853589b3..9985b30c5a42 100644
--- a/net/core/pktgen.c
+++ b/net/core/pktgen.c
@@ -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) {
@@ -2042,9 +2042,9 @@ static struct pktgen_dev *__pktgen_NN_threads(const struct pktgen_net *pn,
}
rcu_read_unlock();
if (pkt_dev)
- break;
+ return true;
}
- return pkt_dev;
+ return false;
}
/*
@@ -2052,7 +2052,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;
@@ -2061,8 +2060,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);
@@ -3836,8 +3834,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;
}
--
2.43.0
next prev parent reply other threads:[~2026-08-25 18:53 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-24 15:23 [PATCH net] net: pktgen: keep device lookup under RCU protection Chengfeng Ye
2026-08-24 15:38 ` Eric Dumazet
2026-08-25 10:45 ` Paolo Abeni
2026-08-25 18:55 ` Chengfeng Ye
2026-08-25 18:53 ` Chengfeng Ye [this message]
2026-08-27 8:16 ` [PATCH net-next] net: pktgen: return bool from __pktgen_NN_threads() Paolo Abeni
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260825185313.239861-1-nicoyip.dev@gmail.com \
--to=nicoyip.dev@gmail.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=horms@kernel.org \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox