.. | .. |
---|
223 | 223 | path = zalloc(sizeof(*path)); |
---|
224 | 224 | if (!path) |
---|
225 | 225 | return NULL; |
---|
226 | | - path->system = malloc(MAX_EVENT_LENGTH); |
---|
227 | | - if (!path->system) { |
---|
| 226 | + if (asprintf(&path->system, "%.*s", MAX_EVENT_LENGTH, sys_dirent->d_name) < 0) { |
---|
228 | 227 | free(path); |
---|
229 | 228 | return NULL; |
---|
230 | 229 | } |
---|
231 | | - path->name = malloc(MAX_EVENT_LENGTH); |
---|
232 | | - if (!path->name) { |
---|
| 230 | + if (asprintf(&path->name, "%.*s", MAX_EVENT_LENGTH, evt_dirent->d_name) < 0) { |
---|
233 | 231 | zfree(&path->system); |
---|
234 | 232 | free(path); |
---|
235 | 233 | return NULL; |
---|
236 | 234 | } |
---|
237 | | - strncpy(path->system, sys_dirent->d_name, |
---|
238 | | - MAX_EVENT_LENGTH); |
---|
239 | | - strncpy(path->name, evt_dirent->d_name, |
---|
240 | | - MAX_EVENT_LENGTH); |
---|
241 | 235 | return path; |
---|
242 | 236 | } |
---|
243 | 237 | } |
---|
.. | .. |
---|
1312 | 1306 | int parse_events_multi_pmu_add(struct parse_events_state *parse_state, |
---|
1313 | 1307 | char *str, struct list_head **listp) |
---|
1314 | 1308 | { |
---|
1315 | | - struct list_head *head; |
---|
1316 | 1309 | struct parse_events_term *term; |
---|
1317 | 1310 | struct list_head *list; |
---|
1318 | 1311 | struct perf_pmu *pmu = NULL; |
---|
.. | .. |
---|
1329 | 1322 | |
---|
1330 | 1323 | list_for_each_entry(alias, &pmu->aliases, list) { |
---|
1331 | 1324 | if (!strcasecmp(alias->name, str)) { |
---|
| 1325 | + struct list_head *head; |
---|
| 1326 | + char *config; |
---|
| 1327 | + |
---|
1332 | 1328 | head = malloc(sizeof(struct list_head)); |
---|
1333 | 1329 | if (!head) |
---|
1334 | 1330 | return -1; |
---|
1335 | 1331 | INIT_LIST_HEAD(head); |
---|
1336 | | - if (parse_events_term__num(&term, PARSE_EVENTS__TERM_TYPE_USER, |
---|
1337 | | - str, 1, false, &str, NULL) < 0) |
---|
| 1332 | + config = strdup(str); |
---|
| 1333 | + if (!config) |
---|
1338 | 1334 | return -1; |
---|
| 1335 | + if (parse_events_term__num(&term, |
---|
| 1336 | + PARSE_EVENTS__TERM_TYPE_USER, |
---|
| 1337 | + config, 1, false, &config, |
---|
| 1338 | + NULL) < 0) { |
---|
| 1339 | + free(list); |
---|
| 1340 | + free(config); |
---|
| 1341 | + return -1; |
---|
| 1342 | + } |
---|
1339 | 1343 | list_add_tail(&term->list, head); |
---|
1340 | 1344 | |
---|
1341 | 1345 | if (!parse_events_add_pmu(parse_state, list, |
---|
1342 | 1346 | pmu->name, head, |
---|
1343 | 1347 | true, true)) { |
---|
1344 | | - pr_debug("%s -> %s/%s/\n", str, |
---|
| 1348 | + pr_debug("%s -> %s/%s/\n", config, |
---|
1345 | 1349 | pmu->name, alias->str); |
---|
1346 | 1350 | ok++; |
---|
1347 | 1351 | } |
---|
.. | .. |
---|
1350 | 1354 | } |
---|
1351 | 1355 | } |
---|
1352 | 1356 | } |
---|
1353 | | - if (!ok) |
---|
| 1357 | + if (!ok) { |
---|
| 1358 | + free(list); |
---|
1354 | 1359 | return -1; |
---|
| 1360 | + } |
---|
1355 | 1361 | *listp = list; |
---|
1356 | 1362 | return 0; |
---|
1357 | 1363 | } |
---|
.. | .. |
---|
2625 | 2631 | char *config, unsigned idx) |
---|
2626 | 2632 | { |
---|
2627 | 2633 | struct event_symbol *sym; |
---|
| 2634 | + char *str; |
---|
2628 | 2635 | struct parse_events_term temp = { |
---|
2629 | 2636 | .type_val = PARSE_EVENTS__TERM_TYPE_STR, |
---|
2630 | 2637 | .type_term = PARSE_EVENTS__TERM_TYPE_USER, |
---|
2631 | | - .config = config ?: (char *) "event", |
---|
| 2638 | + .config = config, |
---|
2632 | 2639 | }; |
---|
2633 | 2640 | |
---|
| 2641 | + if (!temp.config) { |
---|
| 2642 | + temp.config = strdup("event"); |
---|
| 2643 | + if (!temp.config) |
---|
| 2644 | + return -ENOMEM; |
---|
| 2645 | + } |
---|
2634 | 2646 | BUG_ON(idx >= PERF_COUNT_HW_MAX); |
---|
2635 | 2647 | sym = &event_symbols_hw[idx]; |
---|
2636 | 2648 | |
---|
2637 | | - return new_term(term, &temp, (char *) sym->symbol, 0); |
---|
| 2649 | + str = strdup(sym->symbol); |
---|
| 2650 | + if (!str) |
---|
| 2651 | + return -ENOMEM; |
---|
| 2652 | + return new_term(term, &temp, str, 0); |
---|
2638 | 2653 | } |
---|
2639 | 2654 | |
---|
2640 | 2655 | int parse_events_term__clone(struct parse_events_term **new, |
---|
2641 | 2656 | struct parse_events_term *term) |
---|
2642 | 2657 | { |
---|
| 2658 | + char *str; |
---|
2643 | 2659 | struct parse_events_term temp = { |
---|
2644 | 2660 | .type_val = term->type_val, |
---|
2645 | 2661 | .type_term = term->type_term, |
---|
2646 | | - .config = term->config, |
---|
| 2662 | + .config = NULL, |
---|
2647 | 2663 | .err_term = term->err_term, |
---|
2648 | 2664 | .err_val = term->err_val, |
---|
2649 | 2665 | }; |
---|
2650 | 2666 | |
---|
2651 | | - return new_term(new, &temp, term->val.str, term->val.num); |
---|
| 2667 | + if (term->config) { |
---|
| 2668 | + temp.config = strdup(term->config); |
---|
| 2669 | + if (!temp.config) |
---|
| 2670 | + return -ENOMEM; |
---|
| 2671 | + } |
---|
| 2672 | + if (term->type_val == PARSE_EVENTS__TERM_TYPE_NUM) |
---|
| 2673 | + return new_term(new, &temp, NULL, term->val.num); |
---|
| 2674 | + |
---|
| 2675 | + str = strdup(term->val.str); |
---|
| 2676 | + if (!str) |
---|
| 2677 | + return -ENOMEM; |
---|
| 2678 | + return new_term(new, &temp, str, 0); |
---|
2652 | 2679 | } |
---|
2653 | 2680 | |
---|
2654 | 2681 | int parse_events_copy_term_list(struct list_head *old, |
---|