2 * trace_events_filter - generic event filtering
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 * Copyright (C) 2009 Tom Zanussi <tzanussi@gmail.com>
21 #include <linux/module.h>
22 #include <linux/ctype.h>
23 #include <linux/mutex.h>
26 #include "trace_output.h"
49 static struct filter_op filter_ops[] = {
59 { OP_NONE, "OP_NONE", 0 },
60 { OP_OPEN_PAREN, "(", 0 },
66 FILT_ERR_UNBALANCED_PAREN,
67 FILT_ERR_TOO_MANY_OPERANDS,
68 FILT_ERR_OPERAND_TOO_LONG,
69 FILT_ERR_FIELD_NOT_FOUND,
70 FILT_ERR_ILLEGAL_FIELD_OP,
71 FILT_ERR_ILLEGAL_INTVAL,
72 FILT_ERR_BAD_SUBSYS_FILTER,
73 FILT_ERR_TOO_MANY_PREDS,
74 FILT_ERR_MISSING_FIELD,
75 FILT_ERR_INVALID_FILTER,
78 static char *err_text[] = {
85 "Illegal operation for field type",
86 "Illegal integer value",
87 "Couldn't find or set field in one of a subsystem's events",
88 "Too many terms in predicate expression",
89 "Missing field name and/or value",
90 "Meaningless filter expression",
95 struct list_head list;
101 struct list_head list;
104 struct filter_parse_state {
105 struct filter_op *ops;
106 struct list_head opstack;
107 struct list_head postfix;
118 char string[MAX_FILTER_STR_VAL];
124 #define DEFINE_COMPARISON_PRED(type) \
125 static int filter_pred_##type(struct filter_pred *pred, void *event, \
126 int val1, int val2) \
128 type *addr = (type *)(event + pred->offset); \
129 type val = (type)pred->val; \
132 switch (pred->op) { \
134 match = (*addr < val); \
137 match = (*addr <= val); \
140 match = (*addr > val); \
143 match = (*addr >= val); \
152 #define DEFINE_EQUALITY_PRED(size) \
153 static int filter_pred_##size(struct filter_pred *pred, void *event, \
154 int val1, int val2) \
156 u##size *addr = (u##size *)(event + pred->offset); \
157 u##size val = (u##size)pred->val; \
160 match = (val == *addr) ^ pred->not; \
165 DEFINE_COMPARISON_PRED(s64);
166 DEFINE_COMPARISON_PRED(u64);
167 DEFINE_COMPARISON_PRED(s32);
168 DEFINE_COMPARISON_PRED(u32);
169 DEFINE_COMPARISON_PRED(s16);
170 DEFINE_COMPARISON_PRED(u16);
171 DEFINE_COMPARISON_PRED(s8);
172 DEFINE_COMPARISON_PRED(u8);
174 DEFINE_EQUALITY_PRED(64);
175 DEFINE_EQUALITY_PRED(32);
176 DEFINE_EQUALITY_PRED(16);
177 DEFINE_EQUALITY_PRED(8);
179 static int filter_pred_and(struct filter_pred *pred __attribute((unused)),
180 void *event __attribute((unused)),
186 static int filter_pred_or(struct filter_pred *pred __attribute((unused)),
187 void *event __attribute((unused)),
193 /* Filter predicate for fixed sized arrays of characters */
194 static int filter_pred_string(struct filter_pred *pred, void *event,
197 char *addr = (char *)(event + pred->offset);
200 cmp = pred->regex.match(addr, &pred->regex, pred->regex.field_len);
202 match = cmp ^ pred->not;
207 /* Filter predicate for char * pointers */
208 static int filter_pred_pchar(struct filter_pred *pred, void *event,
211 char **addr = (char **)(event + pred->offset);
214 cmp = pred->regex.match(*addr, &pred->regex, pred->regex.field_len);
216 match = cmp ^ pred->not;
222 * Filter predicate for dynamic sized arrays of characters.
223 * These are implemented through a list of strings at the end
225 * Also each of these strings have a field in the entry which
226 * contains its offset from the beginning of the entry.
227 * We have then first to get this field, dereference it
228 * and add it to the address of the entry, and at last we have
229 * the address of the string.
231 static int filter_pred_strloc(struct filter_pred *pred, void *event,
234 u32 str_item = *(u32 *)(event + pred->offset);
235 int str_loc = str_item & 0xffff;
236 int str_len = str_item >> 16;
237 char *addr = (char *)(event + str_loc);
240 cmp = pred->regex.match(addr, &pred->regex, str_len);
242 match = cmp ^ pred->not;
247 static int filter_pred_none(struct filter_pred *pred, void *event,
253 /* Basic regex callbacks */
254 static int regex_match_full(char *str, struct regex *r, int len)
256 if (strncmp(str, r->pattern, len) == 0)
261 static int regex_match_front(char *str, struct regex *r, int len)
263 if (strncmp(str, r->pattern, len) == 0)
268 static int regex_match_middle(char *str, struct regex *r, int len)
270 if (strstr(str, r->pattern))
275 static int regex_match_end(char *str, struct regex *r, int len)
277 char *ptr = strstr(str, r->pattern);
279 if (ptr && (ptr[r->len] == 0))
285 * filter_parse_regex - parse a basic regex
286 * @buff: the raw regex
287 * @len: length of the regex
288 * @search: will point to the beginning of the string to compare
289 * @not: tell whether the match will have to be inverted
291 * This passes in a buffer containing a regex and this function will
292 * set search to point to the search part of the buffer and
293 * return the type of search it is (see enum above).
294 * This does modify buff.
297 * search returns the pointer to use for comparison.
298 * not returns 1 if buff started with a '!'
301 enum regex_type filter_parse_regex(char *buff, int len, char **search, int *not)
303 int type = MATCH_FULL;
306 if (buff[0] == '!') {
315 for (i = 0; i < len; i++) {
316 if (buff[i] == '*') {
319 type = MATCH_END_ONLY;
321 if (type == MATCH_END_ONLY)
322 type = MATCH_MIDDLE_ONLY;
324 type = MATCH_FRONT_ONLY;
334 static void filter_build_regex(struct filter_pred *pred)
336 struct regex *r = &pred->regex;
338 enum regex_type type = MATCH_FULL;
341 if (pred->op == OP_GLOB) {
342 type = filter_parse_regex(r->pattern, r->len, &search, ¬);
343 r->len = strlen(search);
344 memmove(r->pattern, search, r->len+1);
349 r->match = regex_match_full;
351 case MATCH_FRONT_ONLY:
352 r->match = regex_match_front;
354 case MATCH_MIDDLE_ONLY:
355 r->match = regex_match_middle;
358 r->match = regex_match_end;
365 /* return 1 if event matches, 0 otherwise (discard) */
366 int filter_match_preds(struct ftrace_event_call *call, void *rec)
368 struct event_filter *filter = call->filter;
369 int match, top = 0, val1 = 0, val2 = 0;
370 int stack[MAX_FILTER_PRED];
371 struct filter_pred *pred;
374 for (i = 0; i < filter->n_preds; i++) {
375 pred = filter->preds[i];
377 match = pred->fn(pred, rec, val1, val2);
378 stack[top++] = match;
381 if (pred->pop_n > top) {
387 match = pred->fn(pred, rec, val1, val2);
388 stack[top++] = match;
393 EXPORT_SYMBOL_GPL(filter_match_preds);
395 static void parse_error(struct filter_parse_state *ps, int err, int pos)
398 ps->lasterr_pos = pos;
401 static void remove_filter_string(struct event_filter *filter)
403 kfree(filter->filter_string);
404 filter->filter_string = NULL;
407 static int replace_filter_string(struct event_filter *filter,
410 kfree(filter->filter_string);
411 filter->filter_string = kstrdup(filter_string, GFP_KERNEL);
412 if (!filter->filter_string)
418 static int append_filter_string(struct event_filter *filter,
422 char *new_filter_string;
424 BUG_ON(!filter->filter_string);
425 newlen = strlen(filter->filter_string) + strlen(string) + 1;
426 new_filter_string = kmalloc(newlen, GFP_KERNEL);
427 if (!new_filter_string)
430 strcpy(new_filter_string, filter->filter_string);
431 strcat(new_filter_string, string);
432 kfree(filter->filter_string);
433 filter->filter_string = new_filter_string;
438 static void append_filter_err(struct filter_parse_state *ps,
439 struct event_filter *filter)
441 int pos = ps->lasterr_pos;
444 buf = (char *)__get_free_page(GFP_TEMPORARY);
448 append_filter_string(filter, "\n");
449 memset(buf, ' ', PAGE_SIZE);
450 if (pos > PAGE_SIZE - 128)
453 pbuf = &buf[pos] + 1;
455 sprintf(pbuf, "\nparse_error: %s\n", err_text[ps->lasterr]);
456 append_filter_string(filter, buf);
457 free_page((unsigned long) buf);
460 void print_event_filter(struct ftrace_event_call *call, struct trace_seq *s)
462 struct event_filter *filter = call->filter;
464 mutex_lock(&event_mutex);
465 if (filter && filter->filter_string)
466 trace_seq_printf(s, "%s\n", filter->filter_string);
468 trace_seq_printf(s, "none\n");
469 mutex_unlock(&event_mutex);
472 void print_subsystem_event_filter(struct event_subsystem *system,
475 struct event_filter *filter = system->filter;
477 mutex_lock(&event_mutex);
478 if (filter && filter->filter_string)
479 trace_seq_printf(s, "%s\n", filter->filter_string);
481 trace_seq_printf(s, "none\n");
482 mutex_unlock(&event_mutex);
485 static struct ftrace_event_field *
486 find_event_field(struct ftrace_event_call *call, char *name)
488 struct ftrace_event_field *field;
490 list_for_each_entry(field, &call->fields, link) {
491 if (!strcmp(field->name, name))
498 static void filter_free_pred(struct filter_pred *pred)
503 kfree(pred->field_name);
507 static void filter_clear_pred(struct filter_pred *pred)
509 kfree(pred->field_name);
510 pred->field_name = NULL;
514 static int filter_set_pred(struct filter_pred *dest,
515 struct filter_pred *src,
519 if (src->field_name) {
520 dest->field_name = kstrdup(src->field_name, GFP_KERNEL);
521 if (!dest->field_name)
529 static void filter_disable_preds(struct ftrace_event_call *call)
531 struct event_filter *filter = call->filter;
534 call->filter_active = 0;
537 for (i = 0; i < MAX_FILTER_PRED; i++)
538 filter->preds[i]->fn = filter_pred_none;
541 void destroy_preds(struct ftrace_event_call *call)
543 struct event_filter *filter = call->filter;
549 for (i = 0; i < MAX_FILTER_PRED; i++) {
550 if (filter->preds[i])
551 filter_free_pred(filter->preds[i]);
553 kfree(filter->preds);
554 kfree(filter->filter_string);
559 static int init_preds(struct ftrace_event_call *call)
561 struct event_filter *filter;
562 struct filter_pred *pred;
568 filter = call->filter = kzalloc(sizeof(*filter), GFP_KERNEL);
574 filter->preds = kzalloc(MAX_FILTER_PRED * sizeof(pred), GFP_KERNEL);
578 for (i = 0; i < MAX_FILTER_PRED; i++) {
579 pred = kzalloc(sizeof(*pred), GFP_KERNEL);
582 pred->fn = filter_pred_none;
583 filter->preds[i] = pred;
594 static int init_subsystem_preds(struct event_subsystem *system)
596 struct ftrace_event_call *call;
599 list_for_each_entry(call, &ftrace_events, list) {
600 if (!call->define_fields)
603 if (strcmp(call->system, system->name) != 0)
606 err = init_preds(call);
614 static void filter_free_subsystem_preds(struct event_subsystem *system)
616 struct ftrace_event_call *call;
618 list_for_each_entry(call, &ftrace_events, list) {
619 if (!call->define_fields)
622 if (strcmp(call->system, system->name) != 0)
625 filter_disable_preds(call);
626 remove_filter_string(call->filter);
630 static int filter_add_pred_fn(struct filter_parse_state *ps,
631 struct ftrace_event_call *call,
632 struct filter_pred *pred,
635 struct event_filter *filter = call->filter;
638 if (filter->n_preds == MAX_FILTER_PRED) {
639 parse_error(ps, FILT_ERR_TOO_MANY_PREDS, 0);
643 idx = filter->n_preds;
644 filter_clear_pred(filter->preds[idx]);
645 err = filter_set_pred(filter->preds[idx], pred, fn);
650 call->filter_active = 1;
655 int filter_assign_type(const char *type)
657 if (strstr(type, "__data_loc") && strstr(type, "char"))
658 return FILTER_DYN_STRING;
660 if (strchr(type, '[') && strstr(type, "char"))
661 return FILTER_STATIC_STRING;
666 static bool is_string_field(struct ftrace_event_field *field)
668 return field->filter_type == FILTER_DYN_STRING ||
669 field->filter_type == FILTER_STATIC_STRING ||
670 field->filter_type == FILTER_PTR_STRING;
673 static int is_legal_op(struct ftrace_event_field *field, int op)
675 if (is_string_field(field) &&
676 (op != OP_EQ && op != OP_NE && op != OP_GLOB))
678 if (!is_string_field(field) && op == OP_GLOB)
684 static filter_pred_fn_t select_comparison_fn(int op, int field_size,
687 filter_pred_fn_t fn = NULL;
689 switch (field_size) {
691 if (op == OP_EQ || op == OP_NE)
693 else if (field_is_signed)
694 fn = filter_pred_s64;
696 fn = filter_pred_u64;
699 if (op == OP_EQ || op == OP_NE)
701 else if (field_is_signed)
702 fn = filter_pred_s32;
704 fn = filter_pred_u32;
707 if (op == OP_EQ || op == OP_NE)
709 else if (field_is_signed)
710 fn = filter_pred_s16;
712 fn = filter_pred_u16;
715 if (op == OP_EQ || op == OP_NE)
717 else if (field_is_signed)
727 static int filter_add_pred(struct filter_parse_state *ps,
728 struct ftrace_event_call *call,
729 struct filter_pred *pred,
732 struct ftrace_event_field *field;
734 unsigned long long val;
737 pred->fn = filter_pred_none;
739 if (pred->op == OP_AND) {
741 fn = filter_pred_and;
743 } else if (pred->op == OP_OR) {
749 field = find_event_field(call, pred->field_name);
751 parse_error(ps, FILT_ERR_FIELD_NOT_FOUND, 0);
755 pred->offset = field->offset;
757 if (!is_legal_op(field, pred->op)) {
758 parse_error(ps, FILT_ERR_ILLEGAL_FIELD_OP, 0);
762 if (is_string_field(field)) {
763 filter_build_regex(pred);
765 if (field->filter_type == FILTER_STATIC_STRING) {
766 fn = filter_pred_string;
767 pred->regex.field_len = field->size;
768 } else if (field->filter_type == FILTER_DYN_STRING)
769 fn = filter_pred_strloc;
771 fn = filter_pred_pchar;
772 pred->regex.field_len = strlen(pred->regex.pattern);
775 if (field->is_signed)
776 ret = strict_strtoll(pred->regex.pattern, 0, &val);
778 ret = strict_strtoull(pred->regex.pattern, 0, &val);
780 parse_error(ps, FILT_ERR_ILLEGAL_INTVAL, 0);
785 fn = select_comparison_fn(pred->op, field->size,
788 parse_error(ps, FILT_ERR_INVALID_OP, 0);
793 if (pred->op == OP_NE)
798 return filter_add_pred_fn(ps, call, pred, fn);
802 static void parse_init(struct filter_parse_state *ps,
803 struct filter_op *ops,
806 memset(ps, '\0', sizeof(*ps));
808 ps->infix.string = infix_string;
809 ps->infix.cnt = strlen(infix_string);
812 INIT_LIST_HEAD(&ps->opstack);
813 INIT_LIST_HEAD(&ps->postfix);
816 static char infix_next(struct filter_parse_state *ps)
820 return ps->infix.string[ps->infix.tail++];
823 static char infix_peek(struct filter_parse_state *ps)
825 if (ps->infix.tail == strlen(ps->infix.string))
828 return ps->infix.string[ps->infix.tail];
831 static void infix_advance(struct filter_parse_state *ps)
837 static inline int is_precedence_lower(struct filter_parse_state *ps,
840 return ps->ops[a].precedence < ps->ops[b].precedence;
843 static inline int is_op_char(struct filter_parse_state *ps, char c)
847 for (i = 0; strcmp(ps->ops[i].string, "OP_NONE"); i++) {
848 if (ps->ops[i].string[0] == c)
855 static int infix_get_op(struct filter_parse_state *ps, char firstc)
857 char nextc = infix_peek(ps);
865 for (i = 0; strcmp(ps->ops[i].string, "OP_NONE"); i++) {
866 if (!strcmp(opstr, ps->ops[i].string)) {
868 return ps->ops[i].id;
874 for (i = 0; strcmp(ps->ops[i].string, "OP_NONE"); i++) {
875 if (!strcmp(opstr, ps->ops[i].string))
876 return ps->ops[i].id;
882 static inline void clear_operand_string(struct filter_parse_state *ps)
884 memset(ps->operand.string, '\0', MAX_FILTER_STR_VAL);
885 ps->operand.tail = 0;
888 static inline int append_operand_char(struct filter_parse_state *ps, char c)
890 if (ps->operand.tail == MAX_FILTER_STR_VAL - 1)
893 ps->operand.string[ps->operand.tail++] = c;
898 static int filter_opstack_push(struct filter_parse_state *ps, int op)
900 struct opstack_op *opstack_op;
902 opstack_op = kmalloc(sizeof(*opstack_op), GFP_KERNEL);
907 list_add(&opstack_op->list, &ps->opstack);
912 static int filter_opstack_empty(struct filter_parse_state *ps)
914 return list_empty(&ps->opstack);
917 static int filter_opstack_top(struct filter_parse_state *ps)
919 struct opstack_op *opstack_op;
921 if (filter_opstack_empty(ps))
924 opstack_op = list_first_entry(&ps->opstack, struct opstack_op, list);
926 return opstack_op->op;
929 static int filter_opstack_pop(struct filter_parse_state *ps)
931 struct opstack_op *opstack_op;
934 if (filter_opstack_empty(ps))
937 opstack_op = list_first_entry(&ps->opstack, struct opstack_op, list);
939 list_del(&opstack_op->list);
946 static void filter_opstack_clear(struct filter_parse_state *ps)
948 while (!filter_opstack_empty(ps))
949 filter_opstack_pop(ps);
952 static char *curr_operand(struct filter_parse_state *ps)
954 return ps->operand.string;
957 static int postfix_append_operand(struct filter_parse_state *ps, char *operand)
959 struct postfix_elt *elt;
961 elt = kmalloc(sizeof(*elt), GFP_KERNEL);
966 elt->operand = kstrdup(operand, GFP_KERNEL);
972 list_add_tail(&elt->list, &ps->postfix);
977 static int postfix_append_op(struct filter_parse_state *ps, int op)
979 struct postfix_elt *elt;
981 elt = kmalloc(sizeof(*elt), GFP_KERNEL);
988 list_add_tail(&elt->list, &ps->postfix);
993 static void postfix_clear(struct filter_parse_state *ps)
995 struct postfix_elt *elt;
997 while (!list_empty(&ps->postfix)) {
998 elt = list_first_entry(&ps->postfix, struct postfix_elt, list);
999 list_del(&elt->list);
1000 kfree(elt->operand);
1005 static int filter_parse(struct filter_parse_state *ps)
1011 while ((ch = infix_next(ps))) {
1023 if (is_op_char(ps, ch)) {
1024 op = infix_get_op(ps, ch);
1025 if (op == OP_NONE) {
1026 parse_error(ps, FILT_ERR_INVALID_OP, 0);
1030 if (strlen(curr_operand(ps))) {
1031 postfix_append_operand(ps, curr_operand(ps));
1032 clear_operand_string(ps);
1035 while (!filter_opstack_empty(ps)) {
1036 top_op = filter_opstack_top(ps);
1037 if (!is_precedence_lower(ps, top_op, op)) {
1038 top_op = filter_opstack_pop(ps);
1039 postfix_append_op(ps, top_op);
1045 filter_opstack_push(ps, op);
1050 filter_opstack_push(ps, OP_OPEN_PAREN);
1055 if (strlen(curr_operand(ps))) {
1056 postfix_append_operand(ps, curr_operand(ps));
1057 clear_operand_string(ps);
1060 top_op = filter_opstack_pop(ps);
1061 while (top_op != OP_NONE) {
1062 if (top_op == OP_OPEN_PAREN)
1064 postfix_append_op(ps, top_op);
1065 top_op = filter_opstack_pop(ps);
1067 if (top_op == OP_NONE) {
1068 parse_error(ps, FILT_ERR_UNBALANCED_PAREN, 0);
1074 if (append_operand_char(ps, ch)) {
1075 parse_error(ps, FILT_ERR_OPERAND_TOO_LONG, 0);
1080 if (strlen(curr_operand(ps)))
1081 postfix_append_operand(ps, curr_operand(ps));
1083 while (!filter_opstack_empty(ps)) {
1084 top_op = filter_opstack_pop(ps);
1085 if (top_op == OP_NONE)
1087 if (top_op == OP_OPEN_PAREN) {
1088 parse_error(ps, FILT_ERR_UNBALANCED_PAREN, 0);
1091 postfix_append_op(ps, top_op);
1097 static struct filter_pred *create_pred(int op, char *operand1, char *operand2)
1099 struct filter_pred *pred;
1101 pred = kzalloc(sizeof(*pred), GFP_KERNEL);
1105 pred->field_name = kstrdup(operand1, GFP_KERNEL);
1106 if (!pred->field_name) {
1111 strcpy(pred->regex.pattern, operand2);
1112 pred->regex.len = strlen(pred->regex.pattern);
1119 static struct filter_pred *create_logical_pred(int op)
1121 struct filter_pred *pred;
1123 pred = kzalloc(sizeof(*pred), GFP_KERNEL);
1132 static int check_preds(struct filter_parse_state *ps)
1134 int n_normal_preds = 0, n_logical_preds = 0;
1135 struct postfix_elt *elt;
1137 list_for_each_entry(elt, &ps->postfix, list) {
1138 if (elt->op == OP_NONE)
1141 if (elt->op == OP_AND || elt->op == OP_OR) {
1148 if (!n_normal_preds || n_logical_preds >= n_normal_preds) {
1149 parse_error(ps, FILT_ERR_INVALID_FILTER, 0);
1156 static int replace_preds(struct ftrace_event_call *call,
1157 struct filter_parse_state *ps,
1158 char *filter_string,
1161 char *operand1 = NULL, *operand2 = NULL;
1162 struct filter_pred *pred;
1163 struct postfix_elt *elt;
1167 err = check_preds(ps);
1171 list_for_each_entry(elt, &ps->postfix, list) {
1172 if (elt->op == OP_NONE) {
1174 operand1 = elt->operand;
1176 operand2 = elt->operand;
1178 parse_error(ps, FILT_ERR_TOO_MANY_OPERANDS, 0);
1184 if (n_preds++ == MAX_FILTER_PRED) {
1185 parse_error(ps, FILT_ERR_TOO_MANY_PREDS, 0);
1189 if (elt->op == OP_AND || elt->op == OP_OR) {
1190 pred = create_logical_pred(elt->op);
1194 if (!operand1 || !operand2) {
1195 parse_error(ps, FILT_ERR_MISSING_FIELD, 0);
1199 pred = create_pred(elt->op, operand1, operand2);
1203 err = filter_add_pred(ps, call, pred, dry_run);
1204 filter_free_pred(pred);
1208 operand1 = operand2 = NULL;
1214 static int replace_system_preds(struct event_subsystem *system,
1215 struct filter_parse_state *ps,
1216 char *filter_string)
1218 struct ftrace_event_call *call;
1222 list_for_each_entry(call, &ftrace_events, list) {
1224 if (!call->define_fields)
1227 if (strcmp(call->system, system->name) != 0)
1230 /* try to see if the filter can be applied */
1231 err = replace_preds(call, ps, filter_string, true);
1235 /* really apply the filter */
1236 filter_disable_preds(call);
1237 err = replace_preds(call, ps, filter_string, false);
1239 filter_disable_preds(call);
1241 replace_filter_string(call->filter, filter_string);
1246 parse_error(ps, FILT_ERR_BAD_SUBSYS_FILTER, 0);
1252 int apply_event_filter(struct ftrace_event_call *call, char *filter_string)
1256 struct filter_parse_state *ps;
1258 mutex_lock(&event_mutex);
1260 err = init_preds(call);
1264 if (!strcmp(strstrip(filter_string), "0")) {
1265 filter_disable_preds(call);
1266 remove_filter_string(call->filter);
1267 mutex_unlock(&event_mutex);
1272 ps = kzalloc(sizeof(*ps), GFP_KERNEL);
1276 filter_disable_preds(call);
1277 replace_filter_string(call->filter, filter_string);
1279 parse_init(ps, filter_ops, filter_string);
1280 err = filter_parse(ps);
1282 append_filter_err(ps, call->filter);
1286 err = replace_preds(call, ps, filter_string, false);
1288 append_filter_err(ps, call->filter);
1291 filter_opstack_clear(ps);
1295 mutex_unlock(&event_mutex);
1300 int apply_subsystem_event_filter(struct event_subsystem *system,
1301 char *filter_string)
1305 struct filter_parse_state *ps;
1307 mutex_lock(&event_mutex);
1309 err = init_subsystem_preds(system);
1313 if (!strcmp(strstrip(filter_string), "0")) {
1314 filter_free_subsystem_preds(system);
1315 remove_filter_string(system->filter);
1316 mutex_unlock(&event_mutex);
1321 ps = kzalloc(sizeof(*ps), GFP_KERNEL);
1325 replace_filter_string(system->filter, filter_string);
1327 parse_init(ps, filter_ops, filter_string);
1328 err = filter_parse(ps);
1330 append_filter_err(ps, system->filter);
1334 err = replace_system_preds(system, ps, filter_string);
1336 append_filter_err(ps, system->filter);
1339 filter_opstack_clear(ps);
1343 mutex_unlock(&event_mutex);