Blackfin: BF518F-EZBRD: handle required portmuxing of async pins
[safe/jmp/linux-2.6] / kernel / trace / trace_events_filter.c
index f494866..db6e54b 100644 (file)
@@ -151,6 +151,7 @@ static int filter_pred_or(struct filter_pred *pred __attribute((unused)),
        return val1 || val2;
 }
 
+/* Filter predicate for fixed sized arrays of characters */
 static int filter_pred_string(struct filter_pred *pred, void *event,
                              int val1, int val2)
 {
@@ -164,6 +165,30 @@ static int filter_pred_string(struct filter_pred *pred, void *event,
        return match;
 }
 
+/*
+ * Filter predicate for dynamic sized arrays of characters.
+ * These are implemented through a list of strings at the end
+ * of the entry.
+ * Also each of these strings have a field in the entry which
+ * contains its offset from the beginning of the entry.
+ * We have then first to get this field, dereference it
+ * and add it to the address of the entry, and at last we have
+ * the address of the string.
+ */
+static int filter_pred_strloc(struct filter_pred *pred, void *event,
+                             int val1, int val2)
+{
+       int str_loc = *(int *)(event + pred->offset);
+       char *addr = (char *)(event + str_loc);
+       int cmp, match;
+
+       cmp = strncmp(addr, pred->str_val, pred->str_len);
+
+       match = (!cmp) ^ pred->not;
+
+       return match;
+}
+
 static int filter_pred_none(struct filter_pred *pred, void *event,
                            int val1, int val2)
 {
@@ -346,6 +371,20 @@ static void filter_disable_preds(struct ftrace_event_call *call)
                filter->preds[i]->fn = filter_pred_none;
 }
 
+void destroy_preds(struct ftrace_event_call *call)
+{
+       struct event_filter *filter = call->filter;
+       int i;
+
+       for (i = 0; i < MAX_FILTER_PRED; i++) {
+               if (filter->preds[i])
+                       filter_free_pred(filter->preds[i]);
+       }
+       kfree(filter->preds);
+       kfree(filter);
+       call->filter = NULL;
+}
+
 int init_preds(struct ftrace_event_call *call)
 {
        struct event_filter *filter;
@@ -374,13 +413,7 @@ int init_preds(struct ftrace_event_call *call)
        return 0;
 
 oom:
-       for (i = 0; i < MAX_FILTER_PRED; i++) {
-               if (filter->preds[i])
-                       filter_free_pred(filter->preds[i]);
-       }
-       kfree(filter->preds);
-       kfree(call->filter);
-       call->filter = NULL;
+       destroy_preds(call);
 
        return -ENOMEM;
 }
@@ -400,6 +433,7 @@ static void filter_free_subsystem_preds(struct event_subsystem *system)
                filter->n_preds = 0;
        }
 
+       mutex_lock(&event_mutex);
        list_for_each_entry(call, &ftrace_events, list) {
                if (!call->define_fields)
                        continue;
@@ -409,6 +443,7 @@ static void filter_free_subsystem_preds(struct event_subsystem *system)
                        remove_filter_string(call->filter);
                }
        }
