]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
ns: add to_<type>_ns() to respective headers
authorChristian Brauner <brauner@kernel.org>
Fri, 12 Sep 2025 11:52:49 +0000 (13:52 +0200)
committerChristian Brauner <brauner@kernel.org>
Fri, 19 Sep 2025 12:26:16 +0000 (14:26 +0200)
Every namespace type has a container_of(ns, <ns_type>, ns) static inline
function that is currently not exposed in the header. So we have a bunch
of places that open-code it via container_of(). Move it to the headers
so we can use it directly.

Reviewed-by: Aleksa Sarai <cyphar@cyphar.com>
Signed-off-by: Christian Brauner <brauner@kernel.org>
14 files changed:
include/linux/cgroup.h
include/linux/ipc_namespace.h
include/linux/pid_namespace.h
include/linux/time_namespace.h
include/linux/user_namespace.h
include/linux/utsname.h
include/net/net_namespace.h
ipc/namespace.c
kernel/cgroup/namespace.c
kernel/pid_namespace.c
kernel/time/namespace.c
kernel/user_namespace.c
kernel/utsname.c
net/core/net_namespace.c

index b18fb5fcb38e239347c1be4b5af9f74f14c767c4..9ca25346f7cb5c4a0e175463c9b5e64ad45b6bd1 100644 (file)
@@ -794,6 +794,11 @@ extern struct cgroup_namespace init_cgroup_ns;
 
 #ifdef CONFIG_CGROUPS
 
+static inline struct cgroup_namespace *to_cg_ns(struct ns_common *ns)
+{
+       return container_of(ns, struct cgroup_namespace, ns);
+}
+
 void free_cgroup_ns(struct cgroup_namespace *ns);
 
 struct cgroup_namespace *copy_cgroup_ns(unsigned long flags,
index e8240cf2611ad63f427d8fe90b3fe8cbcb1fb6b0..924e4754374fbabc65804699c52ecf4d090c5b23 100644 (file)
@@ -129,6 +129,11 @@ static inline int mq_init_ns(struct ipc_namespace *ns) { return 0; }
 #endif
 
 #if defined(CONFIG_IPC_NS)
+static inline struct ipc_namespace *to_ipc_ns(struct ns_common *ns)
+{
+       return container_of(ns, struct ipc_namespace, ns);
+}
+
 extern struct ipc_namespace *copy_ipcs(unsigned long flags,
        struct user_namespace *user_ns, struct ipc_namespace *ns);
 
index 7c67a58111998d9bcb1ba29c017acb249286ec38..ba0efc8c8596b336fb0b13a54bfb73c6988e8995 100644 (file)
@@ -54,6 +54,11 @@ extern struct pid_namespace init_pid_ns;
 #define PIDNS_ADDING (1U << 31)
 
 #ifdef CONFIG_PID_NS
+static inline struct pid_namespace *to_pid_ns(struct ns_common *ns)
+{
+       return container_of(ns, struct pid_namespace, ns);
+}
+
 static inline struct pid_namespace *get_pid_ns(struct pid_namespace *ns)
 {
        if (ns != &init_pid_ns)
index 7f6af7a9771e9a1a3cf530fdf1a91b383500ace0..a47a4ce4183e1d3a9389a2d8beabe28e3661a435 100644 (file)
@@ -33,6 +33,10 @@ struct time_namespace {
 extern struct time_namespace init_time_ns;
 
 #ifdef CONFIG_TIME_NS
+static inline struct time_namespace *to_time_ns(struct ns_common *ns)
+{
+       return container_of(ns, struct time_namespace, ns);
+}
 void __init time_ns_init(void);
 extern int vdso_join_timens(struct task_struct *task,
                            struct time_namespace *ns);
index a0bb6d012137802ebbf4a8037dc64c540a13a6a0..a09056ad090e1a23b948a6a20d6ca46624d1e457 100644 (file)
@@ -168,6 +168,11 @@ static inline void set_userns_rlimit_max(struct user_namespace *ns,
 
 #ifdef CONFIG_USER_NS
 
+static inline struct user_namespace *to_user_ns(struct ns_common *ns)
+{
+       return container_of(ns, struct user_namespace, ns);
+}
+
 static inline struct user_namespace *get_user_ns(struct user_namespace *ns)
 {
        if (ns)
index bf7613ba412bfe2dae6ced334952e97cddee65cd..5d34c4f0f945490cd1b91ec09d74280449784a3f 100644 (file)
@@ -30,6 +30,11 @@ struct uts_namespace {
 extern struct uts_namespace init_uts_ns;
 
 #ifdef CONFIG_UTS_NS
+static inline struct uts_namespace *to_uts_ns(struct ns_common *ns)
+{
+       return container_of(ns, struct uts_namespace, ns);
+}
+
 static inline void get_uts_ns(struct uts_namespace *ns)
 {
        refcount_inc(&ns->ns.count);
index 025a7574b275f34b7757cb64cd5dfb9a1aeb5169..fd090ceb80bf48133b4a8efe6c4f596fa17409fa 100644 (file)
@@ -262,6 +262,11 @@ void ipx_unregister_sysctl(void);
 #ifdef CONFIG_NET_NS
 void __put_net(struct net *net);
 
+static inline struct net *to_net_ns(struct ns_common *ns)
+{
+       return container_of(ns, struct net, ns);
+}
+
 /* Try using get_net_track() instead */
 static inline struct net *get_net(struct net *net)
 {
index 9f923c1a1eb30c7d9aeec6299d02498a9c88e6fc..89588819956b2042b8626c5fbe908e861b0ff85a 100644 (file)
@@ -209,11 +209,6 @@ void put_ipc_ns(struct ipc_namespace *ns)
        }
 }
 
-static inline struct ipc_namespace *to_ipc_ns(struct ns_common *ns)
-{
-       return container_of(ns, struct ipc_namespace, ns);
-}
-
 static struct ns_common *ipcns_get(struct task_struct *task)
 {
        struct ipc_namespace *ns = NULL;
index fc12c416dfeb34a4c312413eaf02135fed306e8b..5a327914b5654ebdf755843ee26d5a4c062a0d8e 100644 (file)
@@ -89,11 +89,6 @@ struct cgroup_namespace *copy_cgroup_ns(unsigned long flags,
        return new_ns;
 }
 
-static inline struct cgroup_namespace *to_cg_ns(struct ns_common *ns)
-{
-       return container_of(ns, struct cgroup_namespace, ns);
-}
-
 static int cgroupns_install(struct nsset *nsset, struct ns_common *ns)
 {
        struct nsproxy *nsproxy = nsset->nsproxy;
index 228ae20299f9aaf0c5938f25d2d4ede8a66a6f26..9b327420309e8b5f25e62f77b9356dff92de132d 100644 (file)
@@ -345,11 +345,6 @@ int reboot_pid_ns(struct pid_namespace *pid_ns, int cmd)
        return 0;
 }
 
-static inline struct pid_namespace *to_pid_ns(struct ns_common *ns)
-{
-       return container_of(ns, struct pid_namespace, ns);
-}
-
 static struct ns_common *pidns_get(struct task_struct *task)
 {
        struct pid_namespace *ns;
index 408f60d0a3b6ca03391cd0242254aa0ac2193675..20b65f90549e20b739da6831d08ba40a87a8e992 100644 (file)
@@ -261,11 +261,6 @@ void free_time_ns(struct time_namespace *ns)
        kfree_rcu(ns, ns.ns_rcu);
 }
 
-static struct time_namespace *to_time_ns(struct ns_common *ns)
-{
-       return container_of(ns, struct time_namespace, ns);
-}
-
 static struct ns_common *timens_get(struct task_struct *task)
 {
        struct time_namespace *ns = NULL;
index ade5b6806c5c31022fec2b23ff2695205320ce58..cfb0e28f2779c9bf6b49327dfa58165e02815686 100644 (file)
@@ -1325,11 +1325,6 @@ bool current_in_userns(const struct user_namespace *target_ns)
 }
 EXPORT_SYMBOL(current_in_userns);
 
-static inline struct user_namespace *to_user_ns(struct ns_common *ns)
-{
-       return container_of(ns, struct user_namespace, ns);
-}
-
 static struct ns_common *userns_get(struct task_struct *task)
 {
        struct user_namespace *user_ns;
index 64155417ae0c86f4834761fefcec8c2cca0688ef..a682830742d3442e542bb89c91af8e9962b98980 100644 (file)
@@ -103,11 +103,6 @@ void free_uts_ns(struct uts_namespace *ns)
        kfree_rcu(ns, ns.ns_rcu);
 }
 
-static inline struct uts_namespace *to_uts_ns(struct ns_common *ns)
-{
-       return container_of(ns, struct uts_namespace, ns);
-}
-
 static struct ns_common *utsns_get(struct task_struct *task)
 {
        struct uts_namespace *ns = NULL;
index 169ec22c4758f40a992e101c2a49bf0a8e6dbee3..a57b3cda8dbc3172bb9c02ebea0ee121a72613d3 100644 (file)
@@ -1541,11 +1541,6 @@ static struct ns_common *netns_get(struct task_struct *task)
        return net ? &net->ns : NULL;
 }
 
-static inline struct net *to_net_ns(struct ns_common *ns)
-{
-       return container_of(ns, struct net, ns);
-}
-
 static void netns_put(struct ns_common *ns)
 {
        put_net(to_net_ns(ns));