]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
nstree: simplify owner list iteration
authorChristian Brauner <brauner@kernel.org>
Mon, 10 Nov 2025 15:08:18 +0000 (16:08 +0100)
committerChristian Brauner <brauner@kernel.org>
Tue, 11 Nov 2025 09:01:30 +0000 (10:01 +0100)
Make use of list_for_each_entry_from_rcu().

Link: https://patch.msgid.link/20251110-work-namespace-nstree-fixes-v1-6-e8a9264e0fb9@kernel.org
Signed-off-by: Christian Brauner <brauner@kernel.org>
kernel/nstree.c

index 6c7ec9fbf25f2e706d75a7fe87cd1980c017750b..476dd738d65393158310237fcb53876f9cd4c593 100644 (file)
@@ -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;