Skip to contentSkip to conversation

nsproxy: Reuse already available put_nsproxy helper function.

PATCH RESEND In review Parav Pandit 1 participant 2 messages Jan 27, 2017 – Feb 20, 2017

lore
Share & tools
lore
#0 lore raw

PATCH RESEND 1/1 nsproxy: Reuse already available put_nsproxy helper function.

This patch makes use of already available put_nsproxy() helper function which already perform atomic check and conditional free. It also remove braces in put_nsproxy() for single line conditional statement.
Minor fixes for trailing white space, 80 characters etc warnings reported by checkpatch.pl.

Resending it to include Eric Biederman to merge the changes.

---
 include/linux/nsproxy.h | 10 +++++-----
 kernel/nsproxy.c        | 12 +++++++-----
 2 files changed, 12 insertions(+), 10 deletions(-)
include/linux/nsproxy.h +5 -5
index ac0d65b..24556f4 100644
@@ -33,7 +33,7 @@ struct nsproxy {
 	struct ipc_namespace *ipc_ns;
 	struct mnt_namespace *mnt_ns;
 	struct pid_namespace *pid_ns_for_children;
-	struct net 	     *net_ns;
+	struct net	     *net_ns;
 	struct cgroup_namespace *cgroup_ns;
 };
 extern struct nsproxy init_nsproxy;
