Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf_counter tools: Add more warnings and fix/annotate them

Enable -Wextra. This found a few real bugs plus a number
of signed/unsigned type mismatches/uncleanlinesses. It
also required a few annotations

All things considered it was still worth it so lets try with
this enabled for now.

Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
LKML-Reference: <new-submission>
Signed-off-by: Ingo Molnar <mingo@elte.hu>

+152 -129
+1 -1
tools/perf/Makefile
··· 164 164 165 165 # CFLAGS and LDFLAGS are for the users to override from the command line. 166 166 167 - CFLAGS = $(M64) -ggdb3 -Wall -Wstrict-prototypes -Wmissing-declarations -Wmissing-prototypes -std=gnu99 -Wdeclaration-after-statement -Werror -O6 167 + CFLAGS = $(M64) -ggdb3 -Wall -Wextra -Wstrict-prototypes -Wmissing-declarations -Wmissing-prototypes -std=gnu99 -Wdeclaration-after-statement -Werror -O6 168 168 LDFLAGS = -lpthread -lrt -lelf -lm 169 169 ALL_CFLAGS = $(CFLAGS) 170 170 ALL_LDFLAGS = $(LDFLAGS)
+6 -6
tools/perf/builtin-annotate.c
··· 160 160 161 161 static struct symbol *vdso__find_symbol(struct dso *dso, u64 ip) 162 162 { 163 - return dso__find_symbol(kernel_dso, ip); 163 + return dso__find_symbol(dso, ip); 164 164 } 165 165 166 166 static int load_kernel(void) ··· 203 203 return ip - map->start + map->pgoff; 204 204 } 205 205 206 - static u64 vdso__map_ip(struct map *map, u64 ip) 206 + static u64 vdso__map_ip(struct map *map __used, u64 ip) 207 207 { 208 208 return ip; 209 209 } ··· 600 600 601 601 static int sort_dimension__add(char *tok) 602 602 { 603 - int i; 603 + unsigned int i; 604 604 605 605 for (i = 0; i < ARRAY_SIZE(sort_dimensions); i++) { 606 606 struct sort_dimension *sd = &sort_dimensions[i]; ··· 1069 1069 static const char *prev_color; 1070 1070 unsigned int offset; 1071 1071 size_t line_len; 1072 - u64 line_ip; 1072 + s64 line_ip; 1073 1073 int ret; 1074 1074 char *c; 1075 1075 ··· 1428 1428 1429 1429 head += size; 1430 1430 1431 - if (offset + head < stat.st_size) 1431 + if (offset + head < (unsigned long)stat.st_size) 1432 1432 goto more; 1433 1433 1434 1434 rc = EXIT_SUCCESS; ··· 1492 1492 free(str); 1493 1493 } 1494 1494 1495 - int cmd_annotate(int argc, const char **argv, const char *prefix) 1495 + int cmd_annotate(int argc, const char **argv, const char *prefix __used) 1496 1496 { 1497 1497 symbol__init(); 1498 1498
+4 -2
tools/perf/builtin-help.c
··· 3 3 * 4 4 * Builtin help command 5 5 */ 6 + #include "perf.h" 6 7 #include "util/cache.h" 7 8 #include "builtin.h" 8 9 #include "util/exec_cmd.h" ··· 278 277 279 278 void list_common_cmds_help(void) 280 279 { 281 - int i, longest = 0; 280 + unsigned int i, longest = 0; 282 281 283 282 for (i = 0; i < ARRAY_SIZE(common_cmds); i++) { 284 283 if (longest < strlen(common_cmds[i].name)) ··· 416 415 open_html(page_path.buf); 417 416 } 418 417 419 - int cmd_help(int argc, const char **argv, const char *prefix) 418 + int cmd_help(int argc, const char **argv, const char *prefix __used) 420 419 { 421 420 const char *alias; 421 + 422 422 load_command_list("perf-", &main_cmds, &other_cmds); 423 423 424 424 perf_config(perf_help_config, NULL);
+1 -1
tools/perf/builtin-list.c
··· 13 13 #include "util/parse-options.h" 14 14 #include "util/parse-events.h" 15 15 16 - int cmd_list(int argc, const char **argv, const char *prefix) 16 + int cmd_list(int argc __used, const char **argv __used, const char *prefix __used) 17 17 { 18 18 print_events(); 19 19 return 0;
+2 -2
tools/perf/builtin-record.c
··· 294 294 while (1) { 295 295 char bf[BUFSIZ], *pbf = bf; 296 296 struct mmap_event mmap_ev = { 297 - .header.type = PERF_EVENT_MMAP, 297 + .header = { .type = PERF_EVENT_MMAP }, 298 298 }; 299 299 int n; 300 300 size_t size; ··· 650 650 OPT_END() 651 651 }; 652 652 653 - int cmd_record(int argc, const char **argv, const char *prefix) 653 + int cmd_record(int argc, const char **argv, const char *prefix __used) 654 654 { 655 655 int counter; 656 656
+11 -11
tools/perf/builtin-report.c
··· 177 177 178 178 static struct symbol *vdso__find_symbol(struct dso *dso, u64 ip) 179 179 { 180 - return dso__find_symbol(kernel_dso, ip); 180 + return dso__find_symbol(dso, ip); 181 181 } 182 182 183 183 static int load_kernel(void) ··· 239 239 return ip - map->start + map->pgoff; 240 240 } 241 241 242 - static u64 vdso__map_ip(struct map *map, u64 ip) 242 + static u64 vdso__map_ip(struct map *map __used, u64 ip) 243 243 { 244 244 return ip; 245 245 } ··· 712 712 713 713 static int sort_dimension__add(char *tok) 714 714 { 715 - int i; 715 + unsigned int i; 716 716 717 717 for (i = 0; i < ARRAY_SIZE(sort_dimensions); i++) { 718 718 struct sort_dimension *sd = &sort_dimensions[i]; ··· 801 801 ret += fprintf(fp, " %s\n", chain->sym->name); 802 802 else 803 803 ret += fprintf(fp, " %p\n", 804 - (void *)chain->ip); 804 + (void *)(long)chain->ip); 805 805 } 806 806 807 807 return ret; ··· 938 938 } 939 939 940 940 static struct symbol ** 941 - resolve_callchain(struct thread *thread, struct map *map, 941 + resolve_callchain(struct thread *thread, struct map *map __used, 942 942 struct ip_callchain *chain, struct hist_entry *entry) 943 943 { 944 - int i; 945 - struct symbol **syms; 946 944 u64 context = PERF_CONTEXT_MAX; 945 + struct symbol **syms; 946 + unsigned int i; 947 947 948 948 if (callchain) { 949 949 syms = calloc(chain->nr, sizeof(*syms)); ··· 1183 1183 1184 1184 fprintf(fp, "# ........"); 1185 1185 list_for_each_entry(se, &hist_entry__sort_list, list) { 1186 - int i; 1186 + unsigned int i; 1187 1187 1188 1188 if (exclude_other && (se == &sort_parent)) 1189 1189 continue; ··· 1271 1271 (long long)period); 1272 1272 1273 1273 if (sample_type & PERF_SAMPLE_CALLCHAIN) { 1274 - int i; 1274 + unsigned int i; 1275 1275 1276 1276 chain = (void *)more_data; 1277 1277 ··· 1667 1667 if (offset + head >= header->data_offset + header->data_size) 1668 1668 goto done; 1669 1669 1670 - if (offset + head < stat.st_size) 1670 + if (offset + head < (unsigned long)stat.st_size) 1671 1671 goto more; 1672 1672 1673 1673 done: ··· 1756 1756 } 1757 1757 } 1758 1758 1759 - int cmd_report(int argc, const char **argv, const char *prefix) 1759 + int cmd_report(int argc, const char **argv, const char *prefix __used) 1760 1760 { 1761 1761 symbol__init(); 1762 1762
+10 -8
tools/perf/builtin-stat.c
··· 64 64 65 65 static int system_wide = 0; 66 66 static int verbose = 0; 67 - static int nr_cpus = 0; 67 + static unsigned int nr_cpus = 0; 68 68 static int run_idx = 0; 69 69 70 70 static int run_count = 1; ··· 108 108 PERF_FORMAT_TOTAL_TIME_RUNNING; 109 109 110 110 if (system_wide) { 111 - int cpu; 111 + unsigned int cpu; 112 + 112 113 for (cpu = 0; cpu < nr_cpus; cpu++) { 113 114 fd[cpu][counter] = sys_perf_counter_open(attr, -1, cpu, -1, 0); 114 115 if (fd[cpu][counter] < 0 && verbose) ··· 151 150 static void read_counter(int counter) 152 151 { 153 152 u64 *count, single_count[3]; 154 - ssize_t res; 155 - int cpu, nv; 153 + unsigned int cpu; 154 + size_t res, nv; 156 155 int scaled; 157 156 158 157 count = event_res[run_idx][counter]; ··· 166 165 167 166 res = read(fd[cpu][counter], single_count, nv * sizeof(u64)); 168 167 assert(res == nv * sizeof(u64)); 168 + 169 169 close(fd[cpu][counter]); 170 170 fd[cpu][counter] = -1; 171 171 ··· 202 200 runtime_cycles[run_idx] = count[0]; 203 201 } 204 202 205 - static int run_perf_stat(int argc, const char **argv) 203 + static int run_perf_stat(int argc __used, const char **argv) 206 204 { 207 205 unsigned long long t0, t1; 208 206 int status = 0; ··· 392 390 event_res_avg[j]+1, event_res[i][j]+1); 393 391 update_avg("counter/2", j, 394 392 event_res_avg[j]+2, event_res[i][j]+2); 395 - if (event_scaled[i][j] != -1) 393 + if (event_scaled[i][j] != (u64)-1) 396 394 update_avg("scaled", j, 397 395 event_scaled_avg + j, event_scaled[i]+j); 398 396 else ··· 512 510 OPT_END() 513 511 }; 514 512 515 - int cmd_stat(int argc, const char **argv, const char *prefix) 513 + int cmd_stat(int argc, const char **argv, const char *prefix __used) 516 514 { 517 515 int status; 518 516 ··· 530 528 531 529 nr_cpus = sysconf(_SC_NPROCESSORS_ONLN); 532 530 assert(nr_cpus <= MAX_NR_CPUS); 533 - assert(nr_cpus >= 0); 531 + assert((int)nr_cpus >= 0); 534 532 535 533 /* 536 534 * We dont want to block the signals - that would cause
+4 -4
tools/perf/builtin-top.c
··· 269 269 } 270 270 } 271 271 272 - static void *display_thread(void *arg) 272 + static void *display_thread(void *arg __used) 273 273 { 274 274 struct pollfd stdin_poll = { .fd = 0, .events = POLLIN }; 275 275 int delay_msecs = delay_secs * 1000; ··· 287 287 } 288 288 289 289 /* Tag samples to be skipped. */ 290 - char *skip_symbols[] = { 290 + static const char *skip_symbols[] = { 291 291 "default_idle", 292 292 "cpu_idle", 293 293 "enter_idle", ··· 426 426 struct mmap_data { 427 427 int counter; 428 428 void *base; 429 - unsigned int mask; 429 + int mask; 430 430 unsigned int prev; 431 431 }; 432 432 ··· 705 705 OPT_END() 706 706 }; 707 707 708 - int cmd_top(int argc, const char **argv, const char *prefix) 708 + int cmd_top(int argc, const char **argv, const char *prefix __used) 709 709 { 710 710 int counter; 711 711
+1 -4
tools/perf/perf.c
··· 229 229 use_pager = 1; 230 230 commit_pager_choice(); 231 231 232 - if (p->option & NEED_WORK_TREE) 233 - /* setup_work_tree() */; 234 - 235 232 status = p->fn(argc, argv, prefix); 236 233 if (status) 237 234 return status & 0xff; ··· 263 266 { "annotate", cmd_annotate, 0 }, 264 267 { "version", cmd_version, 0 }, 265 268 }; 266 - int i; 269 + unsigned int i; 267 270 static const char ext[] = STRIP_EXTENSION; 268 271 269 272 if (sizeof(ext) > 1) {
+2
tools/perf/perf.h
··· 52 52 #define __user 53 53 #define asmlinkage 54 54 55 + #define __used __attribute__((__unused__)) 56 + 55 57 #define unlikely(x) __builtin_expect(!!(x), 0) 56 58 #define min(x, y) ({ \ 57 59 typeof(x) _min1 = (x); \
+1 -1
tools/perf/util/alias.c
··· 3 3 static const char *alias_key; 4 4 static char *alias_val; 5 5 6 - static int alias_lookup_cb(const char *k, const char *v, void *cb) 6 + static int alias_lookup_cb(const char *k, const char *v, void *cb __used) 7 7 { 8 8 if (!prefixcmp(k, "alias.") && !strcmp(k+6, alias_key)) { 9 9 if (!v)
+1
tools/perf/util/cache.h
··· 3 3 4 4 #include "util.h" 5 5 #include "strbuf.h" 6 + #include "../perf.h" 6 7 7 8 #define PERF_DIR_ENVIRONMENT "PERF_DIR" 8 9 #define PERF_WORK_TREE_ENVIRONMENT "PERF_WORK_TREE"
+8 -7
tools/perf/util/callchain.c
··· 92 92 fill_node(struct callchain_node *node, struct ip_callchain *chain, 93 93 int start, struct symbol **syms) 94 94 { 95 - int i; 95 + unsigned int i; 96 96 97 97 for (i = start; i < chain->nr; i++) { 98 98 struct callchain_list *call; ··· 135 135 { 136 136 struct callchain_node *new; 137 137 struct list_head *old_tail; 138 - int idx_total = idx_parents + idx_local; 138 + unsigned int idx_total = idx_parents + idx_local; 139 139 140 140 /* split */ 141 141 new = create_child(parent, true); ··· 164 164 165 165 static int 166 166 __append_chain(struct callchain_node *root, struct ip_callchain *chain, 167 - int start, struct symbol **syms); 167 + unsigned int start, struct symbol **syms); 168 168 169 169 static void 170 170 __append_chain_children(struct callchain_node *root, struct ip_callchain *chain, 171 - struct symbol **syms, int start) 171 + struct symbol **syms, unsigned int start) 172 172 { 173 173 struct callchain_node *rnode; 174 174 175 175 /* lookup in childrens */ 176 176 list_for_each_entry(rnode, &root->children, brothers) { 177 - int ret = __append_chain(rnode, chain, start, syms); 177 + unsigned int ret = __append_chain(rnode, chain, start, syms); 178 + 178 179 if (!ret) 179 180 return; 180 181 } ··· 185 184 186 185 static int 187 186 __append_chain(struct callchain_node *root, struct ip_callchain *chain, 188 - int start, struct symbol **syms) 187 + unsigned int start, struct symbol **syms) 189 188 { 190 189 struct callchain_list *cnode; 191 - int i = start; 190 + unsigned int i = start; 192 191 bool found = false; 193 192 194 193 /*
+5 -5
tools/perf/util/callchain.h
··· 10 10 struct callchain_node { 11 11 struct callchain_node *parent; 12 12 struct list_head brothers; 13 - struct list_head children; 14 - struct list_head val; 13 + struct list_head children; 14 + struct list_head val; 15 15 struct rb_node rb_node; 16 - int val_nr; 17 - int hit; 16 + unsigned int val_nr; 17 + u64 hit; 18 18 }; 19 19 20 20 struct callchain_list { 21 - unsigned long ip; 21 + u64 ip; 22 22 struct symbol *sym; 23 23 struct list_head list; 24 24 };
+7 -3
tools/perf/util/color.c
··· 11 11 }; 12 12 char *end; 13 13 int i; 14 - for (i = 0; i < ARRAY_SIZE(color_names); i++) { 14 + 15 + for (i = 0; i < (int)ARRAY_SIZE(color_names); i++) { 15 16 const char *str = color_names[i]; 16 17 if (!strncasecmp(name, str, len) && !str[len]) 17 18 return i - 1; ··· 29 28 static const char * const attr_names[] = { 30 29 "bold", "dim", "ul", "blink", "reverse" 31 30 }; 32 - int i; 31 + unsigned int i; 32 + 33 33 for (i = 0; i < ARRAY_SIZE(attr_names); i++) { 34 34 const char *str = attr_names[i]; 35 35 if (!strncasecmp(name, str, len) && !str[len]) ··· 224 222 { 225 223 if (!*color) 226 224 return fwrite(buf, count, 1, fp) != 1; 225 + 227 226 while (count) { 228 227 char *p = memchr(buf, '\n', count); 228 + 229 229 if (p != buf && (fputs(color, fp) < 0 || 230 - fwrite(buf, p ? p - buf : count, 1, fp) != 1 || 230 + fwrite(buf, p ? (size_t)(p - buf) : count, 1, fp) != 1 || 231 231 fputs(PERF_COLOR_RESET, fp) < 0)) 232 232 return -1; 233 233 if (!p)
+10 -8
tools/perf/util/config.c
··· 47 47 static char *parse_value(void) 48 48 { 49 49 static char value[1024]; 50 - int quote = 0, comment = 0, len = 0, space = 0; 50 + int quote = 0, comment = 0, space = 0; 51 + size_t len = 0; 51 52 52 53 for (;;) { 53 54 int c = get_next_char(); 55 + 54 56 if (len >= sizeof(value) - 1) 55 57 return NULL; 56 58 if (c == '\n') { ··· 355 353 return 0; 356 354 } 357 355 358 - static int perf_default_core_config(const char *var, const char *value) 356 + static int perf_default_core_config(const char *var __used, const char *value __used) 359 357 { 360 358 /* Add other config variables here and to Documentation/config.txt. */ 361 359 return 0; 362 360 } 363 361 364 - int perf_default_config(const char *var, const char *value, void *dummy) 362 + int perf_default_config(const char *var, const char *value, void *dummy __used) 365 363 { 366 364 if (!prefixcmp(var, "core.")) 367 365 return perf_default_core_config(var, value); ··· 473 471 !regexec(store.value_regex, value, 0, NULL, 0))); 474 472 } 475 473 476 - static int store_aux(const char* key, const char* value, void *cb) 474 + static int store_aux(const char* key, const char* value, void *cb __used) 477 475 { 476 + int section_len; 478 477 const char *ep; 479 - size_t section_len; 480 478 481 479 switch (store.state) { 482 480 case KEY_SEEN: ··· 553 551 strbuf_addf(&sb, "[%.*s]\n", store.baselen, key); 554 552 } 555 553 556 - success = write_in_full(fd, sb.buf, sb.len) == sb.len; 554 + success = (write_in_full(fd, sb.buf, sb.len) == (ssize_t)sb.len); 557 555 strbuf_release(&sb); 558 556 559 557 return success; ··· 601 599 } 602 600 strbuf_addf(&sb, "%s\n", quote); 603 601 604 - success = write_in_full(fd, sb.buf, sb.len) == sb.len; 602 + success = (write_in_full(fd, sb.buf, sb.len) == (ssize_t)sb.len); 605 603 strbuf_release(&sb); 606 604 607 605 return success; ··· 743 741 } else { 744 742 struct stat st; 745 743 char* contents; 746 - size_t contents_sz, copy_begin, copy_end; 744 + ssize_t contents_sz, copy_begin, copy_end; 747 745 int i, new_line = 0; 748 746 749 747 if (value_regex == NULL)
+4 -1
tools/perf/util/exec_cmd.c
··· 1 1 #include "cache.h" 2 2 #include "exec_cmd.h" 3 3 #include "quote.h" 4 + 5 + #include <string.h> 6 + 4 7 #define MAX_ARGS 32 5 8 6 9 extern char **environ; ··· 54 51 slash--; 55 52 56 53 if (slash >= argv0) { 57 - argv0_path = strndup(argv0, slash - argv0); 54 + argv0_path = xstrndup(argv0, slash - argv0); 58 55 return slash + 1; 59 56 } 60 57
+15 -11
tools/perf/util/help.c
··· 26 26 return 80; 27 27 } 28 28 29 - void add_cmdname(struct cmdnames *cmds, const char *name, int len) 29 + void add_cmdname(struct cmdnames *cmds, const char *name, size_t len) 30 30 { 31 31 struct cmdname *ent = malloc(sizeof(*ent) + len + 1); 32 32 ··· 40 40 41 41 static void clean_cmdnames(struct cmdnames *cmds) 42 42 { 43 - int i; 43 + unsigned int i; 44 + 44 45 for (i = 0; i < cmds->cnt; ++i) 45 46 free(cmds->names[i]); 46 47 free(cmds->names); ··· 58 57 59 58 static void uniq(struct cmdnames *cmds) 60 59 { 61 - int i, j; 60 + unsigned int i, j; 62 61 63 62 if (!cmds->cnt) 64 63 return; ··· 72 71 73 72 void exclude_cmds(struct cmdnames *cmds, struct cmdnames *excludes) 74 73 { 75 - int ci, cj, ei; 74 + size_t ci, cj, ei; 76 75 int cmp; 77 76 78 77 ci = cj = ei = 0; ··· 107 106 printf(" "); 108 107 109 108 for (j = 0; j < cols; j++) { 110 - int n = j * rows + i; 111 - int size = space; 109 + unsigned int n = j * rows + i; 110 + unsigned int size = space; 111 + 112 112 if (n >= cmds->cnt) 113 113 break; 114 114 if (j == cols-1 || n + rows >= cmds->cnt) ··· 210 208 void list_commands(const char *title, struct cmdnames *main_cmds, 211 209 struct cmdnames *other_cmds) 212 210 { 213 - int i, longest = 0; 211 + unsigned int i, longest = 0; 214 212 215 213 for (i = 0; i < main_cmds->cnt; i++) 216 214 if (longest < main_cmds->names[i]->len) ··· 241 239 242 240 int is_in_cmdlist(struct cmdnames *c, const char *s) 243 241 { 244 - int i; 242 + unsigned int i; 243 + 245 244 for (i = 0; i < c->cnt; i++) 246 245 if (!strcmp(s, c->names[i]->name)) 247 246 return 1; ··· 274 271 275 272 static void add_cmd_list(struct cmdnames *cmds, struct cmdnames *old) 276 273 { 277 - int i; 274 + unsigned int i; 275 + 278 276 ALLOC_GROW(cmds->names, cmds->cnt + old->cnt, cmds->alloc); 279 277 280 278 for (i = 0; i < old->cnt; i++) ··· 287 283 288 284 const char *help_unknown_cmd(const char *cmd) 289 285 { 290 - int i, n = 0, best_similarity = 0; 286 + unsigned int i, n = 0, best_similarity = 0; 291 287 struct cmdnames main_cmds, other_cmds; 292 288 293 289 memset(&main_cmds, 0, sizeof(main_cmds)); ··· 349 345 exit(1); 350 346 } 351 347 352 - int cmd_version(int argc, const char **argv, const char *prefix) 348 + int cmd_version(int argc __used, const char **argv __used, const char *prefix __used) 353 349 { 354 350 printf("perf version %s\n", perf_version_string); 355 351 return 0;
+3 -3
tools/perf/util/help.h
··· 2 2 #define HELP_H 3 3 4 4 struct cmdnames { 5 - int alloc; 6 - int cnt; 5 + size_t alloc; 6 + size_t cnt; 7 7 struct cmdname { 8 8 size_t len; /* also used for similarity index in help.c */ 9 9 char name[FLEX_ARRAY]; ··· 19 19 void load_command_list(const char *prefix, 20 20 struct cmdnames *main_cmds, 21 21 struct cmdnames *other_cmds); 22 - void add_cmdname(struct cmdnames *cmds, const char *name, int len); 22 + void add_cmdname(struct cmdnames *cmds, const char *name, size_t len); 23 23 /* Here we require that excludes is a sorted list. */ 24 24 void exclude_cmds(struct cmdnames *cmds, struct cmdnames *excludes); 25 25 int is_in_cmdlist(struct cmdnames *c, const char *s);
+1 -1
tools/perf/util/parse-events.c
··· 385 385 return 1; 386 386 } 387 387 388 - int parse_events(const struct option *opt, const char *str, int unset) 388 + int parse_events(const struct option *opt __used, const char *str, int unset __used) 389 389 { 390 390 struct perf_counter_attr attr; 391 391
+1 -1
tools/perf/util/parse-options.c
··· 485 485 } 486 486 487 487 488 - int parse_opt_verbosity_cb(const struct option *opt, const char *arg, 488 + int parse_opt_verbosity_cb(const struct option *opt, const char *arg __used, 489 489 int unset) 490 490 { 491 491 int *target = opt->value;
+12 -13
tools/perf/util/parse-options.h
··· 90 90 intptr_t defval; 91 91 }; 92 92 93 - #define OPT_END() { OPTION_END } 94 - #define OPT_ARGUMENT(l, h) { OPTION_ARGUMENT, 0, (l), NULL, NULL, (h) } 95 - #define OPT_GROUP(h) { OPTION_GROUP, 0, NULL, NULL, NULL, (h) } 96 - #define OPT_BIT(s, l, v, h, b) { OPTION_BIT, (s), (l), (v), NULL, (h), 0, NULL, (b) } 97 - #define OPT_BOOLEAN(s, l, v, h) { OPTION_BOOLEAN, (s), (l), (v), NULL, (h) } 98 - #define OPT_SET_INT(s, l, v, h, i) { OPTION_SET_INT, (s), (l), (v), NULL, (h), 0, NULL, (i) } 99 - #define OPT_SET_PTR(s, l, v, h, p) { OPTION_SET_PTR, (s), (l), (v), NULL, (h), 0, NULL, (p) } 100 - #define OPT_INTEGER(s, l, v, h) { OPTION_INTEGER, (s), (l), (v), NULL, (h) } 101 - #define OPT_LONG(s, l, v, h) { OPTION_LONG, (s), (l), (v), NULL, (h) } 102 - #define OPT_STRING(s, l, v, a, h) { OPTION_STRING, (s), (l), (v), (a), (h) } 93 + #define OPT_END() { .type = OPTION_END } 94 + #define OPT_ARGUMENT(l, h) { .type = OPTION_ARGUMENT, .long_name = (l), .help = (h) } 95 + #define OPT_GROUP(h) { .type = OPTION_GROUP, .help = (h) } 96 + #define OPT_BIT(s, l, v, h, b) { .type = OPTION_BIT, .short_name = (s), .long_name = (l), .value = (v), .help = (h), .defval = (b) } 97 + #define OPT_BOOLEAN(s, l, v, h) { .type = OPTION_BOOLEAN, .short_name = (s), .long_name = (l), .value = (v), .help = (h) } 98 + #define OPT_SET_INT(s, l, v, h, i) { .type = OPTION_SET_INT, .short_name = (s), .long_name = (l), .value = (v), .help = (h), .defval = (i) } 99 + #define OPT_SET_PTR(s, l, v, h, p) { .type = OPTION_SET_PTR, .short_name = (s), .long_name = (l), .value = (v), .help = (h), .defval = (p) } 100 + #define OPT_INTEGER(s, l, v, h) { .type = OPTION_INTEGER, .short_name = (s), .long_name = (l), .value = (v), .help = (h) } 101 + #define OPT_LONG(s, l, v, h) { .type = OPTION_LONG, .short_name = (s), .long_name = (l), .value = (v), .help = (h) } 102 + #define OPT_STRING(s, l, v, a, h) { .type = OPTION_STRING, .short_name = (s), .long_name = (l), .value = (v), (a), .help = (h) } 103 103 #define OPT_DATE(s, l, v, h) \ 104 - { OPTION_CALLBACK, (s), (l), (v), "time",(h), 0, \ 105 - parse_opt_approxidate_cb } 104 + { .type = OPTION_CALLBACK, .short_name = (s), .long_name = (l), .value = (v), .argh = "time", .help = (h), .callback = parse_opt_approxidate_cb } 106 105 #define OPT_CALLBACK(s, l, v, a, h, f) \ 107 - { OPTION_CALLBACK, (s), (l), (v), (a), (h), 0, (f) } 106 + { .type = OPTION_CALLBACK, .short_name = (s), .long_name = (l), .value = (v), (a), .help = (h), .callback = (f) } 108 107 109 108 /* parse_options() will filter out the processed options and leave the 110 109 * non-option argments in argv[].
+26 -22
tools/perf/util/quote.c
··· 162 162 return sq_lookup[(unsigned char)c] + quote_path_fully > 0; 163 163 } 164 164 165 - /* returns the longest prefix not needing a quote up to maxlen if positive. 166 - This stops at the first \0 because it's marked as a character needing an 167 - escape */ 168 - static size_t next_quote_pos(const char *s, ssize_t maxlen) 165 + /* 166 + * Returns the longest prefix not needing a quote up to maxlen if 167 + * positive. 168 + * This stops at the first \0 because it's marked as a character 169 + * needing an escape. 170 + */ 171 + static ssize_t next_quote_pos(const char *s, ssize_t maxlen) 169 172 { 170 - size_t len; 173 + ssize_t len; 174 + 171 175 if (maxlen < 0) { 172 176 for (len = 0; !sq_must_quote(s[len]); len++); 173 177 } else { ··· 196 192 static size_t quote_c_style_counted(const char *name, ssize_t maxlen, 197 193 struct strbuf *sb, FILE *fp, int no_dq) 198 194 { 199 - #undef EMIT 200 - #define EMIT(c) \ 201 - do { \ 202 - if (sb) strbuf_addch(sb, (c)); \ 203 - if (fp) fputc((c), fp); \ 204 - count++; \ 205 - } while (0) 206 - #define EMITBUF(s, l) \ 207 - do { \ 208 - int __ret; \ 209 - if (sb) strbuf_add(sb, (s), (l)); \ 210 - if (fp) __ret = fwrite((s), (l), 1, fp); \ 211 - count += (l); \ 195 + #define EMIT(c) \ 196 + do { \ 197 + if (sb) strbuf_addch(sb, (c)); \ 198 + if (fp) fputc((c), fp); \ 199 + count++; \ 212 200 } while (0) 213 201 214 - size_t len, count = 0; 202 + #define EMITBUF(s, l) \ 203 + do { \ 204 + int __ret; \ 205 + if (sb) strbuf_add(sb, (s), (l)); \ 206 + if (fp) __ret = fwrite((s), (l), 1, fp); \ 207 + count += (l); \ 208 + } while (0) 209 + 210 + ssize_t len, count = 0; 215 211 const char *p = name; 216 212 217 213 for (;;) { ··· 277 273 fputc(terminator, fp); 278 274 } 279 275 280 - extern void write_name_quotedpfx(const char *pfx, size_t pfxlen, 281 - const char *name, FILE *fp, int terminator) 276 + void write_name_quotedpfx(const char *pfx, ssize_t pfxlen, 277 + const char *name, FILE *fp, int terminator) 282 278 { 283 279 int needquote = 0; 284 280 ··· 310 306 len = strlen(in); 311 307 312 308 /* "../" prefix itself does not need quoting, but "in" might. */ 313 - needquote = next_quote_pos(in, len) < len; 309 + needquote = (next_quote_pos(in, len) < len); 314 310 strbuf_setlen(out, 0); 315 311 strbuf_grow(out, len); 316 312
+1 -1
tools/perf/util/quote.h
··· 53 53 extern void quote_two_c_style(struct strbuf *, const char *, const char *, int); 54 54 55 55 extern void write_name_quoted(const char *name, FILE *, int terminator); 56 - extern void write_name_quotedpfx(const char *pfx, size_t pfxlen, 56 + extern void write_name_quotedpfx(const char *pfx, ssize_t pfxlen, 57 57 const char *name, FILE *, int terminator); 58 58 59 59 /* quote path as relative to the given prefix */
+7 -6
tools/perf/util/strbuf.c
··· 16 16 */ 17 17 char strbuf_slopbuf[1]; 18 18 19 - void strbuf_init(struct strbuf *sb, size_t hint) 19 + void strbuf_init(struct strbuf *sb, ssize_t hint) 20 20 { 21 21 sb->alloc = sb->len = 0; 22 22 sb->buf = strbuf_slopbuf; ··· 92 92 93 93 void strbuf_tolower(struct strbuf *sb) 94 94 { 95 - int i; 95 + unsigned int i; 96 + 96 97 for (i = 0; i < sb->len; i++) 97 98 sb->buf[i] = tolower(sb->buf[i]); 98 99 } ··· 265 264 return res; 266 265 } 267 266 268 - ssize_t strbuf_read(struct strbuf *sb, int fd, size_t hint) 267 + ssize_t strbuf_read(struct strbuf *sb, int fd, ssize_t hint) 269 268 { 270 269 size_t oldlen = sb->len; 271 270 size_t oldalloc = sb->alloc; ··· 294 293 295 294 #define STRBUF_MAXLINK (2*PATH_MAX) 296 295 297 - int strbuf_readlink(struct strbuf *sb, const char *path, size_t hint) 296 + int strbuf_readlink(struct strbuf *sb, const char *path, ssize_t hint) 298 297 { 299 298 size_t oldalloc = sb->alloc; 300 299 ··· 302 301 hint = 32; 303 302 304 303 while (hint < STRBUF_MAXLINK) { 305 - int len; 304 + ssize_t len; 306 305 307 306 strbuf_grow(sb, hint); 308 307 len = readlink(path, sb->buf, hint); ··· 344 343 return 0; 345 344 } 346 345 347 - int strbuf_read_file(struct strbuf *sb, const char *path, size_t hint) 346 + int strbuf_read_file(struct strbuf *sb, const char *path, ssize_t hint) 348 347 { 349 348 int fd, len; 350 349
+5 -5
tools/perf/util/strbuf.h
··· 50 50 #define STRBUF_INIT { 0, 0, strbuf_slopbuf } 51 51 52 52 /*----- strbuf life cycle -----*/ 53 - extern void strbuf_init(struct strbuf *, size_t); 53 + extern void strbuf_init(struct strbuf *buf, ssize_t hint); 54 54 extern void strbuf_release(struct strbuf *); 55 55 extern char *strbuf_detach(struct strbuf *, size_t *); 56 56 extern void strbuf_attach(struct strbuf *, void *, size_t, size_t); ··· 61 61 } 62 62 63 63 /*----- strbuf size related -----*/ 64 - static inline size_t strbuf_avail(const struct strbuf *sb) { 64 + static inline ssize_t strbuf_avail(const struct strbuf *sb) { 65 65 return sb->alloc ? sb->alloc - sb->len - 1 : 0; 66 66 } 67 67 ··· 122 122 123 123 extern size_t strbuf_fread(struct strbuf *, size_t, FILE *); 124 124 /* XXX: if read fails, any partial read is undone */ 125 - extern ssize_t strbuf_read(struct strbuf *, int fd, size_t hint); 126 - extern int strbuf_read_file(struct strbuf *sb, const char *path, size_t hint); 127 - extern int strbuf_readlink(struct strbuf *sb, const char *path, size_t hint); 125 + extern ssize_t strbuf_read(struct strbuf *, int fd, ssize_t hint); 126 + extern int strbuf_read_file(struct strbuf *sb, const char *path, ssize_t hint); 127 + extern int strbuf_readlink(struct strbuf *sb, const char *path, ssize_t hint); 128 128 129 129 extern int strbuf_getline(struct strbuf *, FILE *, int); 130 130
+3 -2
tools/perf/util/wrapper.c
··· 7 7 * There's no pack memory to release - but stay close to the Git 8 8 * version so wrap this away: 9 9 */ 10 - static inline void release_pack_memory(size_t size, int flag) 10 + static inline void release_pack_memory(size_t size __used, int flag __used) 11 11 { 12 12 } 13 13 ··· 59 59 char *xstrndup(const char *str, size_t len) 60 60 { 61 61 char *p = memchr(str, '\0', len); 62 - return xmemdupz(str, p ? p - str : len); 62 + 63 + return xmemdupz(str, p ? (size_t)(p - str) : len); 63 64 } 64 65 65 66 void *xrealloc(void *ptr, size_t size)