Skip to content

Commit ba1f70d

Browse files
ranxiaokaitorvalds
authored andcommitted
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: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 10a6de1 commit ba1f70d

1 file changed

Lines changed: 3 additions & 6 deletions

File tree

kernel/fork.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3027,7 +3027,7 @@ int unshare_fd(unsigned long unshare_flags, unsigned int max_fds,
30273027
int ksys_unshare(unsigned long unshare_flags)
30283028
{
30293029
struct fs_struct *fs, *new_fs = NULL;
3030-
struct files_struct *fd, *new_fd = NULL;
3030+
struct files_struct *new_fd = NULL;
30313031
struct cred *new_cred = NULL;
30323032
struct nsproxy *new_nsproxy = NULL;
30333033
int do_sysvsem = 0;
@@ -3114,11 +3114,8 @@ int ksys_unshare(unsigned long unshare_flags)
31143114
spin_unlock(&fs->lock);
31153115
}
31163116

3117-
if (new_fd) {
3118-
fd = current->files;
3119-
current->files = new_fd;
3120-
new_fd = fd;
3121-
}
3117+
if (new_fd)
3118+
swap(current->files, new_fd);
31223119

31233120
task_unlock(current);
31243121

0 commit comments

Comments
 (0)