From: Rob Jones <rob.jones@codethink.co.uk>
To: linux-kernel@vger.kernel.org
Cc: akpm@linux-foundation.org, linux-kernel@codethink.co.uk,
rob.jones@codethink.co.uk
Subject: [PATCH RESUBMIT] fs/proc/task_mmu: use __seq_open_private()
Date: Thu, 2 Oct 2014 17:40:26 +0100 [thread overview]
Message-ID: <1412268026-633-1-git-send-email-rob.jones@codethink.co.uk> (raw)
Reduce boilerplate code by using __seq_open_private() instead of seq_open().
This function has been around, undocumented, for years. It can simplify
the set up code for seq file operations.
Signed-off-by: Rob Jones <rob.jones@codethink.co.uk>
---
This patch was originally submitted on 12th September as part 2/2.
Part 1 was pipped at the post by someone else doing the same thing.
This part resubmitted as a stand-alone patch.
fs/proc/task_mmu.c | 42 ++++++++++++++++--------------------------
1 file changed, 16 insertions(+), 26 deletions(-)
diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
index 442177b..c8e9045 100644
--- a/fs/proc/task_mmu.c
+++ b/fs/proc/task_mmu.c
@@ -235,19 +235,14 @@ static int do_maps_open(struct inode *inode, struct file *file,
const struct seq_operations *ops)
{
struct proc_maps_private *priv;
- int ret = -ENOMEM;
- priv = kzalloc(sizeof(*priv), GFP_KERNEL);
- if (priv) {
- priv->pid = proc_pid(inode);
- ret = seq_open(file, ops);
- if (!ret) {
- struct seq_file *m = file->private_data;
- m->private = priv;
- } else {
- kfree(priv);
- }
- }
- return ret;
+
+ priv = __seq_open_private(file, ops, sizeof(*priv));
+ if (!priv)
+ return -ENOMEM;
+
+ priv->pid = proc_pid(inode);
+
+ return 0;
}
static void
@@ -1495,19 +1490,14 @@ static int numa_maps_open(struct inode *inode, struct file *file,
const struct seq_operations *ops)
{
struct numa_maps_private *priv;
- int ret = -ENOMEM;
- priv = kzalloc(sizeof(*priv), GFP_KERNEL);
- if (priv) {
- priv->proc_maps.pid = proc_pid(inode);
- ret = seq_open(file, ops);
- if (!ret) {
- struct seq_file *m = file->private_data;
- m->private = priv;
- } else {
- kfree(priv);
- }
- }
- return ret;
+
+ priv = __seq_open_private(file, ops, sizeof(*priv));
+ if (!priv)
+ return -ENOMEM;
+
+ priv->proc_maps.pid = proc_pid(inode);
+
+ return 0;
}
static int pid_numa_maps_open(struct inode *inode, struct file *file)
--
1.7.10.4
reply other threads:[~2014-10-02 16:40 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=1412268026-633-1-git-send-email-rob.jones@codethink.co.uk \
--to=rob.jones@codethink.co.uk \
--cc=akpm@linux-foundation.org \
--cc=linux-kernel@codethink.co.uk \
--cc=linux-kernel@vger.kernel.org \
/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®