Skip to content

Commit

Permalink
fs: allocate structure unconditionally in seq_open()
Browse files Browse the repository at this point in the history
Since patch described below, from v2.6.15-rc1, seq_open() could use a
struct seq_file already allocated by the caller if the pointer to the
structure is stored in file->private_data before calling the function.

    Commit 1abe77b
    Author: Al Viro <[email protected]>
    Date:   Mon Nov 7 17:15:34 2005 -0500

        [PATCH] allow callers of seq_open do allocation themselves

        Allow caller of seq_open() to kmalloc() seq_file + whatever else they
        want and set ->private_data to it.  seq_open() will then abstain from
        doing allocation itself.

As there's no more use for such feature, as it could be easily replaced by
calls to seq_open_private() (see commit 3969903 ("[FS] seq_file:
Introduce the seq_open_private()")) and seq_release_private() (see
v2.6.0-test3), support for this uncommon feature can be removed from
seq_open().

Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Yann Droneaud <[email protected]>
Cc: Al Viro <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
ydroneaud authored and torvalds committed Jul 1, 2015
1 parent ede1bf0 commit 189f984
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions fs/seq_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,16 @@ static void *seq_buf_alloc(unsigned long size)
*/
int seq_open(struct file *file, const struct seq_operations *op)
{
struct seq_file *p = file->private_data;
struct seq_file *p;

WARN_ON(file->private_data);

p = kzalloc(sizeof(*p), GFP_KERNEL);
if (!p)
return -ENOMEM;

file->private_data = p;

if (!p) {
p = kmalloc(sizeof(*p), GFP_KERNEL);
if (!p)
return -ENOMEM;
file->private_data = p;
}
memset(p, 0, sizeof(*p));
mutex_init(&p->lock);
p->op = op;
#ifdef CONFIG_USER_NS
Expand Down

0 comments on commit 189f984

Please sign in to comment.