[PATCH 3/18] allow callers of seq_open do allocation themselves

From: Al Viro
Date: Mon Nov 07 2005 - 21:08:52 EST


From: Al Viro <viro@xxxxxxxxxxxxxxxxxx>
Date: 1131401734 -0500

Allows 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 <viro@xxxxxxxxxxxxxxxxxx>

---

fs/seq_file.c | 12 ++++++++----
1 files changed, 8 insertions(+), 4 deletions(-)

57865a0565080cc56de9aa5369ea1fc2b6477398
diff --git a/fs/seq_file.c b/fs/seq_file.c
--- a/fs/seq_file.c
+++ b/fs/seq_file.c
@@ -28,13 +28,17 @@
*/
int seq_open(struct file *file, struct seq_operations *op)
{
- struct seq_file *p = kmalloc(sizeof(*p), GFP_KERNEL);
- if (!p)
- return -ENOMEM;
+ struct seq_file *p = file->private_data;
+
+ if (!p) {
+ p = kmalloc(sizeof(*p), GFP_KERNEL);
+ if (!p)
+ return -ENOMEM;
+ file->private_data = p;
+ }
memset(p, 0, sizeof(*p));
sema_init(&p->sem, 1);
p->op = op;
- file->private_data = p;

/*
* Wrappers around seq_open(e.g. swaps_open) need to be
-
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/