aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNamhyung Kim <namhyung@kernel.org>2013-12-12 02:36:06 -0500
committerArnaldo Carvalho de Melo <acme@redhat.com>2013-12-13 08:30:21 -0500
commit2e4eb10d7e59df71ab649343b3f1bff9259da15d (patch)
tree30798a9fa9c1602bd5347fb35e0c8a54c71b1924
parentef3072cd1d5c2ea229f7abf8d6475e0c200eeb71 (diff)
tools lib traceevent: Get rid of malloc_or_die() allocate_arg()
Also check return value and handle it. Signed-off-by: Namhyung Kim <namhyung@kernel.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-4-git-send-email-namhyung@kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
-rw-r--r--tools/lib/traceevent/parse-filter.c48
1 files changed, 40 insertions, 8 deletions
diff --git a/tools/lib/traceevent/parse-filter.c b/tools/lib/traceevent/parse-filter.c
index 767de4f1e8ee..ab9cefe320b4 100644
--- a/tools/lib/traceevent/parse-filter.c
+++ b/tools/lib/traceevent/parse-filter.c
@@ -211,12 +211,7 @@ struct event_filter *pevent_filter_alloc(struct pevent *pevent)
211 211
212static struct filter_arg *allocate_arg(void) 212static struct filter_arg *allocate_arg(void)
213{ 213{
214 struct filter_arg *arg; 214 return calloc(1, sizeof(struct filter_arg));
215
216 arg = malloc_or_die(sizeof(*arg));
217 memset(arg, 0, sizeof(*arg));
218
219 return arg;
220} 215}
221 216
222static void free_arg(struct filter_arg *arg) 217static void free_arg(struct filter_arg *arg)
@@ -369,6 +364,10 @@ create_arg_item(struct event_format *event, const char *token,
369 struct filter_arg *arg; 364 struct filter_arg *arg;
370 365
371 arg = allocate_arg(); 366 arg = allocate_arg();
367 if (arg == NULL) {
368 show_error(error_str, "failed to allocate filter arg");
369 return NULL;
370 }
372 371
373 switch (type) { 372 switch (type) {
374 373
@@ -422,6 +421,9 @@ create_arg_op(enum filter_op_type btype)
422 struct filter_arg *arg; 421 struct filter_arg *arg;
423 422
424 arg = allocate_arg(); 423 arg = allocate_arg();
424 if (!arg)
425 return NULL;
426
425 arg->type = FILTER_ARG_OP; 427 arg->type = FILTER_ARG_OP;
426 arg->op.type = btype; 428 arg->op.type = btype;
427 429
@@ -434,6 +436,9 @@ create_arg_exp(enum filter_exp_type etype)
434 struct filter_arg *arg; 436 struct filter_arg *arg;
435 437
436 arg = allocate_arg(); 438 arg = allocate_arg();
439 if (!arg)
440 return NULL;
441
437 arg->type = FILTER_ARG_EXP; 442 arg->type = FILTER_ARG_EXP;
438 arg->op.type = etype; 443 arg->op.type = etype;
439 444
@@ -446,6 +451,9 @@ create_arg_cmp(enum filter_exp_type etype)
446 struct filter_arg *arg; 451 struct filter_arg *arg;
447 452
448 arg = allocate_arg(); 453 arg = allocate_arg();
454 if (!arg)
455 return NULL;
456
449 /* Use NUM and change if necessary */ 457 /* Use NUM and change if necessary */
450 arg->type = FILTER_ARG_NUM; 458 arg->type = FILTER_ARG_NUM;
451 arg->op.type = etype; 459 arg->op.type = etype;
@@ -909,8 +917,10 @@ static struct filter_arg *collapse_tree(struct filter_arg *arg)
909 case FILTER_VAL_FALSE: 917 case FILTER_VAL_FALSE:
910 free_arg(arg); 918 free_arg(arg);
911 arg = allocate_arg(); 919 arg = allocate_arg();
912 arg->type = FILTER_ARG_BOOLEAN; 920 if (arg) {
913 arg->boolean.value = ret == FILTER_VAL_TRUE; 921 arg->type = FILTER_ARG_BOOLEAN;
922 arg->boolean.value = ret == FILTER_VAL_TRUE;
923 }
914 } 924 }
915 925
916 return arg; 926 return arg;
@@ -1057,6 +1067,8 @@ process_filter(struct event_format *event, struct filter_arg **parg,
1057 switch (op_type) { 1067 switch (op_type) {
1058 case OP_BOOL: 1068 case OP_BOOL:
1059 arg = create_arg_op(btype); 1069 arg = create_arg_op(btype);
1070 if (arg == NULL)
1071 goto fail_alloc;
1060 if (current_op) 1072 if (current_op)
1061 ret = add_left(arg, current_op); 1073 ret = add_left(arg, current_op);
1062 else 1074 else
@@ -1067,6 +1079,8 @@ process_filter(struct event_format *event, struct filter_arg **parg,
1067 1079
1068 case OP_NOT: 1080 case OP_NOT:
1069 arg = create_arg_op(btype); 1081 arg = create_arg_op(btype);
1082 if (arg == NULL)
1083 goto fail_alloc;
1070 if (current_op) 1084 if (current_op)
1071 ret = add_right(current_op, arg, error_str); 1085 ret = add_right(current_op, arg, error_str);
1072 if (ret < 0) 1086 if (ret < 0)
@@ -1086,6 +1100,8 @@ process_filter(struct event_format *event, struct filter_arg **parg,
1086 arg = create_arg_exp(etype); 1100 arg = create_arg_exp(etype);
1087 else 1101 else
1088 arg = create_arg_cmp(ctype); 1102 arg = create_arg_cmp(ctype);
1103 if (arg == NULL)
1104 goto fail_alloc;
1089 1105
1090 if (current_op) 1106 if (current_op)
1091 ret = add_right(current_op, arg, error_str); 1107 ret = add_right(current_op, arg, error_str);
@@ -1119,11 +1135,16 @@ process_filter(struct event_format *event, struct filter_arg **parg,
1119 current_op = current_exp; 1135 current_op = current_exp;
1120 1136
1121 current_op = collapse_tree(current_op); 1137 current_op = collapse_tree(current_op);
1138 if (current_op == NULL)
1139 goto fail_alloc;
1122 1140
1123 *parg = current_op; 1141 *parg = current_op;
1124 1142
1125 return 0; 1143 return 0;
1126 1144
1145 fail_alloc:
1146 show_error(error_str, "failed to allocate filter arg");
1147 goto fail;
1127 fail_print: 1148 fail_print:
1128 show_error(error_str, "Syntax error"); 1149 show_error(error_str, "Syntax error");
1129 fail: 1150 fail:
@@ -1154,6 +1175,10 @@ process_event(struct event_format *event, const char *filter_str,
1154 /* If parg is NULL, then make it into FALSE */ 1175 /* If parg is NULL, then make it into FALSE */
1155 if (!*parg) { 1176 if (!*parg) {
1156 *parg = allocate_arg(); 1177 *parg = allocate_arg();
1178 if (*parg == NULL) {
1179 show_error(error_str, "failed to allocate filter arg");
1180 return -1;
1181 }
1157 (*parg)->type = FILTER_ARG_BOOLEAN; 1182 (*parg)->type = FILTER_ARG_BOOLEAN;
1158 (*parg)->boolean.value = FILTER_FALSE; 1183 (*parg)->boolean.value = FILTER_FALSE;
1159 } 1184 }
@@ -1177,6 +1202,10 @@ static int filter_event(struct event_filter *filter,
1177 } else { 1202 } else {
1178 /* just add a TRUE arg */ 1203 /* just add a TRUE arg */
1179 arg = allocate_arg(); 1204 arg = allocate_arg();
1205 if (arg == NULL) {
1206 show_error(error_str, "failed to allocate filter arg");
1207 return -1;
1208 }
1180 arg->type = FILTER_ARG_BOOLEAN; 1209 arg->type = FILTER_ARG_BOOLEAN;
1181 arg->boolean.value = FILTER_TRUE; 1210 arg->boolean.value = FILTER_TRUE;
1182 } 1211 }
@@ -1418,6 +1447,9 @@ static int copy_filter_type(struct event_filter *filter,
1418 if (strcmp(str, "TRUE") == 0 || strcmp(str, "FALSE") == 0) { 1447 if (strcmp(str, "TRUE") == 0 || strcmp(str, "FALSE") == 0) {
1419 /* Add trivial event */ 1448 /* Add trivial event */
1420 arg = allocate_arg(); 1449 arg = allocate_arg();
1450 if (arg == NULL)
1451 return -1;
1452
1421 arg->type = FILTER_ARG_BOOLEAN; 1453 arg->type = FILTER_ARG_BOOLEAN;
1422 if (strcmp(str, "TRUE") == 0) 1454 if (strcmp(str, "TRUE") == 0)
1423 arg->boolean.value = 1; 1455 arg->boolean.value = 1;