mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2025-12-27 12:21:22 -05:00
ns: add ns_common_free()
And drop ns_free_inum(). Anything common that can be wasted centrally should be wasted in the new common helper. Reviewed-by: Jan Kara <jack@suse.cz> Signed-off-by: Christian Brauner <brauner@kernel.org>
This commit is contained in:
@@ -4082,7 +4082,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);
|
||||
}
|
||||
@@ -4154,7 +4154,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);
|
||||
|
||||
@@ -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), \
|
||||
@@ -80,4 +81,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(to_ns_common(__ns), __ops, __inum)
|
||||
|
||||
#define ns_common_free(__ns) __ns_common_free(to_ns_common((__ns)))
|
||||
|
||||
#endif
|
||||
|
||||
@@ -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 */
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -590,7 +590,7 @@ struct net *copy_net_ns(unsigned long flags,
|
||||
|
||||
if (rv < 0) {
|
||||
put_userns:
|
||||
ns_free_inum(&net->ns);
|
||||
ns_common_free(net);
|
||||
#ifdef CONFIG_KEYS
|
||||
key_remove_domain(net->key_domain);
|
||||
#endif
|
||||
@@ -713,7 +713,7 @@ static void cleanup_net(struct work_struct *work)
|
||||
/* Finally it is safe to free my network namespace structure */
|
||||
list_for_each_entry_safe(net, tmp, &net_exit_list, exit_list) {
|
||||
list_del_init(&net->exit_list);
|
||||
ns_free_inum(&net->ns);
|
||||
ns_common_free(net);
|
||||
dec_net_namespaces(net->ucounts);
|
||||
#ifdef CONFIG_KEYS
|
||||
key_remove_domain(net->key_domain);
|
||||
|
||||
Reference in New Issue
Block a user