[PATCH 06/32] ns: uniformly initialize ns_common

Christian Brauner posted 32 patches 9 hours ago
[PATCH 06/32] ns: uniformly initialize ns_common
Posted by Christian Brauner 9 hours ago
No point in cargo-culting the same code across all the different types.
Use one common initializer.

Signed-off-by: Christian Brauner <brauner@kernel.org>
---
 include/linux/proc_ns.h | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/include/linux/proc_ns.h b/include/linux/proc_ns.h
index 5e1a4b378b79..dbb119bda097 100644
--- a/include/linux/proc_ns.h
+++ b/include/linux/proc_ns.h
@@ -72,6 +72,22 @@ static inline int ns_alloc_inum(struct ns_common *ns)
 	return proc_alloc_inum(&ns->inum);
 }
 
+static inline int ns_common_init(struct ns_common *ns,
+				 const struct proc_ns_operations *ops,
+				 bool alloc_inum)
+{
+	if (alloc_inum) {
+		int ret;
+		ret = proc_alloc_inum(&ns->inum);
+		if (ret)
+			return ret;
+	}
+	refcount_set(&ns->count, 1);
+	ns->stashed = NULL;
+	ns->ops = ops;
+	return 0;
+}
+
 #define ns_free_inum(ns) proc_free_inum((ns)->inum)
 
 #define get_proc_ns(inode) ((struct ns_common *)(inode)->i_private)

-- 
2.47.3
Re: [PATCH 06/32] ns: uniformly initialize ns_common
Posted by Jan Kara 7 hours ago
On Wed 10-09-25 16:36:51, Christian Brauner wrote:
> No point in cargo-culting the same code across all the different types.
> Use one common initializer.
> 
> Signed-off-by: Christian Brauner <brauner@kernel.org>

Looks good. Feel free to add:

Reviewed-by: Jan Kara <jack@suse.cz>

								Honza

> ---
>  include/linux/proc_ns.h | 16 ++++++++++++++++
>  1 file changed, 16 insertions(+)
> 
> diff --git a/include/linux/proc_ns.h b/include/linux/proc_ns.h
> index 5e1a4b378b79..dbb119bda097 100644
> --- a/include/linux/proc_ns.h
> +++ b/include/linux/proc_ns.h
> @@ -72,6 +72,22 @@ static inline int ns_alloc_inum(struct ns_common *ns)
>  	return proc_alloc_inum(&ns->inum);
>  }
>  
> +static inline int ns_common_init(struct ns_common *ns,
> +				 const struct proc_ns_operations *ops,
> +				 bool alloc_inum)
> +{
> +	if (alloc_inum) {
> +		int ret;
> +		ret = proc_alloc_inum(&ns->inum);
> +		if (ret)
> +			return ret;
> +	}
> +	refcount_set(&ns->count, 1);
> +	ns->stashed = NULL;
> +	ns->ops = ops;
> +	return 0;
> +}
> +
>  #define ns_free_inum(ns) proc_free_inum((ns)->inum)
>  
>  #define get_proc_ns(inode) ((struct ns_common *)(inode)->i_private)
> 
> -- 
> 2.47.3
> 
-- 
Jan Kara <jack@suse.com>
SUSE Labs, CR