From: viro@parcelfarce.linux.theplanet.co.uk
To: Tigran Aivazian <tigran@aivazian.fsnet.co.uk>
Cc: Harald Welte <laforge@netfilter.org>, linux-kernel@vger.kernel.org
Subject: Re: seq_file API strangeness
Date: Fri, 14 Nov 2003 21:19:13 +0000 [thread overview]
Message-ID: <20031114211912.GL24159@parcelfarce.linux.theplanet.co.uk> (raw)
In-Reply-To: <Pine.LNX.4.44.0311142048520.849-100000@einstein.homenet>
On Fri, Nov 14, 2003 at 08:55:48PM +0000, Tigran Aivazian wrote:
> In the ->open() method I allocate a seq->private like this:
>
> err = seq_open(file, sop);
> if (!err) {
> struct seq_file *m = file->private_data;
>
> m->private = kmalloc(sizeof(struct ctask), GFP_KERNEL);
> if (!m->private) {
> kfree(file->private_data);
> return -ENOMEM;
> }
> }
>
> Now, freeing the structure that I did not allocate (file->private_data
> allocated in seq_open()) is not nice. But calling seq_release() from
> ->open() method is not nice either (different arguments, namely 'inode'
I beg your pardon? What different arguments?
->open() gets struct inode * and struct file *
->release() gets exactly the same.
seq_release() is what you use as ->release()
What's the problem?
> and also m->buf is NULL at that point, although I believe kfree(NULL) is
> not illegal).
Of course it is not illegal. Moreover, if you just do open() immediately
followed by close(), you won't get non-NULL ->buf at all. It's a perfectly
normal situation and seq_release() can handle it - no problems with that.
> What do you think?
if (!m->private) {
seq_release(inode, file);
return -ENOMEM;
}
Same as e.g. fs/proc/base.c does in similar situation (see mounts_open()).
next prev parent reply other threads:[~2003-11-14 21:19 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-11-14 20:06 Harald Welte
2003-11-14 20:23 ` viro
2003-11-14 20:55 ` Tigran Aivazian
2003-11-14 21:19 ` viro [this message]
2003-11-15 19:52 ` Tigran Aivazian
2003-11-15 19:54 ` Tigran Aivazian
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20031114211912.GL24159@parcelfarce.linux.theplanet.co.uk \
--to=viro@parcelfarce.linux.theplanet.co.uk \
--cc=laforge@netfilter.org \
--cc=linux-kernel@vger.kernel.org \
--cc=tigran@aivazian.fsnet.co.uk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®