diff options
author | Jiri Olsa <jolsa@redhat.com> | 2011-08-11 10:25:45 -0400 |
---|---|---|
committer | Steven Rostedt <rostedt@goodmis.org> | 2011-08-19 14:35:51 -0400 |
commit | 81570d9caaad46a056580c9af078c5c55e6c764f (patch) | |
tree | 7a0684a47659215b5714c4de64e5147c5be1c2a4 /kernel | |
parent | 2f3aa7a06f6f48d6f78a90595b17e6beafa7abf6 (diff) |
tracing/filter: Use static allocation for filter predicates
Don't dynamically allocate filter_pred struct, use static memory.
This way we can get rid of the code managing the dynamic filter_pred
struct object.
The create_pred function integrates create_logical_pred function.
This way the static predicate memory is returned only from
one place.
Signed-off-by: Jiri Olsa <jolsa@redhat.com>
Link: http://lkml.kernel.org/r/1313072754-4620-2-git-send-email-jolsa@redhat.com
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
Diffstat (limited to 'kernel')
-rw-r--r-- | kernel/trace/trace_events_filter.c | 57 |
1 files changed, 16 insertions, 41 deletions
diff --git a/kernel/trace/trace_events_filter.c b/kernel/trace/trace_events_filter.c index 256764ecccd6..cb295a117ee7 100644 --- a/kernel/trace/trace_events_filter.c +++ b/kernel/trace/trace_events_filter.c | |||
@@ -630,11 +630,7 @@ find_event_field(struct ftrace_event_call *call, char *name) | |||
630 | 630 | ||
631 | static void filter_free_pred(struct filter_pred *pred) | 631 | static void filter_free_pred(struct filter_pred *pred) |
632 | { | 632 | { |
633 | if (!pred) | ||
634 | return; | ||
635 | |||
636 | kfree(pred->field_name); | 633 | kfree(pred->field_name); |
637 | kfree(pred); | ||
638 | } | 634 | } |
639 | 635 | ||
640 | static void filter_clear_pred(struct filter_pred *pred) | 636 | static void filter_clear_pred(struct filter_pred *pred) |
@@ -1302,39 +1298,30 @@ parse_operand: | |||
1302 | return 0; | 1298 | return 0; |
1303 | } | 1299 | } |
1304 | 1300 | ||
1305 | static struct filter_pred *create_pred(int op, char *operand1, char *operand2) | 1301 | static struct filter_pred *create_pred(struct filter_parse_state *ps, |
1302 | int op, char *operand1, char *operand2) | ||
1306 | { | 1303 | { |
1307 | struct filter_pred *pred; | 1304 | static struct filter_pred pred; |
1308 | 1305 | ||
1309 | pred = kzalloc(sizeof(*pred), GFP_KERNEL); | 1306 | memset(&pred, 0, sizeof(pred)); |
1310 | if (!pred) | 1307 | pred.op = op; |
1311 | return NULL; | ||
1312 | 1308 | ||
1313 | pred->field_name = kstrdup(operand1, GFP_KERNEL); | 1309 | if (op == OP_AND || op == OP_OR) |
1314 | if (!pred->field_name) { | 1310 | return &pred; |
1315 | kfree(pred); | 1311 | |
1312 | if (!operand1 || !operand2) { | ||
1313 | parse_error(ps, FILT_ERR_MISSING_FIELD, 0); | ||
1316 | return NULL; | 1314 | return NULL; |
1317 | } | 1315 | } |
1318 | 1316 | ||
1319 | strcpy(pred->regex.pattern, operand2); | 1317 | pred.field_name = kstrdup(operand1, GFP_KERNEL); |
1320 | pred->regex.len = strlen(pred->regex.pattern); | 1318 | if (!pred.field_name) |
1321 | |||
1322 | pred->op = op; | ||
1323 | |||
1324 | return pred; | ||
1325 | } | ||
1326 | |||
1327 | static struct filter_pred *create_logical_pred(int op) | ||
1328 | { | ||
1329 | struct filter_pred *pred; | ||
1330 | |||
1331 | pred = kzalloc(sizeof(*pred), GFP_KERNEL); | ||
1332 | if (!pred) | ||
1333 | return NULL; | 1319 | return NULL; |
1334 | 1320 | ||
1335 | pred->op = op; | 1321 | strcpy(pred.regex.pattern, operand2); |
1322 | pred.regex.len = strlen(pred.regex.pattern); | ||
1336 | 1323 | ||
1337 | return pred; | 1324 | return &pred; |
1338 | } | 1325 | } |
1339 | 1326 | ||
1340 | static int check_preds(struct filter_parse_state *ps) | 1327 | static int check_preds(struct filter_parse_state *ps) |
@@ -1643,19 +1630,7 @@ static int replace_preds(struct ftrace_event_call *call, | |||
1643 | goto fail; | 1630 | goto fail; |
1644 | } | 1631 | } |
1645 | 1632 | ||
1646 | if (elt->op == OP_AND || elt->op == OP_OR) { | 1633 | pred = create_pred(ps, elt->op, operand1, operand2); |
1647 | pred = create_logical_pred(elt->op); | ||
1648 | goto add_pred; | ||
1649 | } | ||
1650 | |||
1651 | if (!operand1 || !operand2) { | ||
1652 | parse_error(ps, FILT_ERR_MISSING_FIELD, 0); | ||
1653 | err = -EINVAL; | ||
1654 | goto fail; | ||
1655 | } | ||
1656 | |||
1657 | pred = create_pred(elt->op, operand1, operand2); | ||
1658 | add_pred: | ||
1659 | if (!pred) { | 1634 | if (!pred) { |
1660 | err = -ENOMEM; | 1635 | err = -ENOMEM; |
1661 | goto fail; | 1636 | goto fail; |