+       mutex_unlock(&event_mutex);
 }
 
 static int filter_add_pred_fn(struct filter_parse_state *ps,
@@ -436,10 +471,18 @@ static int filter_add_pred_fn(struct filter_parse_state *ps,
        return 0;
 }
 
+enum {
+       FILTER_STATIC_STRING = 1,
+       FILTER_DYN_STRING
+};
+
 static int is_string_field(const char *type)
 {
+       if (strstr(type, "__data_loc") && strstr(type, "char"))
+               return FILTER_DYN_STRING;
+
        if (strchr(type, '[') && strstr(type, "char"))
-               return 1;
+               return FILTER_STATIC_STRING;
 
        return 0;
 }
@@ -502,6 +545,7 @@ static int filter_add_pred(struct filter_parse_state *ps,
        struct ftrace_event_field *field;
        filter_pred_fn_t fn;
        unsigned long long val;
+       int string_type;
 
        pred->fn = filter_pred_none;
 
@@ -526,8 +570,12 @@ static int filter_add_pred(struct filter_parse_state *ps,
                return -EINVAL;
        }
 
-       if (is_string_field(field->type)) {
-               fn = filter_pred_string;
+       string_type = is_string_field(field->type);
+       if (string_type) {
+               if (string_type == FILTER_STATIC_STRING)
+                       fn = filter_pred_string;
+               else
+                       fn = filter_pred_strloc;
                pred->str_len = field->size;
                if (pred->op == OP_NE)
                        pred->not = 1;
@@ -559,6 +607,7 @@ static int filter_add_subsystem_pred(struct filter_parse_state *ps,
 {
        struct event_filter *filter = system->filter;
        struct ftrace_event_call *call;
+       int err = 0;
 
        if (!filter->preds) {
                filter->preds = kzalloc(MAX_FILTER_PRED * sizeof(pred),
@@ -576,8 +625,8 @@ static int filter_add_subsystem_pred(struct filter_parse_state *ps,
        filter->preds[filter->n_preds] = pred;
        filter->n_preds++;
 
+       mutex_lock(&event_mutex);
        list_for_each_entry(call, &ftrace_events, list) {
-               int err;
 
                if (!call->define_fields)
                        continue;
@@ -587,14 +636,16 @@ static int filter_add_subsystem_pred(struct filter_parse_state *ps,
 
                err = filter_add_pred(ps, call, pred);
                if (err) {
+                       mutex_unlock(&event_mutex);
                        filter_free_subsystem_preds(system);
                        parse_error(ps, FILT_ERR_BAD_SUBSYS_FILTER, 0);
-                       return err;
+                       goto out;
                }
                replace_filter_string(call->filter, filter_string);
        }
-
-       return 0;
+       mutex_unlock(&event_mutex);
+out:
+       return err;
 }
 
 static void parse_init(struct filter_parse_state *ps,
@@ -685,7 +736,7 @@ static inline void clear_operand_string(struct filter_parse_state *ps)
 
 static inline int append_operand_char(struct filter_parse_state *ps, char c)
 {
-       if (ps->operand.tail == MAX_FILTER_STR_VAL)
+       if (ps->operand.tail == MAX_FILTER_STR_VAL - 1)
                return -EINVAL;
 
        ps->operand.string[ps->operand.tail++] = c;
@@ -801,10 +852,19 @@ static void postfix_clear(struct filter_parse_state *ps)
 
 static int filter_parse(struct filter_parse_state *ps)
 {
+       int in_string = 0;
        int op, top_op;
        char ch;
 
        while ((ch = infix_next(ps))) {
+               if (ch == '"') {
+                       in_string ^= 1;
+                       continue;
+               }
+
+               if (in_string)
+                       goto parse_operand;
+
                if (isspace(ch))
                        continue;
 
@@ -858,6 +918,7 @@ static int filter_parse(struct filter_parse_state *ps)
                        }
                        continue;
                }
+parse_operand:
                if (append_operand_char(ps, ch)) {
                        parse_error(ps, FILT_ERR_OPERAND_TOO_LONG, 0);
                        return -EINVAL;
@@ -1018,9 +1079,10 @@ int apply_event_filter(struct ftrace_event_call *call, char *filter_string)
                return 0;
        }
 
+       err = -ENOMEM;
        ps = kzalloc(sizeof(*ps), GFP_KERNEL);
        if (!ps)
-               return -ENOMEM;
+               goto out_unlock;
 
        filter_disable_preds(call);
        replace_filter_string(call->filter, filter_string);
@@ -1040,7 +1102,7 @@ out:
        filter_opstack_clear(ps);
        postfix_clear(ps);
        kfree(ps);
-
+out_unlock:
        mutex_unlock(&filter_mutex);
 
        return err;
@@ -1062,9 +1124,10 @@ int apply_subsystem_event_filter(struct event_subsystem *system,
                return 0;
        }
 
+       err = -ENOMEM;
        ps = kzalloc(sizeof(*ps), GFP_KERNEL);
        if (!ps)
-               return -ENOMEM;
+               goto out_unlock;
 
        filter_free_subsystem_preds(system);
        replace_filter_string(system->filter, filter_string);
@@ -1084,7 +1147,7 @@ out:
        filter_opstack_clear(ps);
        postfix_clear(ps);
        kfree(ps);
-
+out_unlock:
        mutex_unlock(&filter_mutex);
 
        return err;