Initialize seq->private before seq_start()

Max Krasnyansky (maxk@qualcomm.com)
Fri, 01 Nov 2002 15:12:47 -0800


Folks,

Currently seq_file API doesn't provide any way to initialize seq->private before
seq_start() is called. In most cases seq_start() uses global tables and
stuff and therefor doesn't need seq->private. However there are cases like
proc/something/0/table
...
proc/something/N/table
and seq_start() has to know where to look for table N.

So, how about something like:

#define seq_open(file, op) __seq_open(file, op, NULL)

int __seq_open(struct file *file, struct seq_operations *op, void *priv)
{
struct seq_file *p = kmalloc(sizeof(*p), GFP_KERNEL);
if (!p)
return -ENOMEM;
memset(p, 0, sizeof(*p));
sema_init(&p->sem, 1);
p->op = op;
p->private = priv;
file->private_data = p;
return 0;
}

Those who need seq->private in seq_start() (that'd be me :)) will use __seq_open().

Currently I have
static int hci_seq_open(struct file *file, struct seq_operations *op, void *priv)
{
struct seq_file *seq;

if (seq_open(file, op))
return -ENOMEM;

seq = file->private_data;
seq->private = priv;
return 0;
}
and it'd be nice if I could get rid of that function and use __seq_file instead.

Max

http://bluez.sf.net
http://vtun.sf.net

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/