Skip to contentSkip to conversation

nsproxy: remove judge of timens_on_fork()'s return val

PATCH In review Hui Su 2 participants 3 messages Nov 15, 2020 – Nov 17, 2020

lore
Share & tools
lore

Hui Su

author
#0 lore raw

PATCH 1/1 nsproxy: remove judge of timens_on_fork()'s return val

timens_on_fork() always return 0, and maybe not need to judge the return value in copy_namespaces().

---
 kernel/nsproxy.c | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)
kernel/nsproxy.c +1 -6
index 12dd41b39a7f..e2e6c5dc433f 100644
@@ -153,7 +153,6 @@ int copy_namespaces(unsigned long flags, struct task_struct *tsk)
 	struct nsproxy *old_ns = tsk->nsproxy;
 	struct user_namespace *user_ns = task_cred_xxx(tsk, user_ns);
 	struct nsproxy *new_ns;
-	int ret;
 
 	if (likely(!(flags & (CLONE_NEWNS | CLONE_NEWUTS | CLONE_NEWIPC |
 			      CLONE_NEWPID | CLONE_NEWNET |
@@ -180,11 +179,7 @@ int copy_namespaces(unsigned long flags, struct task_struct *tsk)
 	if (IS_ERR(new_ns))
 		return  PTR_ERR(new_ns);
 
-	ret = timens_on_fork(new_ns, tsk);
-	if (ret) {
-		free_nsproxy(new_ns);
-		return ret;
-	}
+	timens_on_fork(new_ns, tsk);
 
 	tsk->nsproxy = new_ns;
 	return 0;
Signature · 1 line
2.29.0
#1 lore raw
Quoted 3 lines · Hui Su

timens_on_fork() always return 0, and maybe not need to judge the return value in copy_namespaces().

Thank you for cleaning this up. I think we can go even further and change timens_on_fork to return nothing:

-int timens_on_fork(struct nsproxy *nsproxy, struct task_struct *tsk) +void timens_on_fork(struct nsproxy *nsproxy, struct task_struct *tsk)

 {
        struct ns_common *nsc = &nsproxy->time_ns_for_children->ns;
        struct time_namespace *ns = to_time_ns(nsc);

        /* create_new_namespaces() already incremented the ref counter */
        if (nsproxy->time_ns == nsproxy->time_ns_for_children)

- return 0;
+ return;

        get_time_ns(ns);
        put_time_ns(nsproxy->time_ns);
        nsproxy->time_ns = ns;

        timens_commit(tsk, ns);

-
- return 0;
}

Quoted 35 lines
---
 kernel/nsproxy.c | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)
kernel/nsproxy.c +1 -7
index 12dd41b39a7f..e2e6c5dc433f 100644
@@ -153,7 +153,6 @@ int copy_namespaces(unsigned long flags, struct task_struct *tsk)
        struct nsproxy *old_ns = tsk->nsproxy;
        struct user_namespace *user_ns = task_cred_xxx(tsk, user_ns);
        struct nsproxy *new_ns;
-       int ret;
 
        if (likely(!(flags & (CLONE_NEWNS | CLONE_NEWUTS | CLONE_NEWIPC |
                              CLONE_NEWPID | CLONE_NEWNET |
@@ -180,11 +179,7 @@ int copy_namespaces(unsigned long flags, struct task_struct *tsk)
        if (IS_ERR(new_ns))
                return  PTR_ERR(new_ns);
 
-       ret = timens_on_fork(new_ns, tsk);
-       if (ret) {
-               free_nsproxy(new_ns);
-               return ret;
-       }
+       timens_on_fork(new_ns, tsk);
 
        tsk->nsproxy = new_ns;
        return 0;
--

2.29.0

author
#2 lore raw
Quoted 58 lines · Andrey Vagin
Quoted 3 lines · Hui Su

timens_on_fork() always return 0, and maybe not need to judge the return value in copy_namespaces().

Thank you for cleaning this up. I think we can go even further and change timens_on_fork to return nothing:

(quoted diff) +2 -4
-int timens_on_fork(struct nsproxy *nsproxy, struct task_struct *tsk)
+void timens_on_fork(struct nsproxy *nsproxy, struct task_struct *tsk)
 {
        struct ns_common *nsc = &nsproxy->time_ns_for_children->ns;
        struct time_namespace *ns = to_time_ns(nsc);
 
        /* create_new_namespaces() already incremented the ref counter */
        if (nsproxy->time_ns == nsproxy->time_ns_for_children)
-               return 0;
+               return;
 
        get_time_ns(ns);
        put_time_ns(nsproxy->time_ns);
        nsproxy->time_ns = ns;
 
        timens_commit(tsk, ns);
-
-       return 0;
 }
Quoted 31 lines
---
 kernel/nsproxy.c | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)
kernel/nsproxy.c +1 -6
index 12dd41b39a7f..e2e6c5dc433f 100644
@@ -153,7 +153,6 @@ int copy_namespaces(unsigned long flags, struct task_struct *tsk)
        struct nsproxy *old_ns = tsk->nsproxy;
        struct user_namespace *user_ns = task_cred_xxx(tsk, user_ns);
        struct nsproxy *new_ns;
-       int ret;
 
        if (likely(!(flags & (CLONE_NEWNS | CLONE_NEWUTS | CLONE_NEWIPC |
                              CLONE_NEWPID | CLONE_NEWNET |
@@ -180,11 +179,7 @@ int copy_namespaces(unsigned long flags, struct task_struct *tsk)
        if (IS_ERR(new_ns))
                return  PTR_ERR(new_ns);
 
-       ret = timens_on_fork(new_ns, tsk);
-       if (ret) {
-               free_nsproxy(new_ns);
-               return ret;
-       }
+       timens_on_fork(new_ns, tsk);
 
Quoted 6 lines
Quoted 6 lines
kernel/nsproxy.c +0 -1
        tsk->nsproxy = new_ns;
        return 0;
--

2.29.0

Yeah, thank for your reply, Andrey.

I will resend PATCH V2 with makeing timens_on_fork() return nothing.

Thanks.