aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/trace/trace_events.c
diff options
context:
space:
mode:
authorLi Zefan <lizf@cn.fujitsu.com>2009-05-07 22:31:42 -0400
committerIngo Molnar <mingo@elte.hu>2009-05-08 08:00:35 -0400
commit8f31bfe538ebafac187d2d4465a92e1d9ee6d8c2 (patch)
tree660b7340cadca779314e04b960618d7ac1c7d425 /kernel/trace/trace_events.c
parent74f4fd21664148b8c454cc07bfe74e4dd51cf07b (diff)
tracing/events: clean up for ftrace_set_clr_event()
Add a helper function __ftrace_set_clr_event(), and replace some ftrace_set_clr_event() calls with this helper, thus we don't need any kstrdup() or kmalloc(). As a side effect, this patch fixes an issue in self tests code, which is similar to the one fixed in commit d6bf81ef0f7474434c2a049e8bf3c9146a14dd96 ("tracing: append ":*" to internal setting of system events") It's a small issue and won't cause any bug in fact, but we should do things right anyway. [ Impact: prevent spurious event-enabling in tracing self-tests ] Signed-off-by: Li Zefan <lizf@cn.fujitsu.com> Acked-by: Steven Rostedt <rostedt@goodmis.org> Acked-by: Frederic Weisbecker <fweisbec@gmail.com> LKML-Reference: <4A03998E.3020503@cn.fujitsu.com> Signed-off-by: Ingo Molnar <mingo@elte.hu>
Diffstat (limited to 'kernel/trace/trace_events.c')
-rw-r--r--kernel/trace/trace_events.c126
1 files changed, 46 insertions, 80 deletions
diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
index 8d0fae3af595..45f1099386b6 100644
--- a/kernel/trace/trace_events.c
+++ b/kernel/trace/trace_events.c
@@ -111,11 +111,44 @@ static void ftrace_event_enable_disable(struct ftrace_event_call *call,
111 } 111 }
112} 112}
113 113
114static int ftrace_set_clr_event(char *buf, int set) 114/*
115 * __ftrace_set_clr_event(NULL, NULL, NULL, set) will set/unset all events.
116 */
117static int __ftrace_set_clr_event(const char *match, const char *sub,
118 const char *event, int set)
115{ 119{
116 struct ftrace_event_call *call; 120 struct ftrace_event_call *call;
121 int ret;
122
123 mutex_lock(&event_mutex);
124 list_for_each_entry(call, &ftrace_events, list) {
125
126 if (!call->name || !call->regfunc)
127 continue;
128
129 if (match &&
130 strcmp(match, call->name) != 0 &&
131 strcmp(match, call->system) != 0)
132 continue;
133
134 if (sub && strcmp(sub, call->system) != 0)
135 continue;
136
137 if (event && strcmp(event, call->name) != 0)
138 continue;
139
140 ftrace_event_enable_disable(call, set);
141
142 ret = 0;
143 }
144 mutex_unlock(&event_mutex);
145
146 return ret;
147}
148
149static int ftrace_set_clr_event(char *buf, int set)
150{
117 char *event = NULL, *sub = NULL, *match; 151 char *event = NULL, *sub = NULL, *match;
118 int ret = -EINVAL;
119 152
120 /* 153 /*
121 * The buf format can be <subsystem>:<event-name> 154 * The buf format can be <subsystem>:<event-name>
@@ -141,30 +174,7 @@ static int ftrace_set_clr_event(char *buf, int set)
141 event = NULL; 174 event = NULL;
142 } 175 }
143 176
144 mutex_lock(&event_mutex); 177 return __ftrace_set_clr_event(match, sub, event, set);
145 list_for_each_entry(call, &ftrace_events, list) {
146
147 if (!call->name || !call->regfunc)
148 continue;
149
150 if (match &&
151 strcmp(match, call->name) != 0 &&
152 strcmp(match, call->system) != 0)
153 continue;
154
155 if (sub && strcmp(sub, call->system) != 0)
156 continue;
157
158 if (event && strcmp(event, call->name) != 0)
159 continue;
160
161 ftrace_event_enable_disable(call, set);
162
163 ret = 0;
164 }
165 mutex_unlock(&event_mutex);
166
167 return ret;
168} 178}
169 179
170/* 128 should be much more than enough */ 180/* 128 should be much more than enough */
@@ -408,18 +418,14 @@ system_enable_read(struct file *filp, char __user *ubuf, size_t cnt,
408 struct ftrace_event_call *call; 418 struct ftrace_event_call *call;
409 char buf[2]; 419 char buf[2];
410 int set = -1; 420 int set = -1;
411 int all = 0;
412 int ret; 421 int ret;
413 422
414 if (system[0] == '*')
415 all = 1;
416
417 mutex_lock(&event_mutex); 423 mutex_lock(&event_mutex);
418 list_for_each_entry(call, &ftrace_events, list) { 424 list_for_each_entry(call, &ftrace_events, list) {
419 if (!call->name || !call->regfunc) 425 if (!call->name || !call->regfunc)
420 continue; 426 continue;
421 427
422 if (!all && strcmp(call->system, system) != 0) 428 if (system && strcmp(call->system, system) != 0)
423 continue; 429 continue;
424 430
425 /* 431 /*
@@ -480,7 +486,6 @@ system_enable_write(struct file *filp, const char __user *ubuf, size_t cnt,
480{ 486{
481 const char *system = filp->private_data; 487 const char *system = filp->private_data;
482 unsigned long val; 488 unsigned long val;
483 char *command;
484 char buf[64]; 489 char buf[64];
485 ssize_t ret; 490 ssize_t ret;
486 491
@@ -500,30 +505,16 @@ system_enable_write(struct file *filp, const char __user *ubuf, size_t cnt,
500 if (ret < 0) 505 if (ret < 0)
501 return ret; 506 return ret;
502 507
503 switch (val) { 508 if (val != 0 && val != 1)
504 case 0:
505 case 1:
506 break;
507
508 default:
509 return -EINVAL; 509 return -EINVAL;
510 }
511 510
512 /* +3 for the ":*\0" */ 511 ret = __ftrace_set_clr_event(NULL, system, NULL, val);
513 command = kmalloc(strlen(system)+3, GFP_KERNEL);
514 if (!command)
515 return -ENOMEM;
516 sprintf(command, "%s:*", system);
517
518 ret = ftrace_set_clr_event(command, val);
519 if (ret) 512 if (ret)
520 goto out_free; 513 goto out;
521 514
522 ret = cnt; 515 ret = cnt;
523 516
524 out_free: 517out:
525 kfree(command);
526
527 *ppos += cnt; 518 *ppos += cnt;
528 519
529 return ret; 520 return ret;
@@ -1181,7 +1172,7 @@ static __init int event_trace_init(void)
1181 &ftrace_show_header_fops); 1172 &ftrace_show_header_fops);
1182 1173
1183 trace_create_file("enable", 0644, d_events, 1174 trace_create_file("enable", 0644, d_events,
1184 "*", &ftrace_system_enable_fops); 1175 NULL, &ftrace_system_enable_fops);
1185 1176
1186 for_each_event(call, __start_ftrace_events, __stop_ftrace_events) { 1177 for_each_event(call, __start_ftrace_events, __stop_ftrace_events) {
1187 /* The linker may leave blanks */ 1178 /* The linker may leave blanks */
@@ -1259,7 +1250,6 @@ static __init void event_trace_self_tests(void)
1259{ 1250{
1260 struct ftrace_event_call *call; 1251 struct ftrace_event_call *call;
1261 struct event_subsystem *system; 1252 struct event_subsystem *system;
1262 char *sysname;
1263 int ret; 1253 int ret;
1264 1254
1265 pr_info("Running tests on trace events:\n"); 1255 pr_info("Running tests on trace events:\n");
@@ -1305,14 +1295,7 @@ static __init void event_trace_self_tests(void)
1305 1295
1306 pr_info("Testing event system %s: ", system->name); 1296 pr_info("Testing event system %s: ", system->name);
1307 1297
1308 /* ftrace_set_clr_event can modify the name passed in. */ 1298 ret = __ftrace_set_clr_event(NULL, system->name, NULL, 1);
1309 sysname = kstrdup(system->name, GFP_KERNEL);
1310 if (WARN_ON(!sysname)) {
1311 pr_warning("Can't allocate memory, giving up!\n");
1312 return;
1313 }
1314 ret = ftrace_set_clr_event(sysname, 1);
1315 kfree(sysname);
1316 if (WARN_ON_ONCE(ret)) { 1299 if (WARN_ON_ONCE(ret)) {
1317 pr_warning("error enabling system %s\n", 1300 pr_warning("error enabling system %s\n",
1318 system->name); 1301 system->name);
@@ -1321,14 +1304,7 @@ static __init void event_trace_self_tests(void)
1321 1304
1322 event_test_stuff(); 1305 event_test_stuff();
1323 1306
1324 sysname = kstrdup(system->name, GFP_KERNEL); 1307 ret = __ftrace_set_clr_event(NULL, system->name, NULL, 0);
1325 if (WARN_ON(!sysname)) {
1326 pr_warning("Can't allocate memory, giving up!\n");
1327 return;
1328 }
1329 ret = ftrace_set_clr_event(sysname, 0);
1330 kfree(sysname);
1331
1332 if (WARN_ON_ONCE(ret)) 1308 if (WARN_ON_ONCE(ret))
1333 pr_warning("error disabling system %s\n", 1309 pr_warning("error disabling system %s\n",
1334 system->name); 1310 system->name);
@@ -1341,15 +1317,8 @@ static __init void event_trace_self_tests(void)
1341 pr_info("Running tests on all trace events:\n"); 1317 pr_info("Running tests on all trace events:\n");
1342 pr_info("Testing all events: "); 1318 pr_info("Testing all events: ");
1343 1319
1344 sysname = kmalloc(4, GFP_KERNEL); 1320 ret = __ftrace_set_clr_event(NULL, NULL, NULL, 1);
1345 if (WARN_ON(!sysname)) {
1346 pr_warning("Can't allocate memory, giving up!\n");
1347 return;
1348 }
1349 memcpy(sysname, "*:*", 4);
1350 ret = ftrace_set_clr_event(sysname, 1);
1351 if (WARN_ON_ONCE(ret)) { 1321 if (WARN_ON_ONCE(ret)) {
1352 kfree(sysname);
1353 pr_warning("error enabling all events\n"); 1322 pr_warning("error enabling all events\n");
1354 return; 1323 return;
1355 } 1324 }
@@ -1357,10 +1326,7 @@ static __init void event_trace_self_tests(void)
1357 event_test_stuff(); 1326 event_test_stuff();
1358 1327
1359 /* reset sysname */ 1328 /* reset sysname */
1360 memcpy(sysname, "*:*", 4); 1329 ret = __ftrace_set_clr_event(NULL, NULL, NULL, 0);
1361 ret = ftrace_set_clr_event(sysname, 0);
1362 kfree(sysname);
1363
1364 if (WARN_ON_ONCE(ret)) { 1330 if (WARN_ON_ONCE(ret)) {
1365 pr_warning("error disabling all events\n"); 1331 pr_warning("error disabling all events\n");
1366 return; 1332 return;