@@ -68,15 +68,15 @@ struct nsproxy {
 void exit_task_namespaces(struct task_struct *tsk);
 void switch_task_namespaces(struct task_struct *tsk, struct nsproxy *new);
 void free_nsproxy(struct nsproxy *ns);
-int unshare_nsproxy_namespaces(unsigned long, struct nsproxy **,
-	struct cred *, struct fs_struct *);
+int unshare_nsproxy_namespaces(unsigned long unshare_flags,
+	struct nsproxy **new_nsp, struct cred *new_cred,
+	struct fs_struct *new_fs);
 int __init nsproxy_cache_init(void);
 
 static inline void put_nsproxy(struct nsproxy *ns)
 {
-	if (atomic_dec_and_test(&ns->count)) {
+	if (atomic_dec_and_test(&ns->count))
 		free_nsproxy(ns);
-	}
 }
 
 static inline void get_nsproxy(struct nsproxy *ns)
kernel/nsproxy.c +7 -5
index 782102e..f253655 100644
@@ -71,7 +71,8 @@ static struct nsproxy *create_new_namespaces(unsigned long flags,
 	if (!new_nsp)
 		return ERR_PTR(-ENOMEM);
 
-	new_nsp->mnt_ns = copy_mnt_ns(flags, tsk->nsproxy->mnt_ns, user_ns, new_fs);
+	new_nsp->mnt_ns = copy_mnt_ns(flags, tsk->nsproxy->mnt_ns, user_ns,
+				      new_fs);
 	if (IS_ERR(new_nsp->mnt_ns)) {
 		err = PTR_ERR(new_nsp->mnt_ns);
 		goto out_ns;
@@ -158,7 +159,7 @@ int copy_namespaces(unsigned long flags, struct task_struct *tsk)
 	 * it along with CLONE_NEWIPC.
 	 */
 	if ((flags & (CLONE_NEWIPC | CLONE_SYSVSEM)) ==
-		(CLONE_NEWIPC | CLONE_SYSVSEM)) 
+		(CLONE_NEWIPC | CLONE_SYSVSEM))
 		return -EINVAL;
 
 	new_ns = create_new_namespaces(flags, tsk, user_ns, tsk->fs);
@@ -189,7 +190,8 @@ void free_nsproxy(struct nsproxy *ns)
  * On success, returns the new nsproxy.
  */
 int unshare_nsproxy_namespaces(unsigned long unshare_flags,
-	struct nsproxy **new_nsp, struct cred *new_cred, struct fs_struct *new_fs)
+	struct nsproxy **new_nsp, struct cred *new_cred,
+	struct fs_struct *new_fs)
 {
 	struct user_namespace *user_ns;
 	int err = 0;
@@ -224,8 +226,8 @@ void switch_task_namespaces(struct task_struct *p, struct nsproxy *new)
 	p->nsproxy = new;
 	task_unlock(p);
 
-	if (ns && atomic_dec_and_test(&ns->count))
-		free_nsproxy(ns);
+	if (ns)
+		put_nsproxy(ns);
 }
 
 void exit_task_namespaces(struct task_struct *p)
Signature · 1 line
1.8.3.1
#1 lore raw

Hi Eric,

Will you be able to merge this patch if it looks o.k.

Parav

Quoted 106 lines

-----Original Message-----
From: Parav Pandit [mailto:[email protected]]
Sent: Friday, January 27, 2017 1:39 PM
To: [email protected]; [email protected]; [email protected]; linux- [email protected]
Cc: Parav Pandit <[email protected]>
Subject: [PATCH RESEND] nsproxy: Reuse already available put_nsproxy helper function.

This patch makes use of already available put_nsproxy() helper function which already perform atomic check and conditional free.
It also remove braces in put_nsproxy() for single line conditional statement. Minor fixes for trailing white space, 80 characters etc warnings reported by checkpatch.pl.

Resending it to include Eric Biederman to merge the changes.

---
 include/linux/nsproxy.h | 10 +++++-----
 kernel/nsproxy.c        | 12 +++++++-----
 2 files changed, 12 insertions(+), 10 deletions(-)
include/linux/nsproxy.h index renamed from include/linux/nsproxy.h +0 -0

ac0d65b..24556f4 100644

include/linux/nsproxy.h +1 -1
@@ -33,7 +33,7 @@ struct nsproxy {
 	struct ipc_namespace *ipc_ns;
 	struct mnt_namespace *mnt_ns;
 	struct pid_namespace *pid_ns_for_children;
-	struct net 	     *net_ns;
+	struct net	     *net_ns;
 	struct cgroup_namespace *cgroup_ns;
 };
 extern struct nsproxy init_nsproxy;
@@ -68,15 +68,15 @@ struct nsproxy {
 void exit_task_namespaces(struct task_struct *tsk);  void

switch_task_namespaces(struct task_struct *tsk, struct nsproxy *new); void free_nsproxy(struct nsproxy *ns); -int unshare_nsproxy_namespaces(unsigned long, struct nsproxy **,

include/linux/nsproxy.h +4 -3
-	struct cred *, struct fs_struct *);
+int unshare_nsproxy_namespaces(unsigned long unshare_flags,
+	struct nsproxy **new_nsp, struct cred *new_cred,
+	struct fs_struct *new_fs);
 int __init nsproxy_cache_init(void);
 
 static inline void put_nsproxy(struct nsproxy *ns)  {
-	if (atomic_dec_and_test(&ns->count)) {
+	if (atomic_dec_and_test(&ns->count))
 		free_nsproxy(ns);
-	}
 }
 
 static inline void get_nsproxy(struct nsproxy *ns) diff --git

a/kernel/nsproxy.c b/kernel/nsproxy.c index 782102e..f253655 100644

kernel/nsproxy.c +2 -1
@@ -71,7 +71,8 @@ static struct nsproxy
 *create_new_namespaces(unsigned long flags,
 	if (!new_nsp)
 		return ERR_PTR(-ENOMEM);
 
-	new_nsp->mnt_ns = copy_mnt_ns(flags, tsk->nsproxy->mnt_ns,
 user_ns, new_fs);
+	new_nsp->mnt_ns = copy_mnt_ns(flags, tsk->nsproxy->mnt_ns,
 user_ns,
+				      new_fs);
kernel/nsproxy.c +1 -1
 	if (IS_ERR(new_nsp->mnt_ns)) {
 		err = PTR_ERR(new_nsp->mnt_ns);
 		goto out_ns;
@@ -158,7 +159,7 @@ int copy_namespaces(unsigned long flags, struct
 task_struct *tsk)
 	 * it along with CLONE_NEWIPC.
 	 */
 	if ((flags & (CLONE_NEWIPC | CLONE_SYSVSEM)) ==
-		(CLONE_NEWIPC | CLONE_SYSVSEM))
+		(CLONE_NEWIPC | CLONE_SYSVSEM))
 		return -EINVAL;
 
kernel/nsproxy.c +0 -2
 	new_ns = create_new_namespaces(flags, tsk, user_ns, tsk->fs); @@
-189,7 +190,8 @@ void free_nsproxy(struct nsproxy *ns)
  * On success, returns the new nsproxy.
  */
 int unshare_nsproxy_namespaces(unsigned long unshare_flags,
-	struct nsproxy **new_nsp, struct cred *new_cred, struct fs_struct

*new_fs)

kernel/nsproxy.c +4 -2
+	struct nsproxy **new_nsp, struct cred *new_cred,
+	struct fs_struct *new_fs)
 {
 	struct user_namespace *user_ns;
 	int err = 0;
@@ -224,8 +226,8 @@ void switch_task_namespaces(struct task_struct *p,
 struct nsproxy *new)
 	p->nsproxy = new;
 	task_unlock(p);
 
-	if (ns && atomic_dec_and_test(&ns->count))
-		free_nsproxy(ns);
+	if (ns)
+		put_nsproxy(ns);
 }
 

void exit_task_namespaces(struct task_struct *p)
--
1.8.3.1