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/debugfs.h>
22 #include <linux/uaccess.h>
23 #include <linux/module.h>
24 #include <linux/ctype.h>
25 #include <linux/mutex.h>
28 #include "trace_output.h"
50 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_COMPARISON_PRED(s64
);
125 DEFINE_COMPARISON_PRED(u64
);
126 DEFINE_COMPARISON_PRED(s32
);
127 DEFINE_COMPARISON_PRED(u32
);
128 DEFINE_COMPARISON_PRED(s16
);
129 DEFINE_COMPARISON_PRED(u16
);
130 DEFINE_COMPARISON_PRED(s8
);
131 DEFINE_COMPARISON_PRED(u8
);
133 DEFINE_EQUALITY_PRED(64);
134 DEFINE_EQUALITY_PRED(32);
135 DEFINE_EQUALITY_PRED(16);
136 DEFINE_EQUALITY_PRED(8);
138 static int filter_pred_and(struct filter_pred
*pred
__attribute((unused
)),
139 void *event
__attribute((unused
)),
145 static int filter_pred_or(struct filter_pred
*pred
__attribute((unused
)),
146 void *event
__attribute((unused
)),
152 /* Filter predicate for fixed sized arrays of characters */
153 static int filter_pred_string(struct filter_pred
*pred
, void *event
,
156 char *addr
= (char *)(event
+ pred
->offset
);
159 cmp
= strncmp(addr
, pred
->str_val
, pred
->str_len
);
161 match
= (!cmp
) ^ pred
->not;
166 /* Filter predicate for char * pointers */
167 static int filter_pred_pchar(struct filter_pred
*pred
, void *event
,
170 char **addr
= (char **)(event
+ pred
->offset
);
173 cmp
= strncmp(*addr
, pred
->str_val
, pred
->str_len
);
175 match
= (!cmp
) ^ pred
->not;
181 * Filter predicate for dynamic sized arrays of characters.
182 * These are implemented through a list of strings at the end
184 * Also each of these strings have a field in the entry which
185 * contains its offset from the beginning of the entry.
186 * We have then first to get this field, dereference it
187 * and add it to the address of the entry, and at last we have
188 * the address of the string.
190 static int filter_pred_strloc(struct filter_pred
*pred
, void *event
,
193 u32 str_item
= *(u32
*)(event
+ pred
->offset
);
194 int str_loc
= str_item
& 0xffff;
195 int str_len
= str_item
>> 16;
196 char *addr
= (char *)(event
+ str_loc
);
199 cmp
= strncmp(addr
, pred
->str_val
, str_len
);
201 match
= (!cmp
) ^ pred
->not;
206 static int filter_pred_none(struct filter_pred
*pred
, void *event
,
212 /* return 1 if event matches, 0 otherwise (discard) */
213 int filter_match_preds(struct ftrace_event_call
*call
, void *rec
)
215 struct event_filter
*filter
= call
->filter
;
216 int match
, top
= 0, val1
= 0, val2
= 0;
217 int stack
[MAX_FILTER_PRED
];
218 struct filter_pred
*pred
;
221 for (i
= 0; i
< filter
->n_preds
; i
++) {
222 pred
= filter
->preds
[i
];
224 match
= pred
->fn(pred
, rec
, val1
, val2
);
225 stack
[top
++] = match
;
228 if (pred
->pop_n
> top
) {
234 match
= pred
->fn(pred
, rec
, val1
, val2
);
235 stack
[top
++] = match
;
240 EXPORT_SYMBOL_GPL(filter_match_preds
);
242 static void parse_error(struct filter_parse_state
*ps
, int err
, int pos
)
245 ps
->lasterr_pos
= pos
;
248 static void remove_filter_string(struct event_filter
*filter
)
250 kfree(filter
->filter_string
);
251 filter
->filter_string
= NULL
;
254 static int replace_filter_string(struct event_filter
*filter
,
257 kfree(filter
->filter_string
);
258 filter
->filter_string
= kstrdup(filter_string
, GFP_KERNEL
);
259 if (!filter
->filter_string
)
265 static int append_filter_string(struct event_filter
*filter
,
269 char *new_filter_string
;
271 BUG_ON(!filter
->filter_string
);
272 newlen
= strlen(filter
->filter_string
) + strlen(string
) + 1;
273 new_filter_string
= kmalloc(newlen
, GFP_KERNEL
);
274 if (!new_filter_string
)
277 strcpy(new_filter_string
, filter
->filter_string
);
278 strcat(new_filter_string
, string
);
279 kfree(filter
->filter_string
);
280 filter
->filter_string
= new_filter_string
;
285 static void append_filter_err(struct filter_parse_state
*ps
,
286 struct event_filter
*filter
)
288 int pos
= ps
->lasterr_pos
;
291 buf
= (char *)__get_free_page(GFP_TEMPORARY
);
295 append_filter_string(filter
, "\n");
296 memset(buf
, ' ', PAGE_SIZE
);
297 if (pos
> PAGE_SIZE
- 128)
300 pbuf
= &buf
[pos
] + 1;
302 sprintf(pbuf
, "\nparse_error: %s\n", err_text
[ps
->lasterr
]);
303 append_filter_string(filter
, buf
);
304 free_page((unsigned long) buf
);
307 void print_event_filter(struct ftrace_event_call
*call
, struct trace_seq
*s
)
309 struct event_filter
*filter
= call
->filter
;
311 mutex_lock(&event_mutex
);
312 if (filter
&& filter
->filter_string
)
313 trace_seq_printf(s
, "%s\n", filter
->filter_string
);
315 trace_seq_printf(s
, "none\n");
316 mutex_unlock(&event_mutex
);
319 void print_subsystem_event_filter(struct event_subsystem
*system
,
322 struct event_filter
*filter
= system
->filter
;
324 mutex_lock(&event_mutex
);
325 if (filter
&& filter
->filter_string
)
326 trace_seq_printf(s
, "%s\n", filter
->filter_string
);
328 trace_seq_printf(s
, "none\n");
329 mutex_unlock(&event_mutex
);
332 static struct ftrace_event_field
*
333 find_event_field(struct ftrace_event_call
*call
, char *name
)
335 struct ftrace_event_field
*field
;
337 list_for_each_entry(field
, &call
->fields
, link
) {
338 if (!strcmp(field
->name
, name
))
345 static void filter_free_pred(struct filter_pred
*pred
)
350 kfree(pred
->field_name
);
354 static void filter_clear_pred(struct filter_pred
*pred
)
356 kfree(pred
->field_name
);
357 pred
->field_name
= NULL
;
361 static int filter_set_pred(struct filter_pred
*dest
,
362 struct filter_pred
*src
,
366 if (src
->field_name
) {
367 dest
->field_name
= kstrdup(src
->field_name
, GFP_KERNEL
);
368 if (!dest
->field_name
)
376 static void filter_disable_preds(struct ftrace_event_call
*call
)
378 struct event_filter
*filter
= call
->filter
;
381 call
->filter_active
= 0;
384 for (i
= 0; i
< MAX_FILTER_PRED
; i
++)
385 filter
->preds
[i
]->fn
= filter_pred_none
;
388 void destroy_preds(struct ftrace_event_call
*call
)
390 struct event_filter
*filter
= call
->filter
;
396 for (i
= 0; i
< MAX_FILTER_PRED
; i
++) {
397 if (filter
->preds
[i
])
398 filter_free_pred(filter
->preds
[i
]);
400 kfree(filter
->preds
);
401 kfree(filter
->filter_string
);
406 static int init_preds(struct ftrace_event_call
*call
)
408 struct event_filter
*filter
;
409 struct filter_pred
*pred
;
415 filter
= call
->filter
= kzalloc(sizeof(*filter
), GFP_KERNEL
);
421 filter
->preds
= kzalloc(MAX_FILTER_PRED
* sizeof(pred
), GFP_KERNEL
);
425 for (i
= 0; i
< MAX_FILTER_PRED
; i
++) {
426 pred
= kzalloc(sizeof(*pred
), GFP_KERNEL
);
429 pred
->fn
= filter_pred_none
;
430 filter
->preds
[i
] = pred
;
441 static int init_subsystem_preds(struct event_subsystem
*system
)
443 struct ftrace_event_call
*call
;
446 list_for_each_entry(call
, &ftrace_events
, list
) {
447 if (!call
->define_fields
)
450 if (strcmp(call
->system
, system
->name
) != 0)
453 err
= init_preds(call
);
463 FILTER_INIT_NO_RESET
,
464 FILTER_SKIP_NO_RESET
,
467 static void filter_free_subsystem_preds(struct event_subsystem
*system
,
470 struct ftrace_event_call
*call
;
472 list_for_each_entry(call
, &ftrace_events
, list
) {
473 if (!call
->define_fields
)
476 if (strcmp(call
->system
, system
->name
) != 0)
479 if (flag
== FILTER_INIT_NO_RESET
) {
480 call
->filter
->no_reset
= false;
484 if (flag
== FILTER_SKIP_NO_RESET
&& call
->filter
->no_reset
)
487 filter_disable_preds(call
);
488 remove_filter_string(call
->filter
);
492 static int filter_add_pred_fn(struct filter_parse_state
*ps
,
493 struct ftrace_event_call
*call
,
494 struct filter_pred
*pred
,
497 struct event_filter
*filter
= call
->filter
;
500 if (filter
->n_preds
== MAX_FILTER_PRED
) {
501 parse_error(ps
, FILT_ERR_TOO_MANY_PREDS
, 0);
505 idx
= filter
->n_preds
;
506 filter_clear_pred(filter
->preds
[idx
]);
507 err
= filter_set_pred(filter
->preds
[idx
], pred
, fn
);
512 call
->filter_active
= 1;
517 int filter_assign_type(const char *type
)
519 if (strstr(type
, "__data_loc") && strstr(type
, "char"))
520 return FILTER_DYN_STRING
;
522 if (strchr(type
, '[') && strstr(type
, "char"))
523 return FILTER_STATIC_STRING
;
528 static bool is_string_field(struct ftrace_event_field
*field
)
530 return field
->filter_type
== FILTER_DYN_STRING
||
531 field
->filter_type
== FILTER_STATIC_STRING
||
532 field
->filter_type
== FILTER_PTR_STRING
;
535 static int is_legal_op(struct ftrace_event_field
*field
, int op
)
537 if (is_string_field(field
) && (op
!= OP_EQ
&& op
!= OP_NE
))
543 static filter_pred_fn_t
select_comparison_fn(int op
, int field_size
,
546 filter_pred_fn_t fn
= NULL
;
548 switch (field_size
) {
550 if (op
== OP_EQ
|| op
== OP_NE
)
552 else if (field_is_signed
)
553 fn
= filter_pred_s64
;
555 fn
= filter_pred_u64
;
558 if (op
== OP_EQ
|| op
== OP_NE
)
560 else if (field_is_signed
)
561 fn
= filter_pred_s32
;
563 fn
= filter_pred_u32
;
566 if (op
== OP_EQ
|| op
== OP_NE
)
568 else if (field_is_signed
)
569 fn
= filter_pred_s16
;
571 fn
= filter_pred_u16
;
574 if (op
== OP_EQ
|| op
== OP_NE
)
576 else if (field_is_signed
)
586 static int filter_add_pred(struct filter_parse_state
*ps
,
587 struct ftrace_event_call
*call
,
588 struct filter_pred
*pred
,
591 struct ftrace_event_field
*field
;
593 unsigned long long val
;
596 pred
->fn
= filter_pred_none
;
598 if (pred
->op
== OP_AND
) {
600 fn
= filter_pred_and
;
602 } else if (pred
->op
== OP_OR
) {
608 field
= find_event_field(call
, pred
->field_name
);
610 parse_error(ps
, FILT_ERR_FIELD_NOT_FOUND
, 0);
614 pred
->offset
= field
->offset
;
616 if (!is_legal_op(field
, pred
->op
)) {
617 parse_error(ps
, FILT_ERR_ILLEGAL_FIELD_OP
, 0);
621 if (is_string_field(field
)) {
622 pred
->str_len
= field
->size
;
624 if (field
->filter_type
== FILTER_STATIC_STRING
)
625 fn
= filter_pred_string
;
626 else if (field
->filter_type
== FILTER_DYN_STRING
)
627 fn
= filter_pred_strloc
;
629 fn
= filter_pred_pchar
;
630 pred
->str_len
= strlen(pred
->str_val
);
633 if (field
->is_signed
)
634 ret
= strict_strtoll(pred
->str_val
, 0, &val
);
636 ret
= strict_strtoull(pred
->str_val
, 0, &val
);
638 parse_error(ps
, FILT_ERR_ILLEGAL_INTVAL
, 0);
643 fn
= select_comparison_fn(pred
->op
, field
->size
,
646 parse_error(ps
, FILT_ERR_INVALID_OP
, 0);
651 if (pred
->op
== OP_NE
)
656 return filter_add_pred_fn(ps
, call
, pred
, fn
);
660 static int filter_add_subsystem_pred(struct filter_parse_state
*ps
,
661 struct event_subsystem
*system
,
662 struct filter_pred
*pred
,
666 struct ftrace_event_call
*call
;
670 list_for_each_entry(call
, &ftrace_events
, list
) {
672 if (!call
->define_fields
)
675 if (strcmp(call
->system
, system
->name
))
678 if (call
->filter
->no_reset
)
681 err
= filter_add_pred(ps
, call
, pred
, dry_run
);
683 call
->filter
->no_reset
= true;
688 replace_filter_string(call
->filter
, filter_string
);
692 parse_error(ps
, FILT_ERR_BAD_SUBSYS_FILTER
, 0);
698 static void parse_init(struct filter_parse_state
*ps
,
699 struct filter_op
*ops
,
702 memset(ps
, '\0', sizeof(*ps
));
704 ps
->infix
.string
= infix_string
;
705 ps
->infix
.cnt
= strlen(infix_string
);
708 INIT_LIST_HEAD(&ps
->opstack
);
709 INIT_LIST_HEAD(&ps
->postfix
);
712 static char infix_next(struct filter_parse_state
*ps
)
716 return ps
->infix
.string
[ps
->infix
.tail
++];
719 static char infix_peek(struct filter_parse_state
*ps
)
721 if (ps
->infix
.tail
== strlen(ps
->infix
.string
))
724 return ps
->infix
.string
[ps
->infix
.tail
];
727 static void infix_advance(struct filter_parse_state
*ps
)
733 static inline int is_precedence_lower(struct filter_parse_state
*ps
,
736 return ps
->ops
[a
].precedence
< ps
->ops
[b
].precedence
;
739 static inline int is_op_char(struct filter_parse_state
*ps
, char c
)
743 for (i
= 0; strcmp(ps
->ops
[i
].string
, "OP_NONE"); i
++) {
744 if (ps
->ops
[i
].string
[0] == c
)
751 static int infix_get_op(struct filter_parse_state
*ps
, char firstc
)
753 char nextc
= infix_peek(ps
);
761 for (i
= 0; strcmp(ps
->ops
[i
].string
, "OP_NONE"); i
++) {
762 if (!strcmp(opstr
, ps
->ops
[i
].string
)) {
764 return ps
->ops
[i
].id
;
770 for (i
= 0; strcmp(ps
->ops
[i
].string
, "OP_NONE"); i
++) {
771 if (!strcmp(opstr
, ps
->ops
[i
].string
))
772 return ps
->ops
[i
].id
;
778 static inline void clear_operand_string(struct filter_parse_state
*ps
)
780 memset(ps
->operand
.string
, '\0', MAX_FILTER_STR_VAL
);
781 ps
->operand
.tail
= 0;
784 static inline int append_operand_char(struct filter_parse_state
*ps
, char c
)
786 if (ps
->operand
.tail
== MAX_FILTER_STR_VAL
- 1)
789 ps
->operand
.string
[ps
->operand
.tail
++] = c
;
794 static int filter_opstack_push(struct filter_parse_state
*ps
, int op
)
796 struct opstack_op
*opstack_op
;
798 opstack_op
= kmalloc(sizeof(*opstack_op
), GFP_KERNEL
);
803 list_add(&opstack_op
->list
, &ps
->opstack
);
808 static int filter_opstack_empty(struct filter_parse_state
*ps
)
810 return list_empty(&ps
->opstack
);
813 static int filter_opstack_top(struct filter_parse_state
*ps
)
815 struct opstack_op
*opstack_op
;
817 if (filter_opstack_empty(ps
))
820 opstack_op
= list_first_entry(&ps
->opstack
, struct opstack_op
, list
);
822 return opstack_op
->op
;
825 static int filter_opstack_pop(struct filter_parse_state
*ps
)
827 struct opstack_op
*opstack_op
;
830 if (filter_opstack_empty(ps
))
833 opstack_op
= list_first_entry(&ps
->opstack
, struct opstack_op
, list
);
835 list_del(&opstack_op
->list
);
842 static void filter_opstack_clear(struct filter_parse_state
*ps
)
844 while (!filter_opstack_empty(ps
))
845 filter_opstack_pop(ps
);
848 static char *curr_operand(struct filter_parse_state
*ps
)
850 return ps
->operand
.string
;
853 static int postfix_append_operand(struct filter_parse_state
*ps
, char *operand
)
855 struct postfix_elt
*elt
;
857 elt
= kmalloc(sizeof(*elt
), GFP_KERNEL
);
862 elt
->operand
= kstrdup(operand
, GFP_KERNEL
);
868 list_add_tail(&elt
->list
, &ps
->postfix
);
873 static int postfix_append_op(struct filter_parse_state
*ps
, int op
)
875 struct postfix_elt
*elt
;
877 elt
= kmalloc(sizeof(*elt
), GFP_KERNEL
);
884 list_add_tail(&elt
->list
, &ps
->postfix
);
889 static void postfix_clear(struct filter_parse_state
*ps
)
891 struct postfix_elt
*elt
;
893 while (!list_empty(&ps
->postfix
)) {
894 elt
= list_first_entry(&ps
->postfix
, struct postfix_elt
, list
);
896 list_del(&elt
->list
);
900 static int filter_parse(struct filter_parse_state
*ps
)
906 while ((ch
= infix_next(ps
))) {
918 if (is_op_char(ps
, ch
)) {
919 op
= infix_get_op(ps
, ch
);
921 parse_error(ps
, FILT_ERR_INVALID_OP
, 0);
925 if (strlen(curr_operand(ps
))) {
926 postfix_append_operand(ps
, curr_operand(ps
));
927 clear_operand_string(ps
);
930 while (!filter_opstack_empty(ps
)) {
931 top_op
= filter_opstack_top(ps
);
932 if (!is_precedence_lower(ps
, top_op
, op
)) {
933 top_op
= filter_opstack_pop(ps
);
934 postfix_append_op(ps
, top_op
);
940 filter_opstack_push(ps
, op
);
945 filter_opstack_push(ps
, OP_OPEN_PAREN
);
950 if (strlen(curr_operand(ps
))) {
951 postfix_append_operand(ps
, curr_operand(ps
));
952 clear_operand_string(ps
);
955 top_op
= filter_opstack_pop(ps
);
956 while (top_op
!= OP_NONE
) {
957 if (top_op
== OP_OPEN_PAREN
)
959 postfix_append_op(ps
, top_op
);
960 top_op
= filter_opstack_pop(ps
);
962 if (top_op
== OP_NONE
) {
963 parse_error(ps
, FILT_ERR_UNBALANCED_PAREN
, 0);
969 if (append_operand_char(ps
, ch
)) {
970 parse_error(ps
, FILT_ERR_OPERAND_TOO_LONG
, 0);
975 if (strlen(curr_operand(ps
)))
976 postfix_append_operand(ps
, curr_operand(ps
));
978 while (!filter_opstack_empty(ps
)) {
979 top_op
= filter_opstack_pop(ps
);
980 if (top_op
== OP_NONE
)
982 if (top_op
== OP_OPEN_PAREN
) {
983 parse_error(ps
, FILT_ERR_UNBALANCED_PAREN
, 0);
986 postfix_append_op(ps
, top_op
);
992 static struct filter_pred
*create_pred(int op
, char *operand1
, char *operand2
)
994 struct filter_pred
*pred
;
996 pred
= kzalloc(sizeof(*pred
), GFP_KERNEL
);
1000 pred
->field_name
= kstrdup(operand1
, GFP_KERNEL
);
1001 if (!pred
->field_name
) {
1006 strcpy(pred
->str_val
, operand2
);
1007 pred
->str_len
= strlen(operand2
);
1014 static struct filter_pred
*create_logical_pred(int op
)
1016 struct filter_pred
*pred
;
1018 pred
= kzalloc(sizeof(*pred
), GFP_KERNEL
);
1027 static int check_preds(struct filter_parse_state
*ps
)
1029 int n_normal_preds
= 0, n_logical_preds
= 0;
1030 struct postfix_elt
*elt
;
1032 list_for_each_entry(elt
, &ps
->postfix
, list
) {
1033 if (elt
->op
== OP_NONE
)
1036 if (elt
->op
== OP_AND
|| elt
->op
== OP_OR
) {
1043 if (!n_normal_preds
|| n_logical_preds
>= n_normal_preds
) {
1044 parse_error(ps
, FILT_ERR_INVALID_FILTER
, 0);
1051 static int replace_preds(struct event_subsystem
*system
,
1052 struct ftrace_event_call
*call
,
1053 struct filter_parse_state
*ps
,
1054 char *filter_string
,
1057 char *operand1
= NULL
, *operand2
= NULL
;
1058 struct filter_pred
*pred
;
1059 struct postfix_elt
*elt
;
1063 err
= check_preds(ps
);
1067 list_for_each_entry(elt
, &ps
->postfix
, list
) {
1068 if (elt
->op
== OP_NONE
) {
1070 operand1
= elt
->operand
;
1072 operand2
= elt
->operand
;
1074 parse_error(ps
, FILT_ERR_TOO_MANY_OPERANDS
, 0);
1080 if (n_preds
++ == MAX_FILTER_PRED
) {
1081 parse_error(ps
, FILT_ERR_TOO_MANY_PREDS
, 0);
1085 if (elt
->op
== OP_AND
|| elt
->op
== OP_OR
) {
1086 pred
= create_logical_pred(elt
->op
);
1090 if (!operand1
|| !operand2
) {
1091 parse_error(ps
, FILT_ERR_MISSING_FIELD
, 0);
1095 pred
= create_pred(elt
->op
, operand1
, operand2
);
1100 err
= filter_add_pred(ps
, call
, pred
, false);
1102 err
= filter_add_subsystem_pred(ps
, system
, pred
,
1103 filter_string
, dry_run
);
1104 filter_free_pred(pred
);
1108 operand1
= operand2
= NULL
;
1114 int apply_event_filter(struct ftrace_event_call
*call
, char *filter_string
)
1118 struct filter_parse_state
*ps
;
1120 mutex_lock(&event_mutex
);
1122 err
= init_preds(call
);
1126 if (!strcmp(strstrip(filter_string
), "0")) {
1127 filter_disable_preds(call
);
1128 remove_filter_string(call
->filter
);
1129 mutex_unlock(&event_mutex
);
1134 ps
= kzalloc(sizeof(*ps
), GFP_KERNEL
);
1138 filter_disable_preds(call
);
1139 replace_filter_string(call
->filter
, filter_string
);
1141 parse_init(ps
, filter_ops
, filter_string
);
1142 err
= filter_parse(ps
);
1144 append_filter_err(ps
, call
->filter
);
1148 err
= replace_preds(NULL
, call
, ps
, filter_string
, false);
1150 append_filter_err(ps
, call
->filter
);
1153 filter_opstack_clear(ps
);
1157 mutex_unlock(&event_mutex
);
1162 int apply_subsystem_event_filter(struct event_subsystem
*system
,
1163 char *filter_string
)
1167 struct filter_parse_state
*ps
;
1169 mutex_lock(&event_mutex
);
1171 err
= init_subsystem_preds(system
);
1175 if (!strcmp(strstrip(filter_string
), "0")) {
1176 filter_free_subsystem_preds(system
, FILTER_DISABLE_ALL
);
1177 remove_filter_string(system
->filter
);
1178 mutex_unlock(&event_mutex
);
1183 ps
= kzalloc(sizeof(*ps
), GFP_KERNEL
);
1187 replace_filter_string(system
->filter
, filter_string
);
1189 parse_init(ps
, filter_ops
, filter_string
);
1190 err
= filter_parse(ps
);
1192 append_filter_err(ps
, system
->filter
);
1196 filter_free_subsystem_preds(system
, FILTER_INIT_NO_RESET
);
1198 /* try to see the filter can be applied to which events */
1199 err
= replace_preds(system
, NULL
, ps
, filter_string
, true);
1201 append_filter_err(ps
, system
->filter
);
1205 filter_free_subsystem_preds(system
, FILTER_SKIP_NO_RESET
);
1207 /* really apply the filter to the events */
1208 err
= replace_preds(system
, NULL
, ps
, filter_string
, false);
1210 append_filter_err(ps
, system
->filter
);
1211 filter_free_subsystem_preds(system
, 2);
1215 filter_opstack_clear(ps
);
1219 mutex_unlock(&event_mutex
);