aboutsummaryrefslogtreecommitdiffstats
path: root/fs/proc/base.c
diff options
context:
space:
mode:
authorOleg Nesterov <oleg@redhat.com>2014-10-09 18:25:24 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2014-10-09 22:25:48 -0400
commit5381e169e78405bd54256860f151596f5a887617 (patch)
treeef00fbd66715e1856fba055d5b8205dd9725ea93 /fs/proc/base.c
parent4db7d0ee198d417f4144c58048fcb173d90096ea (diff)
proc: introduce proc_mem_open()
Extract the mm_access() code from __mem_open() into the new helper, proc_mem_open(), the next patch will add another caller. Signed-off-by: Oleg Nesterov <oleg@redhat.com> Acked-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com> Acked-by: Cyrill Gorcunov <gorcunov@openvz.org> Cc: "Eric W. Biederman" <ebiederm@xmission.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'fs/proc/base.c')
-rw-r--r--fs/proc/base.c36
1 files changed, 21 insertions, 15 deletions
diff --git a/fs/proc/base.c b/fs/proc/base.c
index baf852b648ad..4c542b907754 100644
--- a/fs/proc/base.c
+++ b/fs/proc/base.c
@@ -632,29 +632,35 @@ static const struct file_operations proc_single_file_operations = {
632 .release = single_release, 632 .release = single_release,
633}; 633};
634 634
635static int __mem_open(struct inode *inode, struct file *file, unsigned int mode) 635
636struct mm_struct *proc_mem_open(struct inode *inode, unsigned int mode)
636{ 637{
637 struct task_struct *task = get_proc_task(file_inode(file)); 638 struct task_struct *task = get_proc_task(inode);
638 struct mm_struct *mm; 639 struct mm_struct *mm = ERR_PTR(-ESRCH);
639 640
640 if (!task) 641 if (task) {
641 return -ESRCH; 642 mm = mm_access(task, mode);
643 put_task_struct(task);
642 644
643 mm = mm_access(task, mode); 645 if (!IS_ERR_OR_NULL(mm)) {
644 put_task_struct(task); 646 /* ensure this mm_struct can't be freed */
647 atomic_inc(&mm->mm_count);
648 /* but do not pin its memory */
649 mmput(mm);
650 }
651 }
652
653 return mm;
654}
655
656static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
657{
658 struct mm_struct *mm = proc_mem_open(inode, mode);
645 659
646 if (IS_ERR(mm)) 660 if (IS_ERR(mm))
647 return PTR_ERR(mm); 661 return PTR_ERR(mm);
648 662
649 if (mm) {
650 /* ensure this mm_struct can't be freed */
651 atomic_inc(&mm->mm_count);
652 /* but do not pin its memory */
653 mmput(mm);
654 }
655
656 file->private_data = mm; 663 file->private_data = mm;
657
658 return 0; 664 return 0;
659} 665}
660 666