aboutsummaryrefslogtreecommitdiffstats
path: root/fs/ocfs2/cluster/netdebug.c
diff options
context:
space:
mode:
authorRob Jones <rob.jones@codethink.co.uk>2014-10-09 18:25:07 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2014-10-09 22:25:47 -0400
commitf32883384846e1d4aa941c60dd8adb44093359c6 (patch)
tree26d4ee3341ea74efff74ed209dc4bf067c564e31 /fs/ocfs2/cluster/netdebug.c
parent8f9ac032322b855ff9f578efcb5de891dcf85e9b (diff)
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: Rob Jones <rob.jones@codethink.co.uk> Cc: Joel Becker <jlbec@evilplan.org> Cc: Mark Fasheh <mfasheh@suse.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'fs/ocfs2/cluster/netdebug.c')
-rw-r--r--fs/ocfs2/cluster/netdebug.c78
1 files changed, 19 insertions, 59 deletions
diff --git a/fs/ocfs2/cluster/netdebug.c b/fs/ocfs2/cluster/netdebug.c
index 73ba81928bce..27d1242c8383 100644
--- a/fs/ocfs2/cluster/netdebug.c
+++ b/fs/ocfs2/cluster/netdebug.c
@@ -185,29 +185,13 @@ static const struct seq_operations nst_seq_ops = {
185static int nst_fop_open(struct inode *inode, struct file *file) 185static int nst_fop_open(struct inode *inode, struct file *file)
186{ 186{
187 struct o2net_send_tracking *dummy_nst; 187 struct o2net_send_tracking *dummy_nst;
188 struct seq_file *seq;
189 int ret;
190 188
191 dummy_nst = kmalloc(sizeof(struct o2net_send_tracking), GFP_KERNEL); 189 dummy_nst = __seq_open_private(file, &nst_seq_ops, sizeof(*dummy_nst));
192 if (dummy_nst == NULL) { 190 if (!dummy_nst)
193 ret = -ENOMEM; 191 return -ENOMEM;
194 goto out;
195 }
196 dummy_nst->st_task = NULL;
197
198 ret = seq_open(file, &nst_seq_ops);
199 if (ret)
200 goto out;
201
202 seq = file->private_data;
203 seq->private = dummy_nst;
204 o2net_debug_add_nst(dummy_nst); 192 o2net_debug_add_nst(dummy_nst);
205 193
206 dummy_nst = NULL; 194 return 0;
207
208out:
209 kfree(dummy_nst);
210 return ret;
211} 195}
212 196
213static int nst_fop_release(struct inode *inode, struct file *file) 197static int nst_fop_release(struct inode *inode, struct file *file)
@@ -412,33 +396,27 @@ static const struct seq_operations sc_seq_ops = {
412 .show = sc_seq_show, 396 .show = sc_seq_show,
413}; 397};
414 398
415static int sc_common_open(struct file *file, struct o2net_sock_debug *sd) 399static int sc_common_open(struct file *file, int ctxt)
416{ 400{
401 struct o2net_sock_debug *sd;
417 struct o2net_sock_container *dummy_sc; 402 struct o2net_sock_container *dummy_sc;
418 struct seq_file *seq;
419 int ret;
420 403
421 dummy_sc = kmalloc(sizeof(struct o2net_sock_container), GFP_KERNEL); 404 dummy_sc = kzalloc(sizeof(*dummy_sc), GFP_KERNEL);
422 if (dummy_sc == NULL) { 405 if (!dummy_sc)
423 ret = -ENOMEM; 406 return -ENOMEM;
424 goto out;
425 }
426 dummy_sc->sc_page = NULL;
427 407
428 ret = seq_open(file, &sc_seq_ops); 408 sd = __seq_open_private(file, &sc_seq_ops, sizeof(*sd));
429 if (ret) 409 if (!sd) {
430 goto out; 410 kfree(dummy_sc);
411 return -ENOMEM;
412 }
431 413
432 seq = file->private_data; 414 sd->dbg_ctxt = ctxt;
433 seq->private = sd;
434 sd->dbg_sock = dummy_sc; 415 sd->dbg_sock = dummy_sc;
435 o2net_debug_add_sc(dummy_sc);
436 416
437 dummy_sc = NULL; 417 o2net_debug_add_sc(dummy_sc);
438 418
439out: 419 return 0;
440 kfree(dummy_sc);
441 return ret;
442} 420}
443 421
444static int sc_fop_release(struct inode *inode, struct file *file) 422static 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 431
454static int stats_fop_open(struct inode *inode, struct file *file) 432static int stats_fop_open(struct inode *inode, struct file *file)
455{ 433{
456 struct o2net_sock_debug *sd; 434 return sc_common_open(file, SHOW_SOCK_STATS);
457
458 sd = kmalloc(sizeof(struct o2net_sock_debug), GFP_KERNEL);
459 if (sd == NULL)
460 return -ENOMEM;
461
462 sd->dbg_ctxt = SHOW_SOCK_STATS;
463 sd->dbg_sock = NULL;
464
465 return sc_common_open(file, sd);
466} 435}
467 436
468static const struct file_operations stats_seq_fops = { 437static const struct file_operations stats_seq_fops = {
@@ -474,16 +443,7 @@ static const struct file_operations stats_seq_fops = {
474 443
475static int sc_fop_open(struct inode *inode, struct file *file) 444static int sc_fop_open(struct inode *inode, struct file *file)
476{ 445{
477 struct o2net_sock_debug *sd; 446 return sc_common_open(file, SHOW_SOCK_CONTAINERS);
478
479 sd = kmalloc(sizeof(struct o2net_sock_debug), GFP_KERNEL);
480 if (sd == NULL)
481 return -ENOMEM;
482
483 sd->dbg_ctxt = SHOW_SOCK_CONTAINERS;
484 sd->dbg_sock = NULL;
485
486 return sc_common_open(file, sd);
487} 447}
488 448
489static const struct file_operations sc_seq_fops = { 449static const struct file_operations sc_seq_fops = {