From: Al Viro Date: Mon, 7 Nov 2005 22:15:34 +0000 (-0500) Subject: [PATCH] allow callers of seq_open do allocation themselves X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=1abe77b0fc4b485927f1f798ae81a752677e1d05;p=GitHub%2FLineageOS%2Fandroid_kernel_samsung_universal7580.git [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 Signed-off-by: Linus Torvalds --- diff --git a/fs/seq_file.c b/fs/seq_file.c index 38ef913767f..7c40570b71d 100644 --- 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