[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <1411557356-10673-2-git-send-email-rob.jones@codethink.co.uk>
Date: Wed, 24 Sep 2014 12:15:55 +0100
From: Rob Jones <rob.jones@...ethink.co.uk>
To: rdunlap@...radead.org, viro@...iv.linux.org.uk
Cc: linux-doc@...r.kernel.org, linux-fsdevel@...r.kernel.org,
linux-kernel@...r.kernel.org, linux-kernel@...ethink.co.uk,
akpm@...ux-foundation.org, keescook@...omium.org,
penguin-kernel@...ove.SAKURA.ne.jp, rob.jones@...ethink.co.uk
Subject: [PATCH RESUBMIT 1/2] fs/seq_file: Create new function seq_open_init()
Add a new function to help reduce boilerplate code.
This is a wrapper function for seq_open() that will simplify the code in a
significant number of cases where seq_open() is currently called.
It's first use is in __seq_open_private(), thereby recovering most of
the code space used by the new function.
Signed-off-by: Rob Jones <rob.jones@...ethink.co.uk>
---
fs/seq_file.c | 34 ++++++++++++++++++++++------------
include/linux/seq_file.h | 1 +
2 files changed, 23 insertions(+), 12 deletions(-)
diff --git a/fs/seq_file.c b/fs/seq_file.c
index dc2dfec..4be3aa8 100644
--- a/fs/seq_file.c
+++ b/fs/seq_file.c
@@ -639,28 +639,38 @@ int seq_release_private(struct inode *inode, struct file *file)
}
EXPORT_SYMBOL(seq_release_private);
+int seq_open_init(struct file *f, const struct seq_operations *ops, void *p)
+{
+ struct seq_file *s;
+ int rc;
+
+ rc = seq_open(f, ops);
+ if (rc)
+ return rc;
+
+ s = f->private_data;
+ s->private = p;
+
+ return 0;
+}
+EXPORT_SYMBOL(seq_open_init);
+
void *__seq_open_private(struct file *f, const struct seq_operations *ops,
size_t psize)
{
int rc;
void *private;
- struct seq_file *seq;
private = kzalloc(psize, GFP_KERNEL);
- if (private == NULL)
- goto out;
+ if (!private)
+ return NULL;
- rc = seq_open(f, ops);
- if (rc < 0)
- goto out_free;
-
- seq = f->private_data;
- seq->private = private;
- return private;
+ rc = seq_open_init(f, ops, private);
+ if (!rc)
+ return private;
-out_free:
kfree(private);
-out:
+
return NULL;
}
EXPORT_SYMBOL(__seq_open_private);
diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
index 9382339..6b0d953 100644
--- a/include/linux/seq_file.h
+++ b/include/linux/seq_file.h
@@ -142,6 +142,7 @@ int single_open_size(struct file *, int (*)(struct seq_file *, void *), void *,
int single_release(struct inode *, struct file *);
void *__seq_open_private(struct file *, const struct seq_operations *, size_t);
int seq_open_private(struct file *, const struct seq_operations *, size_t);
+int seq_open_init(struct file *, const struct seq_operations *, void *);
int seq_release_private(struct inode *, struct file *);
int seq_put_decimal_ull(struct seq_file *m, char delimiter,
unsigned long long num);
--
1.7.10.4
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists