aboutsummaryrefslogtreecommitdiffstats
path: root/tools/lib/traceevent
diff options
context:
space:
mode:
authorNamhyung Kim <namhyung@kernel.org>2013-12-12 02:36:08 -0500
committerArnaldo Carvalho de Melo <acme@redhat.com>2013-12-13 08:30:22 -0500
commit605b8fda958a578e0a50ed1df3cac5a12f1fe8dc (patch)
treea28e668c0c22484a355b5707c8a9dd308c53d496 /tools/lib/traceevent
parent91dfa49bdd8ef9600d850ef68ec892eb70824e3d (diff)
tools lib traceevent: Get rid of malloc_or_die() in find_event()
Make it return pevent_errno to distinguish malloc allocation failure. Since it'll be returned to user later, add more error code. Signed-off-by: Namhyung Kim <namhyung@kernel.org> Reviewed-by: Steven Rostedt <rostedt@goodmis.org> Cc: Frederic Weisbecker <fweisbec@gmail.com> Cc: Ingo Molnar <mingo@kernel.org> Cc: Jiri Olsa <jolsa@redhat.com> Cc: Namhyung Kim <namhyung.kim@lge.com> Cc: Peter Zijlstra <a.p.zijlstra@chello.nl> Cc: Steven Rostedt <rostedt@goodmis.org> Link: http://lkml.kernel.org/r/1386833777-3790-6-git-send-email-namhyung@kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/lib/traceevent')
-rw-r--r--tools/lib/traceevent/event-parse.h4
-rw-r--r--tools/lib/traceevent/parse-filter.c27
2 files changed, 22 insertions, 9 deletions
diff --git a/tools/lib/traceevent/event-parse.h b/tools/lib/traceevent/event-parse.h
index 6e23f197175f..abdfd3c606ed 100644
--- a/tools/lib/traceevent/event-parse.h
+++ b/tools/lib/traceevent/event-parse.h
@@ -356,7 +356,9 @@ enum pevent_flag {
356 _PE(READ_FORMAT_FAILED, "failed to read event format"), \ 356 _PE(READ_FORMAT_FAILED, "failed to read event format"), \
357 _PE(READ_PRINT_FAILED, "failed to read event print fmt"), \ 357 _PE(READ_PRINT_FAILED, "failed to read event print fmt"), \
358 _PE(OLD_FTRACE_ARG_FAILED,"failed to allocate field name for ftrace"),\ 358 _PE(OLD_FTRACE_ARG_FAILED,"failed to allocate field name for ftrace"),\
359 _PE(INVALID_ARG_TYPE, "invalid argument type") 359 _PE(INVALID_ARG_TYPE, "invalid argument type"), \
360 _PE(INVALID_EVENT_NAME, "invalid event name"), \
361 _PE(EVENT_NOT_FOUND, "No event found")
360 362
361#undef _PE 363#undef _PE
362#define _PE(__code, __str) PEVENT_ERRNO__ ## __code 364#define _PE(__code, __str) PEVENT_ERRNO__ ## __code
diff --git a/tools/lib/traceevent/parse-filter.c b/tools/lib/traceevent/parse-filter.c
index 246ee81e1f93..a0ab040e8f71 100644
--- a/tools/lib/traceevent/parse-filter.c
+++ b/tools/lib/traceevent/parse-filter.c
@@ -287,7 +287,7 @@ static int event_match(struct event_format *event,
287 !regexec(ereg, event->name, 0, NULL, 0); 287 !regexec(ereg, event->name, 0, NULL, 0);
288} 288}
289 289
290static int 290static enum pevent_errno
291find_event(struct pevent *pevent, struct event_list **events, 291find_event(struct pevent *pevent, struct event_list **events,
292 char *sys_name, char *event_name) 292 char *sys_name, char *event_name)
293{ 293{
@@ -306,23 +306,31 @@ find_event(struct pevent *pevent, struct event_list **events,
306 sys_name = NULL; 306 sys_name = NULL;
307 } 307 }
308 308
309 reg = malloc_or_die(strlen(event_name) + 3); 309 reg = malloc(strlen(event_name) + 3);
310 if (reg == NULL)
311 return PEVENT_ERRNO__MEM_ALLOC_FAILED;
312
310 sprintf(reg, "^%s$", event_name); 313 sprintf(reg, "^%s$", event_name);
311 314
312 ret = regcomp(&ereg, reg, REG_ICASE|REG_NOSUB); 315 ret = regcomp(&ereg, reg, REG_ICASE|REG_NOSUB);
313 free(reg); 316 free(reg);
314 317
315 if (ret) 318 if (ret)
316 return -1; 319 return PEVENT_ERRNO__INVALID_EVENT_NAME;
317 320
318 if (sys_name) { 321 if (sys_name) {
319 reg = malloc_or_die(strlen(sys_name) + 3); 322 reg = malloc(strlen(sys_name) + 3);
323 if (reg == NULL) {
324 regfree(&ereg);
325 return PEVENT_ERRNO__MEM_ALLOC_FAILED;
326 }
327
320 sprintf(reg, "^%s$", sys_name); 328 sprintf(reg, "^%s$", sys_name);
321 ret = regcomp(&sreg, reg, REG_ICASE|REG_NOSUB); 329 ret = regcomp(&sreg, reg, REG_ICASE|REG_NOSUB);
322 free(reg); 330 free(reg);
323 if (ret) { 331 if (ret) {
324 regfree(&ereg); 332 regfree(&ereg);
325 return -1; 333 return PEVENT_ERRNO__INVALID_EVENT_NAME;
326 } 334 }
327 } 335 }
328 336
@@ -342,9 +350,9 @@ find_event(struct pevent *pevent, struct event_list **events,
342 regfree(&sreg); 350 regfree(&sreg);
343 351
344 if (!match) 352 if (!match)
345 return -1; 353 return PEVENT_ERRNO__EVENT_NOT_FOUND;
346 if (fail) 354 if (fail)
347 return -2; 355 return PEVENT_ERRNO__MEM_ALLOC_FAILED;
348 356
349 return 0; 357 return 0;
350} 358}
@@ -1312,7 +1320,10 @@ int pevent_filter_add_filter_str(struct event_filter *filter,
1312 /* Find this event */ 1320 /* Find this event */
1313 ret = find_event(pevent, &events, strim(sys_name), strim(event_name)); 1321 ret = find_event(pevent, &events, strim(sys_name), strim(event_name));
1314 if (ret < 0) { 1322 if (ret < 0) {
1315 if (event_name) 1323 if (ret == PEVENT_ERRNO__MEM_ALLOC_FAILED)
1324 show_error(error_str,
1325 "Memory allocation failure");
1326 else if (event_name)
1316 show_error(error_str, 1327 show_error(error_str,
1317 "No event found under '%s.%s'", 1328 "No event found under '%s.%s'",
1318 sys_name, event_name); 1329 sys_name, event_name);