Re: [Patch v2] proc: clean up /proc/<pid>/environ handling

From: Oleg Nesterov
Date: Tue Apr 03 2012 - 11:02:49 EST


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.

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/