lkml.org 
[lkml]   [2013]   [Oct]   [17]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH] tracing: fix referencing after memory freeing and refactors code
Date
Restructures function logic conditions testing 'tracing_open_generic'
return before the others. It avoids: unnecessary trace_array_get and
kzalloc when tracing is disabled; and fix the possible 'dir'
assignment after freeing it.

Centralizes the exiting, ensuring the 'trace_array_put' on error,
in accordance to Coding Style, Chapter 7.

Signed-off-by: Geyslan G. Bem <geyslan@gmail.com>
---
kernel/trace/trace_events.c | 22 ++++++++++++----------
1 file changed, 12 insertions(+), 10 deletions(-)

diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
index 368a4d5..8232362 100644
--- a/kernel/trace/trace_events.c
+++ b/kernel/trace/trace_events.c
@@ -1108,26 +1108,28 @@ static int system_tr_open(struct inode *inode, struct file *filp)
struct trace_array *tr = inode->i_private;
int ret;

- if (trace_array_get(tr) < 0)
- return -ENODEV;
+ ret = tracing_open_generic(inode, filp);
+ if (ret)
+ return ret;
+
+ ret = trace_array_get(tr);
+ if (ret)
+ return ret;

/* Make a temporary dir that has no system but points to tr */
dir = kzalloc(sizeof(*dir), GFP_KERNEL);
if (!dir) {
- trace_array_put(tr);
- return -ENOMEM;
+ ret = -ENOMEM;
+ goto err_dir;
}

dir->tr = tr;

- ret = tracing_open_generic(inode, filp);
- if (ret < 0) {
- trace_array_put(tr);
- kfree(dir);
- }
-
filp->private_data = dir;
+ return 0;

+err_dir:
+ trace_array_put(tr);
return ret;
}

--
1.8.4


\
 
 \ /
  Last update: 2013-10-18 04:01    [W:0.062 / U:4.948 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site