linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Yann Droneaud <ydroneaud@opteya.com>
To: Al Viro <viro@zeniv.linux.org.uk>
Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org,
	Yann Droneaud <ydroneaud@opteya.com>
Subject: [PATCH 2/3] fs: allocate structure unconditionally in seq_open()
Date: Tue,  5 May 2015 00:19:14 +0200	[thread overview]
Message-ID: <c45e0cf89a2de02524d7f1ebd7f4270a2ace0259.1430777196.git.ydroneaud@opteya.com> (raw)
In-Reply-To: <cover.1430777196.git.ydroneaud@opteya.com>
In-Reply-To: <cover.1430777196.git.ydroneaud@opteya.com>

Since following commit, from v2.6.15-rc1, seq_open()
could use a struct seq_file already allocated by the
caller if the pointer to the structure is stored in
file->private_data before calling the function.

    Commit 1abe77b0fc4b485927f1f798ae81a752677e1d05
    Author: Al Viro <viro@zeniv.linux.org.uk>
    Date:   Mon Nov 7 17:15:34 2005 -0500

        [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.

As there's no more use for such feature, as it could
be easily replaced by calls to seq_open_private(),
see commit 39699037a5c9 ("[FS] seq_file: Introduce
the seq_open_private()") and seq_release_private(),
see v2.6.0-test3, support for this uncommon feature
can be removed from seq_open().

Link: http://lkml.kernel.org/r/cover.1430777196.git.ydroneaud@opteya.com
Signed-off-by: Yann Droneaud <ydroneaud@opteya.com>
---
 fs/seq_file.c | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)

diff --git a/fs/seq_file.c b/fs/seq_file.c
index 555f82155be8..cb9c3dbd1a1e 100644
--- a/fs/seq_file.c
+++ b/fs/seq_file.c
@@ -51,14 +51,16 @@ static void *seq_buf_alloc(unsigned long size)
  */
 int seq_open(struct file *file, const struct seq_operations *op)
 {
-	struct seq_file *p = file->private_data;
+	struct seq_file *p;
+
+	WARN_ON(file->private_data);
+
+	p = kmalloc(sizeof(*p), GFP_KERNEL);
+	if (!p)
+		return -ENOMEM;
+
+	file->private_data = p;
 
-	if (!p) {
-		p = kmalloc(sizeof(*p), GFP_KERNEL);
-		if (!p)
-			return -ENOMEM;
-		file->private_data = p;
-	}
 	memset(p, 0, sizeof(*p));
 	mutex_init(&p->lock);
 	p->op = op;
-- 
2.1.0


  parent reply	other threads:[~2015-05-04 22:20 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-05-04 22:19 [PATCH 0/3] seq_file allocation in seq_open() Yann Droneaud
2015-05-04 22:19 ` [PATCH 1/3] fs: use seq_open_private() for proc_mounts Yann Droneaud
2015-05-04 22:19 ` Yann Droneaud [this message]
2015-05-04 22:19 ` [PATCH 3/3] fs: documents seq_open()'s usage of file->private_data Yann Droneaud

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=c45e0cf89a2de02524d7f1ebd7f4270a2ace0259.1430777196.git.ydroneaud@opteya.com \
    --to=ydroneaud@opteya.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=viro@zeniv.linux.org.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;
as well as URLs for NNTP newsgroup(s).