Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 287094
b: refs/heads/master
c: 6d08f2c
h: refs/heads/master
v: v3
  • Loading branch information
Oleg Nesterov authored and Linus Torvalds committed Feb 1, 2012
1 parent 5b365e8 commit 224c7b6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 572d34b946bae070debd42db1143034d9687e13f
refs/heads/master: 6d08f2c7139790c268820a2e590795cb8333181a
14 changes: 13 additions & 1 deletion trunk/fs/proc/base.c
Original file line number Diff line number Diff line change
Expand Up @@ -711,6 +711,13 @@ static int mem_open(struct inode* inode, struct file* file)
if (IS_ERR(mm))
return PTR_ERR(mm);

if (mm) {
/* ensure this mm_struct can't be freed */
atomic_inc(&mm->mm_count);
/* but do not pin its memory */
mmput(mm);
}

/* OK to pass negative loff_t, we can catch out-of-range */
file->f_mode |= FMODE_UNSIGNED_OFFSET;
file->private_data = mm;
Expand All @@ -734,6 +741,9 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
return -ENOMEM;

copied = 0;
if (!atomic_inc_not_zero(&mm->mm_users))
goto free;

while (count > 0) {
int this_len = min_t(int, count, PAGE_SIZE);

Expand Down Expand Up @@ -761,6 +771,8 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
}
*ppos = addr;

mmput(mm);
free:
free_page((unsigned long) page);
return copied;
}
Expand Down Expand Up @@ -797,7 +809,7 @@ static int mem_release(struct inode *inode, struct file *file)
{
struct mm_struct *mm = file->private_data;
if (mm)
mmput(mm);
mmdrop(mm);
return 0;
}

Expand Down

0 comments on commit 224c7b6

Please sign in to comment.