Commit ba1f70dd authored by Ran Xiaokai's avatar Ran Xiaokai Committed by Linus Torvalds

kernel/fork.c: unshare(): use swap() to make code cleaner

Use swap() instead of reimplementing it.

Link: https://lkml.kernel.org/r/20210909022046.8151-1-ran.xiaokai@zte.com.cnSigned-off-by: default avatarRan Xiaokai <ran.xiaokai@zte.com.cn>
Cc: Gabriel Krisman Bertazi <krisman@collabora.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Eric W. Biederman <ebiederm@xmission.com>
Cc: Jens Axboe <axboe@kernel.dk>
Cc: Alexey Gladkov <legion@kernel.org>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 10a6de19
...@@ -3027,7 +3027,7 @@ int unshare_fd(unsigned long unshare_flags, unsigned int max_fds, ...@@ -3027,7 +3027,7 @@ int unshare_fd(unsigned long unshare_flags, unsigned int max_fds,
int ksys_unshare(unsigned long unshare_flags) int ksys_unshare(unsigned long unshare_flags)
{ {
struct fs_struct *fs, *new_fs = NULL; struct fs_struct *fs, *new_fs = NULL;
struct files_struct *fd, *new_fd = NULL; struct files_struct *new_fd = NULL;
struct cred *new_cred = NULL; struct cred *new_cred = NULL;
struct nsproxy *new_nsproxy = NULL; struct nsproxy *new_nsproxy = NULL;
int do_sysvsem = 0; int do_sysvsem = 0;
...@@ -3114,11 +3114,8 @@ int ksys_unshare(unsigned long unshare_flags) ...@@ -3114,11 +3114,8 @@ int ksys_unshare(unsigned long unshare_flags)
spin_unlock(&fs->lock); spin_unlock(&fs->lock);
} }
if (new_fd) { if (new_fd)
fd = current->files; swap(current->files, new_fd);
current->files = new_fd;
new_fd = fd;
}
task_unlock(current); task_unlock(current);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment