Commit f3288338 authored by Rob Jones's avatar Rob Jones Committed by Linus Torvalds

fs/ocfs2/cluster/netdebug.c: use seq_open_private() not seq_open()

Reduce boilerplate code by using seq_open_private() instead of seq_open()

Note that the code in and using sc_common_open() has been quite
extensively changed.  Not least because there was a latent memory leak in
the code as was: if sc_common_open() failed, the previously allocated
buffer was not freed.
Signed-off-by: default avatarRob Jones <rob.jones@codethink.co.uk>
Cc: Joel Becker <jlbec@evilplan.org>
Cc: Mark Fasheh <mfasheh@suse.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 8f9ac032
...@@ -185,29 +185,13 @@ static const struct seq_operations nst_seq_ops = { ...@@ -185,29 +185,13 @@ static const struct seq_operations nst_seq_ops = {
static int nst_fop_open(struct inode *inode, struct file *file) static int nst_fop_open(struct inode *inode, struct file *file)
{ {
struct o2net_send_tracking *dummy_nst; struct o2net_send_tracking *dummy_nst;
struct seq_file *seq;
int ret;
dummy_nst = kmalloc(sizeof(struct o2net_send_tracking), GFP_KERNEL); dummy_nst = __seq_open_private(file, &nst_seq_ops, sizeof(*dummy_nst));
if (dummy_nst == NULL) { if (!dummy_nst)
ret = -ENOMEM; return -ENOMEM;
goto out;
}
dummy_nst->st_task = NULL;
ret = seq_open(file, &nst_seq_ops);
if (ret)
goto out;
seq = file->private_data;
seq->private = dummy_nst;
o2net_debug_add_nst(dummy_nst); o2net_debug_add_nst(dummy_nst);
dummy_nst = NULL; return 0;
out:
kfree(dummy_nst);
return ret;
} }
static int nst_fop_release(struct inode *inode, struct file *file) static int nst_fop_release(struct inode *inode, struct file *file)
...@@ -412,33 +396,27 @@ static const struct seq_operations sc_seq_ops = { ...@@ -412,33 +396,27 @@ static const struct seq_operations sc_seq_ops = {
.show = sc_seq_show, .show = sc_seq_show,
}; };
static int sc_common_open(struct file *file, struct o2net_sock_debug *sd) static int sc_common_open(struct file *file, int ctxt)
{ {
struct o2net_sock_debug *sd;
struct o2net_sock_container *dummy_sc; struct o2net_sock_container *dummy_sc;
struct seq_file *seq;
int ret;
dummy_sc = kmalloc(sizeof(struct o2net_sock_container), GFP_KERNEL); dummy_sc = kzalloc(sizeof(*dummy_sc), GFP_KERNEL);
if (dummy_sc == NULL) { if (!dummy_sc)
ret = -ENOMEM; return -ENOMEM;
goto out;
}
dummy_sc->sc_page = NULL;
ret = seq_open(file, &sc_seq_ops); sd = __seq_open_private(file, &sc_seq_ops, sizeof(*sd));
if (ret) if (!sd) {
goto out; kfree(dummy_sc);
return -ENOMEM;
}
seq = file->private_data; sd->dbg_ctxt = ctxt;
seq->private = sd;
sd->dbg_sock = dummy_sc; sd->dbg_sock = dummy_sc;
o2net_debug_add_sc(dummy_sc);
dummy_sc = NULL; o2net_debug_add_sc(dummy_sc);
out: return 0;
kfree(dummy_sc);
return ret;
} }
static int sc_fop_release(struct inode *inode, struct file *file) static int sc_fop_release(struct inode *inode, struct file *file)
...@@ -453,16 +431,7 @@ static int sc_fop_release(struct inode *inode, struct file *file) ...@@ -453,16 +431,7 @@ static int sc_fop_release(struct inode *inode, struct file *file)
static int stats_fop_open(struct inode *inode, struct file *file) static int stats_fop_open(struct inode *inode, struct file *file)
{ {
struct o2net_sock_debug *sd; return sc_common_open(file, SHOW_SOCK_STATS);
sd = kmalloc(sizeof(struct o2net_sock_debug), GFP_KERNEL);
if (sd == NULL)
return -ENOMEM;
sd->dbg_ctxt = SHOW_SOCK_STATS;
sd->dbg_sock = NULL;
return sc_common_open(file, sd);
} }
static const struct file_operations stats_seq_fops = { static const struct file_operations stats_seq_fops = {
...@@ -474,16 +443,7 @@ static const struct file_operations stats_seq_fops = { ...@@ -474,16 +443,7 @@ static const struct file_operations stats_seq_fops = {
static int sc_fop_open(struct inode *inode, struct file *file) static int sc_fop_open(struct inode *inode, struct file *file)
{ {
struct o2net_sock_debug *sd; return sc_common_open(file, SHOW_SOCK_CONTAINERS);
sd = kmalloc(sizeof(struct o2net_sock_debug), GFP_KERNEL);
if (sd == NULL)
return -ENOMEM;
sd->dbg_ctxt = SHOW_SOCK_CONTAINERS;
sd->dbg_sock = NULL;
return sc_common_open(file, sd);
} }
static const struct file_operations sc_seq_fops = { static const struct file_operations sc_seq_fops = {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment