perf parse-events: Fix incorrect conversion of 'if () free()' to 'zfree()'
[linux-2.6-microblaze.git] / tools / perf / util / parse-events.c
index 1010774..e37a6a3 100644 (file)
@@ -354,7 +354,7 @@ __add_event(struct list_head *list, int *idx,
 
        event_attr_init(attr);
 
-       evsel = perf_evsel__new_idx(attr, *idx);
+       evsel = evsel__new_idx(attr, *idx);
        if (!evsel)
                return NULL;
 
@@ -399,13 +399,13 @@ static int add_event_tool(struct list_head *list, int *idx,
        return 0;
 }
 
-static int parse_aliases(char *str, const char *names[][PERF_EVSEL__MAX_ALIASES], int size)
+static int parse_aliases(char *str, const char *names[][EVSEL__MAX_ALIASES], int size)
 {
        int i, j;
        int n, longest = -1;
 
        for (i = 0; i < size; i++) {
-               for (j = 0; j < PERF_EVSEL__MAX_ALIASES && names[i][j]; j++) {
+               for (j = 0; j < EVSEL__MAX_ALIASES && names[i][j]; j++) {
                        n = strlen(names[i][j]);
                        if (n > longest && !strncasecmp(str, names[i][j], n))
                                longest = n;
@@ -444,8 +444,7 @@ int parse_events_add_cache(struct list_head *list, int *idx,
         * No fallback - if we cannot get a clear cache type
         * then bail out:
         */
-       cache_type = parse_aliases(type, perf_evsel__hw_cache,
-                                  PERF_COUNT_HW_CACHE_MAX);
+       cache_type = parse_aliases(type, evsel__hw_cache, PERF_COUNT_HW_CACHE_MAX);
        if (cache_type == -1)
                return -EINVAL;
 
@@ -458,17 +457,17 @@ int parse_events_add_cache(struct list_head *list, int *idx,
                n += snprintf(name + n, MAX_NAME_LEN - n, "-%s", str);
 
                if (cache_op == -1) {
-                       cache_op = parse_aliases(str, perf_evsel__hw_cache_op,
+                       cache_op = parse_aliases(str, evsel__hw_cache_op,
                                                 PERF_COUNT_HW_CACHE_OP_MAX);
                        if (cache_op >= 0) {
-                               if (!perf_evsel__is_cache_op_valid(cache_type, cache_op))
+                               if (!evsel__is_cache_op_valid(cache_type, cache_op))
                                        return -EINVAL;
                                continue;
                        }
                }
 
                if (cache_result == -1) {
-                       cache_result = parse_aliases(str, perf_evsel__hw_cache_result,
+                       cache_result = parse_aliases(str, evsel__hw_cache_result,
                                                     PERF_COUNT_HW_CACHE_RESULT_MAX);
                        if (cache_result >= 0)
                                continue;
@@ -538,9 +537,8 @@ static int add_tracepoint(struct list_head *list, int *idx,
                          struct parse_events_error *err,
                          struct list_head *head_config)
 {
-       struct evsel *evsel;
+       struct evsel *evsel = evsel__newtp_idx(sys_name, evt_name, (*idx)++);
 
-       evsel = perf_evsel__newtp_idx(sys_name, evt_name, (*idx)++);
        if (IS_ERR(evsel)) {
                tracepoint_error(err, PTR_ERR(evsel), sys_name, evt_name);
                return PTR_ERR(evsel);
@@ -1214,14 +1212,14 @@ static int get_config_terms(struct list_head *head_config,
                            struct list_head *head_terms __maybe_unused)
 {
 #define ADD_CONFIG_TERM(__type, __weak)                                \
-       struct perf_evsel_config_term *__t;                     \
+       struct evsel_config_term *__t;                  \
                                                                \
        __t = zalloc(sizeof(*__t));                             \
        if (!__t)                                               \
                return -ENOMEM;                                 \
                                                                \
        INIT_LIST_HEAD(&__t->list);                             \
-       __t->type       = PERF_EVSEL__CONFIG_TERM_ ## __type;   \
+       __t->type       = EVSEL__CONFIG_TERM_ ## __type;        \
        __t->weak       = __weak;                               \
        list_add_tail(&__t->list, head_terms)
 
@@ -1312,7 +1310,7 @@ do {                                                              \
 }
 
 /*
- * Add PERF_EVSEL__CONFIG_TERM_CFG_CHG where cfg_chg will have a bit set for
+ * Add EVSEL__CONFIG_TERM_CFG_CHG where cfg_chg will have a bit set for
  * each bit of attr->config that the user has changed.
  */
 static int get_config_chgs(struct perf_pmu *pmu, struct list_head *head_config,
@@ -1400,10 +1398,10 @@ int parse_events_add_tool(struct parse_events_state *parse_state,
 
 static bool config_term_percore(struct list_head *config_terms)
 {
-       struct perf_evsel_config_term *term;
+       struct evsel_config_term *term;
 
        list_for_each_entry(term, config_terms, list) {
-               if (term->type == PERF_EVSEL__CONFIG_TERM_PERCORE)
+               if (term->type == EVSEL__CONFIG_TERM_PERCORE)
                        return term->val.percore;
        }
 
@@ -1478,10 +1476,12 @@ int parse_events_add_pmu(struct parse_events_state *parse_state,
                return -ENOMEM;
 
        if (perf_pmu__config(pmu, &attr, head_config, parse_state->error)) {
-               struct perf_evsel_config_term *pos, *tmp;
+               struct evsel_config_term *pos, *tmp;
 
                list_for_each_entry_safe(pos, tmp, &config_terms, list) {
                        list_del_init(&pos->list);
+                       if (pos->free_str)
+                               zfree(&pos->val.str);
                        free(pos);
                }
                return -EINVAL;
@@ -1629,12 +1629,11 @@ parse_events__set_leader_for_uncore_aliase(char *name, struct list_head *list,
                 * event. That can be used to distinguish the leader from
                 * other members, even they have the same event name.
                 */
-               if ((leader != evsel) && (leader->pmu_name == evsel->pmu_name)) {
+               if ((leader != evsel) &&
+                   !strcmp(leader->pmu_name, evsel->pmu_name)) {
                        is_leader = false;
                        continue;
                }
-               /* The name is always alias name */
-               WARN_ON(strcmp(leader->name, evsel->name));
 
                /* Store the leader event for each PMU */
                leaders[nr_pmu++] = (uintptr_t) evsel;
@@ -1870,7 +1869,7 @@ int parse_events__modifier_event(struct list_head *list, char *str, bool add)
                evsel->precise_max         = mod.precise_max;
                evsel->weak_group          = mod.weak;
 
-               if (perf_evsel__is_group_leader(evsel))
+               if (evsel__is_group_leader(evsel))
                        evsel->core.attr.pinned = mod.pinned;
        }
 
@@ -2190,6 +2189,29 @@ int parse_events_option(const struct option *opt, const char *str,
        return ret;
 }
 
+int parse_events_option_new_evlist(const struct option *opt, const char *str, int unset)
+{
+       struct evlist **evlistp = opt->value;
+       int ret;
+
+       if (*evlistp == NULL) {
+               *evlistp = evlist__new();
+
+               if (*evlistp == NULL) {
+                       fprintf(stderr, "Not enough memory to create evlist\n");
+                       return -1;
+               }
+       }
+
+       ret = parse_events_option(opt, str, unset);
+       if (ret) {
+               evlist__delete(*evlistp);
+               *evlistp = NULL;
+       }
+
+       return ret;
+}
+
 static int
 foreach_evsel_in_last_glob(struct evlist *evlist,
                           int (*func)(struct evsel *evsel,
@@ -2237,7 +2259,7 @@ static int set_filter(struct evsel *evsel, const void *arg)
        }
 
        if (evsel->core.attr.type == PERF_TYPE_TRACEPOINT) {
-               if (perf_evsel__append_tp_filter(evsel, str) < 0) {
+               if (evsel__append_tp_filter(evsel, str) < 0) {
                        fprintf(stderr,
                                "not enough memory to hold filter string\n");
                        return -1;
@@ -2262,7 +2284,7 @@ static int set_filter(struct evsel *evsel, const void *arg)
                return -1;
        }
 
-       if (perf_evsel__append_addr_filter(evsel, str) < 0) {
+       if (evsel__append_addr_filter(evsel, str) < 0) {
                fprintf(stderr,
                        "not enough memory to hold filter string\n");
                return -1;
@@ -2293,7 +2315,7 @@ static int add_exclude_perf_filter(struct evsel *evsel,
 
        snprintf(new_filter, sizeof(new_filter), "common_pid != %d", getpid());
 
-       if (perf_evsel__append_tp_filter(evsel, new_filter) < 0) {
+       if (evsel__append_tp_filter(evsel, new_filter) < 0) {
                fprintf(stderr,
                        "not enough memory to hold filter string\n");
                return -1;
@@ -2603,12 +2625,11 @@ restart:
        for (type = 0; type < PERF_COUNT_HW_CACHE_MAX; type++) {
                for (op = 0; op < PERF_COUNT_HW_CACHE_OP_MAX; op++) {
                        /* skip invalid cache type */
-                       if (!perf_evsel__is_cache_op_valid(type, op))
+                       if (!evsel__is_cache_op_valid(type, op))
                                continue;
 
                        for (i = 0; i < PERF_COUNT_HW_CACHE_RESULT_MAX; i++) {
-                               __perf_evsel__hw_cache_type_op_res_name(type, op, i,
-                                                                       name, sizeof(name));
+                               __evsel__hw_cache_type_op_res_name(type, op, i, name, sizeof(name));
                                if (event_glob != NULL && !strglobmatch(name, event_glob))
                                        continue;