[PATCH 06/17] nstree: simplify owner list iteration

Christian Brauner
2025-11-10T15:09:12Z

Make use of list_for_each_entry_from_rcu().

Signed-off-by: Christian Brauner <brauner@kernel.org>
---
kernel/nstree.c | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/kernel/nstree.c b/kernel/nstree.c
index 6c7ec9fbf25f..476dd738d653 100644
--- a/kernel/nstree.c
+++ b/kernel/nstree.c
@@ -598,11 +598,15 @@ static ssize_t do_listns_userns(struct klistns *kls)
rcu_read_lock();

if (!first_ns)
- first_ns = list_entry_rcu(head->next, typeof(*ns), ns_owner_node.ns_list_entry);
- for (ns = first_ns; &ns->ns_owner_node.ns_list_entry != head && nr_ns_ids;
- ns = list_entry_rcu(ns->ns_owner_node.ns_list_entry.next, typeof(*ns), ns_owner_node.ns_list_entry)) {
+ first_ns = list_entry_rcu(head->next, typeof(*first_ns), ns_owner_node.ns_list_entry);
+
+ ns = first_ns;
+ list_for_each_entry_from_rcu(ns, head, ns_owner_node.ns_list_entry) {
struct ns_common *valid;

+ if (!nr_ns_ids)
+ break;
+
valid = legitimize_ns(kls, ns);
if (!valid)
continue;

--
2.47.3