]> git.baikalelectronics.ru Git - kernel.git/commitdiff
kernel/fork.c: unshare(): use swap() to make code cleaner
authorRan Xiaokai <ran.xiaokai@zte.com.cn>
Tue, 9 Nov 2021 02:35:22 +0000 (18:35 -0800)
committerLinus Torvalds <torvalds@linux-foundation.org>
Tue, 9 Nov 2021 18:02:52 +0000 (10:02 -0800)
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>
kernel/fork.c

index 38681ad44c76bc71ce3795ff052f7eb218769643..acf94e660ce3c88272039bb3590f64cfd87b6d69 100644 (file)
@@ -3027,7 +3027,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;
@@ -3114,11 +3114,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);