Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1abe77b0 authored by Al Viro's avatar Al Viro Committed by Linus Torvalds
Browse files

[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: default avatarAl Viro <viro@zeniv.linux.org.uk>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent ccd48bc7
Loading
Loading
Loading
Loading
+8 −4
Original line number Original line Diff line number Diff line
@@ -28,13 +28,17 @@
 */
 */
int seq_open(struct file *file, struct seq_operations *op)
int seq_open(struct file *file, struct seq_operations *op)
{
{
	struct seq_file *p = kmalloc(sizeof(*p), GFP_KERNEL);
	struct seq_file *p = file->private_data;

	if (!p) {
		p = kmalloc(sizeof(*p), GFP_KERNEL);
		if (!p)
		if (!p)
			return -ENOMEM;
			return -ENOMEM;
		file->private_data = p;
	}
	memset(p, 0, sizeof(*p));
	memset(p, 0, sizeof(*p));
	sema_init(&p->sem, 1);
	sema_init(&p->sem, 1);
	p->op = op;
	p->op = op;
	file->private_data = p;


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