aboutsummaryrefslogtreecommitdiffstats
path: root/fs/file.c
diff options
context:
space:
mode:
authorOleg Nesterov <oleg@redhat.com>2014-01-13 10:48:19 -0500
committerAl Viro <viro@zeniv.linux.org.uk>2014-01-25 03:14:37 -0500
commit1deb46e2562561255c34075825fd00f22a858bb3 (patch)
tree1ddd569cd9f72f16ad1a7c63e247c5847e4f44c2 /fs/file.c
parentce08b62d18b3f97cd4e5a39bd5898872b9201875 (diff)
fs: factor out common code in fget() and fget_raw()
Apart from FMODE_PATH check fget() and fget_raw() are identical, shift the code into the new simple helper, __fget(fd, mask). Saves 160 bytes. Signed-off-by: Oleg Nesterov <oleg@redhat.com> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Diffstat (limited to 'fs/file.c')
-rw-r--r--fs/file.c25
1 files changed, 8 insertions, 17 deletions
diff --git a/fs/file.c b/fs/file.c
index d34e59e51743..4ed58a32575e 100644
--- a/fs/file.c
+++ b/fs/file.c
@@ -637,16 +637,16 @@ void do_close_on_exec(struct files_struct *files)
637 spin_unlock(&files->file_lock); 637 spin_unlock(&files->file_lock);
638} 638}
639 639
640struct file *fget(unsigned int fd) 640static struct file *__fget(unsigned int fd, fmode_t mask)
641{ 641{
642 struct file *file;
643 struct files_struct *files = current->files; 642 struct files_struct *files = current->files;
643 struct file *file;
644 644
645 rcu_read_lock(); 645 rcu_read_lock();
646 file = fcheck_files(files, fd); 646 file = fcheck_files(files, fd);
647 if (file) { 647 if (file) {
648 /* File object ref couldn't be taken */ 648 /* File object ref couldn't be taken */
649 if (file->f_mode & FMODE_PATH || 649 if ((file->f_mode & mask) ||
650 !atomic_long_inc_not_zero(&file->f_count)) 650 !atomic_long_inc_not_zero(&file->f_count))
651 file = NULL; 651 file = NULL;
652 } 652 }
@@ -655,25 +655,16 @@ struct file *fget(unsigned int fd)
655 return file; 655 return file;
656} 656}
657 657
658struct file *fget(unsigned int fd)
659{
660 return __fget(fd, FMODE_PATH);
661}
658EXPORT_SYMBOL(fget); 662EXPORT_SYMBOL(fget);
659 663
660struct file *fget_raw(unsigned int fd) 664struct file *fget_raw(unsigned int fd)
661{ 665{
662 struct file *file; 666 return __fget(fd, 0);
663 struct files_struct *files = current->files;
664
665 rcu_read_lock();
666 file = fcheck_files(files, fd);
667 if (file) {
668 /* File object ref couldn't be taken */
669 if (!atomic_long_inc_not_zero(&file->f_count))
670 file = NULL;
671 }
672 rcu_read_unlock();
673
674 return file;
675} 667}
676
677EXPORT_SYMBOL(fget_raw); 668EXPORT_SYMBOL(fget_raw);
678 669
679/* 670/*