Messages in this thread | | | Date | Tue, 3 Apr 2012 17:02:25 +0200 | From | Oleg Nesterov <> | Subject | Re: [Patch v2] proc: clean up /proc/<pid>/environ handling |
| |
On 04/03, Cong Wang wrote: > > +static int environ_open(struct inode *inode, struct file *file) > +{ > + struct task_struct *task = get_proc_task(file->f_path.dentry->d_inode); > + struct mm_struct *mm; > + > + if (!task) > + return -ESRCH; > + > + mm = mm_for_maps(task); > + put_task_struct(task); > + > + 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); > + } > + > + file->private_data = mm; > + > + return 0; > +}
Well, can we unify this code with mem_open() ? Say, let it be __mem_open() or whatever, then mem_open() can use the common helper and add FMODE_UNSIGNED_OFFSET. Just we need another argument for mm_access.
> +static int environ_release(struct inode *inode, struct file *file) > +{ > + struct mm_struct *mm = file->private_data; > + if (mm) > + mmdrop(mm); > + return 0; > +}
Again, this is identical with mem_release(), proc_environ_operations can simply use it instead.
Oleg.
| |