summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRan Xiaokai <ran.xiaokai@zte.com.cn>2021-10-28 13:25:52 +1100
committerStephen Rothwell <sfr@canb.auug.org.au>2021-10-28 13:25:52 +1100
commit3802213e06786e2c1f131672c0711319e27f51e7 (patch)
treec37ced21805dadecdf6d0e573c624e4d747af4c9
parent1dd1eb3b6ca6451b75e6d966f245ae9a24389685 (diff)
downloadlinux-3802213e06786e2c1f131672c0711319e27f51e7.tar.gz
linux-3802213e06786e2c1f131672c0711319e27f51e7.tar.xz
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.cn Signed-off-by: Ran 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: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Stephen Rothwell <sfr@canb.auug.org.au>
-rw-r--r--kernel/fork.c9
1 files changed, 3 insertions, 6 deletions
diff --git a/kernel/fork.c b/kernel/fork.c
index a7da9b0bc402..723125f2cbed 100644
--- a/kernel/fork.c
+++ b/kernel/fork.c
@@ -3078,7 +3078,7 @@ int unshare_fd(unsigned long unshare_flags, unsigned int max_fds,
int ksys_unshare(unsigned long unshare_flags)
{
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 nsproxy *new_nsproxy = NULL;
int do_sysvsem = 0;
@@ -3165,11 +3165,8 @@ int ksys_unshare(unsigned long unshare_flags)
spin_unlock(&fs->lock);
}
- if (new_fd) {
- fd = current->files;
- current->files = new_fd;
- new_fd = fd;
- }
+ if (new_fd)
+ swap(current->files, new_fd);
task_unlock(current);