And drop ns_free_inum(). Anything common that can be wasted centrally
should be wasted in the new common helper.
Signed-off-by: Christian Brauner <brauner@kernel.org>
---
fs/namespace.c | 4 ++--
include/linux/ns_common.h | 3 +++
include/linux/proc_ns.h | 2 --
ipc/namespace.c | 4 ++--
kernel/cgroup/namespace.c | 2 +-
kernel/nscommon.c | 5 +++++
kernel/pid_namespace.c | 4 ++--
kernel/time/namespace.c | 2 +-
kernel/user_namespace.c | 4 ++--
kernel/utsname.c | 2 +-
net/core/net_namespace.c | 4 ++--
11 files changed, 21 insertions(+), 15 deletions(-)
diff --git a/fs/namespace.c b/fs/namespace.c
index 31eb0e8f21eb..03bd04559e69 100644
--- a/fs/namespace.c
+++ b/fs/namespace.c
@@ -4083,7 +4083,7 @@ static void dec_mnt_namespaces(struct ucounts *ucounts)
static void free_mnt_ns(struct mnt_namespace *ns)
{
if (!is_anon_ns(ns))
- ns_free_inum(&ns->ns);
+ ns_common_free(ns);
dec_mnt_namespaces(ns->ucounts);
mnt_ns_tree_remove(ns);
}
@@ -4155,7 +4155,7 @@ struct mnt_namespace *copy_mnt_ns(unsigned long flags, struct mnt_namespace *ns,
new = copy_tree(old, old->mnt.mnt_root, copy_flags);
if (IS_ERR(new)) {
namespace_unlock();
- ns_free_inum(&new_ns->ns);
+ ns_common_free(ns);
dec_mnt_namespaces(new_ns->ucounts);
mnt_ns_release(new_ns);
return ERR_CAST(new);
diff --git a/include/linux/ns_common.h b/include/linux/ns_common.h
index 284bba2b7c43..5094c0147b54 100644
--- a/include/linux/ns_common.h
+++ b/include/linux/ns_common.h
@@ -41,6 +41,7 @@ struct ns_common {
};
int __ns_common_init(struct ns_common *ns, const struct proc_ns_operations *ops, int inum);
+void __ns_common_free(struct ns_common *ns);
#define to_ns_common(__ns) \
_Generic((__ns), \
@@ -82,4 +83,6 @@ int __ns_common_init(struct ns_common *ns, const struct proc_ns_operations *ops,
#define ns_common_init_inum(__ns, __ops, __inum) \
__ns_common_init(&(__ns)->ns, __ops, __inum)
+#define ns_common_free(__ns) __ns_common_free(to_ns_common((__ns)))
+
#endif
diff --git a/include/linux/proc_ns.h b/include/linux/proc_ns.h
index 9f21670b5824..08016f6e0e6f 100644
--- a/include/linux/proc_ns.h
+++ b/include/linux/proc_ns.h
@@ -66,8 +66,6 @@ static inline void proc_free_inum(unsigned int inum) {}
#endif /* CONFIG_PROC_FS */
-#define ns_free_inum(ns) proc_free_inum((ns)->inum)
-
#define get_proc_ns(inode) ((struct ns_common *)(inode)->i_private)
#endif /* _LINUX_PROC_NS_H */
diff --git a/ipc/namespace.c b/ipc/namespace.c
index 0f8bbd18a475..09d261a1a2aa 100644
--- a/ipc/namespace.c
+++ b/ipc/namespace.c
@@ -97,7 +97,7 @@ static struct ipc_namespace *create_ipc_ns(struct user_namespace *user_ns,
fail_put:
put_user_ns(ns->user_ns);
- ns_free_inum(&ns->ns);
+ ns_common_free(ns);
fail_free:
kfree(ns);
fail_dec:
@@ -161,7 +161,7 @@ static void free_ipc_ns(struct ipc_namespace *ns)
dec_ipc_namespaces(ns->ucounts);
put_user_ns(ns->user_ns);
- ns_free_inum(&ns->ns);
+ ns_common_free(ns);
kfree(ns);
}
diff --git a/kernel/cgroup/namespace.c b/kernel/cgroup/namespace.c
index d928c557e28b..16ead7508371 100644
--- a/kernel/cgroup/namespace.c
+++ b/kernel/cgroup/namespace.c
@@ -40,7 +40,7 @@ void free_cgroup_ns(struct cgroup_namespace *ns)
put_css_set(ns->root_cset);
dec_cgroup_namespaces(ns->ucounts);
put_user_ns(ns->user_ns);
- ns_free_inum(&ns->ns);
+ ns_common_free(ns);
/* Concurrent nstree traversal depends on a grace period. */
kfree_rcu(ns, ns.ns_rcu);
}
diff --git a/kernel/nscommon.c b/kernel/nscommon.c
index c3a90bb665ad..7c1b07e2a6c9 100644
--- a/kernel/nscommon.c
+++ b/kernel/nscommon.c
@@ -18,3 +18,8 @@ int __ns_common_init(struct ns_common *ns, const struct proc_ns_operations *ops,
}
return proc_alloc_inum(&ns->inum);
}
+
+void __ns_common_free(struct ns_common *ns)
+{
+ proc_free_inum(ns->inum);
+}
diff --git a/kernel/pid_namespace.c b/kernel/pid_namespace.c
index 170757c265c2..27e2dd9ee051 100644
--- a/kernel/pid_namespace.c
+++ b/kernel/pid_namespace.c
@@ -127,7 +127,7 @@ static struct pid_namespace *create_pid_namespace(struct user_namespace *user_ns
return ns;
out_free_inum:
- ns_free_inum(&ns->ns);
+ ns_common_free(ns);
out_free_idr:
idr_destroy(&ns->idr);
kmem_cache_free(pid_ns_cachep, ns);
@@ -152,7 +152,7 @@ static void destroy_pid_namespace(struct pid_namespace *ns)
ns_tree_remove(ns);
unregister_pidns_sysctls(ns);
- ns_free_inum(&ns->ns);
+ ns_common_free(ns);
idr_destroy(&ns->idr);
call_rcu(&ns->rcu, delayed_free_pidns);
diff --git a/kernel/time/namespace.c b/kernel/time/namespace.c
index ce8e952104a7..d49c73015d6e 100644
--- a/kernel/time/namespace.c
+++ b/kernel/time/namespace.c
@@ -255,7 +255,7 @@ void free_time_ns(struct time_namespace *ns)
ns_tree_remove(ns);
dec_time_namespaces(ns->ucounts);
put_user_ns(ns->user_ns);
- ns_free_inum(&ns->ns);
+ ns_common_free(ns);
__free_page(ns->vvar_page);
/* Concurrent nstree traversal depends on a grace period. */
kfree_rcu(ns, ns.ns_rcu);
diff --git a/kernel/user_namespace.c b/kernel/user_namespace.c
index db9f0463219c..32406bcab526 100644
--- a/kernel/user_namespace.c
+++ b/kernel/user_namespace.c
@@ -165,7 +165,7 @@ int create_user_ns(struct cred *new)
#ifdef CONFIG_PERSISTENT_KEYRINGS
key_put(ns->persistent_keyring_register);
#endif
- ns_free_inum(&ns->ns);
+ ns_common_free(ns);
fail_free:
kmem_cache_free(user_ns_cachep, ns);
fail_dec:
@@ -220,7 +220,7 @@ static void free_user_ns(struct work_struct *work)
#endif
retire_userns_sysctls(ns);
key_free_user_ns(ns);
- ns_free_inum(&ns->ns);
+ ns_common_free(ns);
/* Concurrent nstree traversal depends on a grace period. */
kfree_rcu(ns, ns.ns_rcu);
dec_user_namespaces(ucounts);
diff --git a/kernel/utsname.c b/kernel/utsname.c
index 399888be66bd..95d733eb2c98 100644
--- a/kernel/utsname.c
+++ b/kernel/utsname.c
@@ -98,7 +98,7 @@ void free_uts_ns(struct uts_namespace *ns)
ns_tree_remove(ns);
dec_uts_namespaces(ns->ucounts);
put_user_ns(ns->user_ns);
- ns_free_inum(&ns->ns);
+ ns_common_free(ns);
/* Concurrent nstree traversal depends on a grace period. */
kfree_rcu(ns, ns.ns_rcu);
}
diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c
index fdb266bbdf93..fdbaf5f8ac78 100644
--- a/net/core/net_namespace.c
+++ b/net/core/net_namespace.c
@@ -597,7 +597,7 @@ struct net *copy_net_ns(unsigned long flags,
net_passive_dec(net);
dec_ucounts:
dec_net_namespaces(ucounts);
- ns_free_inum(&net->ns);
+ ns_common_free(net);
return ERR_PTR(rv);
}
return net;
@@ -719,7 +719,7 @@ static void cleanup_net(struct work_struct *work)
#endif
put_user_ns(net->user_ns);
net_passive_dec(net);
- ns_free_inum(&net->ns);
+ ns_common_free(net);
}
WRITE_ONCE(cleanup_net_task, NULL);
}
--
2.47.3
On Wed 17-09-25 12:28:08, Christian Brauner wrote: > And drop ns_free_inum(). Anything common that can be wasted centrally > should be wasted in the new common helper. > > Signed-off-by: Christian Brauner <brauner@kernel.org> Nice. Feel free to add: Reviewed-by: Jan Kara <jack@suse.cz> Honza > --- > fs/namespace.c | 4 ++-- > include/linux/ns_common.h | 3 +++ > include/linux/proc_ns.h | 2 -- > ipc/namespace.c | 4 ++-- > kernel/cgroup/namespace.c | 2 +- > kernel/nscommon.c | 5 +++++ > kernel/pid_namespace.c | 4 ++-- > kernel/time/namespace.c | 2 +- > kernel/user_namespace.c | 4 ++-- > kernel/utsname.c | 2 +- > net/core/net_namespace.c | 4 ++-- > 11 files changed, 21 insertions(+), 15 deletions(-) > > diff --git a/fs/namespace.c b/fs/namespace.c > index 31eb0e8f21eb..03bd04559e69 100644 > --- a/fs/namespace.c > +++ b/fs/namespace.c > @@ -4083,7 +4083,7 @@ static void dec_mnt_namespaces(struct ucounts *ucounts) > static void free_mnt_ns(struct mnt_namespace *ns) > { > if (!is_anon_ns(ns)) > - ns_free_inum(&ns->ns); > + ns_common_free(ns); > dec_mnt_namespaces(ns->ucounts); > mnt_ns_tree_remove(ns); > } > @@ -4155,7 +4155,7 @@ struct mnt_namespace *copy_mnt_ns(unsigned long flags, struct mnt_namespace *ns, > new = copy_tree(old, old->mnt.mnt_root, copy_flags); > if (IS_ERR(new)) { > namespace_unlock(); > - ns_free_inum(&new_ns->ns); > + ns_common_free(ns); > dec_mnt_namespaces(new_ns->ucounts); > mnt_ns_release(new_ns); > return ERR_CAST(new); > diff --git a/include/linux/ns_common.h b/include/linux/ns_common.h > index 284bba2b7c43..5094c0147b54 100644 > --- a/include/linux/ns_common.h > +++ b/include/linux/ns_common.h > @@ -41,6 +41,7 @@ struct ns_common { > }; > > int __ns_common_init(struct ns_common *ns, const struct proc_ns_operations *ops, int inum); > +void __ns_common_free(struct ns_common *ns); > > #define to_ns_common(__ns) \ > _Generic((__ns), \ > @@ -82,4 +83,6 @@ int __ns_common_init(struct ns_common *ns, const struct proc_ns_operations *ops, > #define ns_common_init_inum(__ns, __ops, __inum) \ > __ns_common_init(&(__ns)->ns, __ops, __inum) > > +#define ns_common_free(__ns) __ns_common_free(to_ns_common((__ns))) > + > #endif > diff --git a/include/linux/proc_ns.h b/include/linux/proc_ns.h > index 9f21670b5824..08016f6e0e6f 100644 > --- a/include/linux/proc_ns.h > +++ b/include/linux/proc_ns.h > @@ -66,8 +66,6 @@ static inline void proc_free_inum(unsigned int inum) {} > > #endif /* CONFIG_PROC_FS */ > > -#define ns_free_inum(ns) proc_free_inum((ns)->inum) > - > #define get_proc_ns(inode) ((struct ns_common *)(inode)->i_private) > > #endif /* _LINUX_PROC_NS_H */ > diff --git a/ipc/namespace.c b/ipc/namespace.c > index 0f8bbd18a475..09d261a1a2aa 100644 > --- a/ipc/namespace.c > +++ b/ipc/namespace.c > @@ -97,7 +97,7 @@ static struct ipc_namespace *create_ipc_ns(struct user_namespace *user_ns, > > fail_put: > put_user_ns(ns->user_ns); > - ns_free_inum(&ns->ns); > + ns_common_free(ns); > fail_free: > kfree(ns); > fail_dec: > @@ -161,7 +161,7 @@ static void free_ipc_ns(struct ipc_namespace *ns) > > dec_ipc_namespaces(ns->ucounts); > put_user_ns(ns->user_ns); > - ns_free_inum(&ns->ns); > + ns_common_free(ns); > kfree(ns); > } > > diff --git a/kernel/cgroup/namespace.c b/kernel/cgroup/namespace.c > index d928c557e28b..16ead7508371 100644 > --- a/kernel/cgroup/namespace.c > +++ b/kernel/cgroup/namespace.c > @@ -40,7 +40,7 @@ void free_cgroup_ns(struct cgroup_namespace *ns) > put_css_set(ns->root_cset); > dec_cgroup_namespaces(ns->ucounts); > put_user_ns(ns->user_ns); > - ns_free_inum(&ns->ns); > + ns_common_free(ns); > /* Concurrent nstree traversal depends on a grace period. */ > kfree_rcu(ns, ns.ns_rcu); > } > diff --git a/kernel/nscommon.c b/kernel/nscommon.c > index c3a90bb665ad..7c1b07e2a6c9 100644 > --- a/kernel/nscommon.c > +++ b/kernel/nscommon.c > @@ -18,3 +18,8 @@ int __ns_common_init(struct ns_common *ns, const struct proc_ns_operations *ops, > } > return proc_alloc_inum(&ns->inum); > } > + > +void __ns_common_free(struct ns_common *ns) > +{ > + proc_free_inum(ns->inum); > +} > diff --git a/kernel/pid_namespace.c b/kernel/pid_namespace.c > index 170757c265c2..27e2dd9ee051 100644 > --- a/kernel/pid_namespace.c > +++ b/kernel/pid_namespace.c > @@ -127,7 +127,7 @@ static struct pid_namespace *create_pid_namespace(struct user_namespace *user_ns > return ns; > > out_free_inum: > - ns_free_inum(&ns->ns); > + ns_common_free(ns); > out_free_idr: > idr_destroy(&ns->idr); > kmem_cache_free(pid_ns_cachep, ns); > @@ -152,7 +152,7 @@ static void destroy_pid_namespace(struct pid_namespace *ns) > ns_tree_remove(ns); > unregister_pidns_sysctls(ns); > > - ns_free_inum(&ns->ns); > + ns_common_free(ns); > > idr_destroy(&ns->idr); > call_rcu(&ns->rcu, delayed_free_pidns); > diff --git a/kernel/time/namespace.c b/kernel/time/namespace.c > index ce8e952104a7..d49c73015d6e 100644 > --- a/kernel/time/namespace.c > +++ b/kernel/time/namespace.c > @@ -255,7 +255,7 @@ void free_time_ns(struct time_namespace *ns) > ns_tree_remove(ns); > dec_time_namespaces(ns->ucounts); > put_user_ns(ns->user_ns); > - ns_free_inum(&ns->ns); > + ns_common_free(ns); > __free_page(ns->vvar_page); > /* Concurrent nstree traversal depends on a grace period. */ > kfree_rcu(ns, ns.ns_rcu); > diff --git a/kernel/user_namespace.c b/kernel/user_namespace.c > index db9f0463219c..32406bcab526 100644 > --- a/kernel/user_namespace.c > +++ b/kernel/user_namespace.c > @@ -165,7 +165,7 @@ int create_user_ns(struct cred *new) > #ifdef CONFIG_PERSISTENT_KEYRINGS > key_put(ns->persistent_keyring_register); > #endif > - ns_free_inum(&ns->ns); > + ns_common_free(ns); > fail_free: > kmem_cache_free(user_ns_cachep, ns); > fail_dec: > @@ -220,7 +220,7 @@ static void free_user_ns(struct work_struct *work) > #endif > retire_userns_sysctls(ns); > key_free_user_ns(ns); > - ns_free_inum(&ns->ns); > + ns_common_free(ns); > /* Concurrent nstree traversal depends on a grace period. */ > kfree_rcu(ns, ns.ns_rcu); > dec_user_namespaces(ucounts); > diff --git a/kernel/utsname.c b/kernel/utsname.c > index 399888be66bd..95d733eb2c98 100644 > --- a/kernel/utsname.c > +++ b/kernel/utsname.c > @@ -98,7 +98,7 @@ void free_uts_ns(struct uts_namespace *ns) > ns_tree_remove(ns); > dec_uts_namespaces(ns->ucounts); > put_user_ns(ns->user_ns); > - ns_free_inum(&ns->ns); > + ns_common_free(ns); > /* Concurrent nstree traversal depends on a grace period. */ > kfree_rcu(ns, ns.ns_rcu); > } > diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c > index fdb266bbdf93..fdbaf5f8ac78 100644 > --- a/net/core/net_namespace.c > +++ b/net/core/net_namespace.c > @@ -597,7 +597,7 @@ struct net *copy_net_ns(unsigned long flags, > net_passive_dec(net); > dec_ucounts: > dec_net_namespaces(ucounts); > - ns_free_inum(&net->ns); > + ns_common_free(net); > return ERR_PTR(rv); > } > return net; > @@ -719,7 +719,7 @@ static void cleanup_net(struct work_struct *work) > #endif > put_user_ns(net->user_ns); > net_passive_dec(net); > - ns_free_inum(&net->ns); > + ns_common_free(net); > } > WRITE_ONCE(cleanup_net_task, NULL); > } > > -- > 2.47.3 > -- Jan Kara <jack@suse.com> SUSE Labs, CR
© 2016 - 2025 Red Hat, Inc.