Skip to content

Commit 1abe77b

Browse files
Al ViroLinus Torvalds
authored andcommitted
[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. Signed-off-by: Al Viro <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent ccd48bc commit 1abe77b

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

fs/seq_file.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,17 @@
2828
*/
2929
int seq_open(struct file *file, struct seq_operations *op)
3030
{
31-
struct seq_file *p = kmalloc(sizeof(*p), GFP_KERNEL);
32-
if (!p)
33-
return -ENOMEM;
31+
struct seq_file *p = file->private_data;
32+
33+
if (!p) {
34+
p = kmalloc(sizeof(*p), GFP_KERNEL);
35+
if (!p)
36+
return -ENOMEM;
37+
file->private_data = p;
38+
}
3439
memset(p, 0, sizeof(*p));
3540
sema_init(&p->sem, 1);
3641
p->op = op;
37-
file->private_data = p;
3842

3943
/*
4044
* Wrappers around seq_open(e.g. swaps_open) need to be

0 commit comments

Comments
 (0)