Skip to contentSkip to conversation

Initialize seq->private before seq_start()

DISCUSSION Max Krasnyansky 1 participant 1 message Nov 1, 2002

lore
Share & tools
lore
#0 lore raw

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