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

Configure Feed

Select the types of activity you want to include in your feed.

bpftool: Using the right format specifiers

Fixed some formatting specifiers errors, such as using %d for int and %u
for unsigned int, as well as other byte-length types.

Signed-off-by: Jiayuan Chen <mrpre@163.com>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Reviewed-by: Quentin Monnet <qmo@kernel.org>
Link: https://lore.kernel.org/bpf/20250207123706.727928-2-mrpre@163.com

authored by

Jiayuan Chen and committed by
Andrii Nakryiko
17c3dc50 9b6cdaf2

+22 -22
+6 -6
tools/bpf/bpftool/gen.c
··· 670 670 continue; 671 671 if (bpf_map__is_internal(map) && 672 672 (bpf_map__map_flags(map) & BPF_F_MMAPABLE)) 673 - printf("\tskel_free_map_data(skel->%1$s, skel->maps.%1$s.initial_value, %2$zd);\n", 673 + printf("\tskel_free_map_data(skel->%1$s, skel->maps.%1$s.initial_value, %2$zu);\n", 674 674 ident, bpf_map_mmap_sz(map)); 675 675 codegen("\ 676 676 \n\ ··· 984 984 985 985 offset = m->offset / 8; 986 986 if (next_offset < offset) 987 - printf("\t\t\tchar __padding_%d[%d];\n", i, offset - next_offset); 987 + printf("\t\t\tchar __padding_%d[%u];\n", i, offset - next_offset); 988 988 989 989 switch (btf_kind(member_type)) { 990 990 case BTF_KIND_INT: ··· 1052 1052 /* Cannot fail since it must be a struct type */ 1053 1053 size = btf__resolve_size(btf, map_type_id); 1054 1054 if (next_offset < (__u32)size) 1055 - printf("\t\t\tchar __padding_end[%d];\n", size - next_offset); 1055 + printf("\t\t\tchar __padding_end[%u];\n", size - next_offset); 1056 1056 1057 1057 out: 1058 1058 btf_dump__free(d); ··· 2095 2095 break; 2096 2096 /* tells if some other type needs to be handled */ 2097 2097 default: 2098 - p_err("unsupported kind: %s (%d)", btf_kind_str(btf_type), type_id); 2098 + p_err("unsupported kind: %s (%u)", btf_kind_str(btf_type), type_id); 2099 2099 return -EINVAL; 2100 2100 } 2101 2101 ··· 2147 2147 btf_type = btf__type_by_id(btf, type_id); 2148 2148 break; 2149 2149 default: 2150 - p_err("unsupported kind: %s (%d)", 2150 + p_err("unsupported kind: %s (%u)", 2151 2151 btf_kind_str(btf_type), btf_type->type); 2152 2152 return -EINVAL; 2153 2153 } ··· 2246 2246 } 2247 2247 /* tells if some other type needs to be handled */ 2248 2248 default: 2249 - p_err("unsupported kind: %s (%d)", btf_kind_str(btf_type), type_id); 2249 + p_err("unsupported kind: %s (%u)", btf_kind_str(btf_type), type_id); 2250 2250 return -EINVAL; 2251 2251 } 2252 2252
+7 -7
tools/bpf/bpftool/link.c
··· 107 107 108 108 fd = bpf_link_get_fd_by_id(id); 109 109 if (fd < 0) 110 - p_err("failed to get link with ID %d: %s", id, strerror(errno)); 110 + p_err("failed to get link with ID %u: %s", id, strerror(errno)); 111 111 return fd; 112 112 } else if (is_prefix(**argv, "pinned")) { 113 113 char *path; ··· 404 404 if (hw_cache) 405 405 snprintf(str, PERF_HW_CACHE_LEN, "%s-", hw_cache); 406 406 else 407 - snprintf(str, PERF_HW_CACHE_LEN, "%lld-", config & 0xff); 407 + snprintf(str, PERF_HW_CACHE_LEN, "%llu-", config & 0xff); 408 408 409 409 op = perf_event_name(evsel__hw_cache_op, (config >> 8) & 0xff); 410 410 if (op) ··· 412 412 "%s-", op); 413 413 else 414 414 snprintf(str + strlen(str), PERF_HW_CACHE_LEN - strlen(str), 415 - "%lld-", (config >> 8) & 0xff); 415 + "%llu-", (config >> 8) & 0xff); 416 416 417 417 result = perf_event_name(evsel__hw_cache_result, config >> 16); 418 418 if (result) ··· 420 420 "%s", result); 421 421 else 422 422 snprintf(str + strlen(str), PERF_HW_CACHE_LEN - strlen(str), 423 - "%lld", config >> 16); 423 + "%llu", config >> 16); 424 424 return str; 425 425 } 426 426 ··· 623 623 else 624 624 snprintf(devname, sizeof(devname), "(detached)"); 625 625 if (ret) 626 - snprintf(devname, sizeof(devname), "%s(%d)", 626 + snprintf(devname, sizeof(devname), "%s(%u)", 627 627 tmpname, ifindex); 628 628 printf("ifindex %s ", devname); 629 629 } ··· 699 699 if (pfname) 700 700 printf("\n\t%s", pfname); 701 701 else 702 - printf("\n\tpf: %d", pf); 702 + printf("\n\tpf: %u", pf); 703 703 704 704 if (hookname) 705 705 printf(" %s", hookname); ··· 773 773 printf("func_cnt %u ", info->uprobe_multi.count); 774 774 775 775 if (info->uprobe_multi.pid) 776 - printf("pid %d ", info->uprobe_multi.pid); 776 + printf("pid %u ", info->uprobe_multi.pid); 777 777 778 778 printf("\n\t%-16s %-16s %-16s", "offset", "ref_ctr_offset", "cookies"); 779 779 for (i = 0; i < info->uprobe_multi.count; i++) {
+4 -4
tools/bpf/bpftool/main.c
··· 152 152 BPFTOOL_MINOR_VERSION, BPFTOOL_PATCH_VERSION); 153 153 #endif 154 154 jsonw_name(json_wtr, "libbpf_version"); 155 - jsonw_printf(json_wtr, "\"%d.%d\"", 155 + jsonw_printf(json_wtr, "\"%u.%u\"", 156 156 libbpf_major_version(), libbpf_minor_version()); 157 157 158 158 jsonw_name(json_wtr, "features"); ··· 370 370 while ((cp = strstr(buf, "\\\n")) != NULL) { 371 371 if (!fgets(contline, sizeof(contline), fp) || 372 372 strlen(contline) == 0) { 373 - p_err("missing continuation line on command %d", 373 + p_err("missing continuation line on command %u", 374 374 lines); 375 375 err = -1; 376 376 goto err_close; ··· 381 381 *cp = '\0'; 382 382 383 383 if (strlen(buf) + strlen(contline) + 1 > sizeof(buf)) { 384 - p_err("command %d is too long", lines); 384 + p_err("command %u is too long", lines); 385 385 err = -1; 386 386 goto err_close; 387 387 } ··· 423 423 err = -1; 424 424 } else { 425 425 if (!json_output) 426 - printf("processed %d commands\n", lines); 426 + printf("processed %u commands\n", lines); 427 427 } 428 428 err_close: 429 429 if (fp != stdin)
+5 -5
tools/bpf/bpftool/map.c
··· 285 285 } 286 286 if (info->value_size) { 287 287 for (i = 0; i < n; i++) { 288 - printf("value (CPU %02d):%c", 288 + printf("value (CPU %02u):%c", 289 289 i, info->value_size > 16 ? '\n' : ' '); 290 290 fprint_hex(stdout, value + i * step, 291 291 info->value_size, " "); ··· 316 316 } 317 317 318 318 if (i != n) { 319 - p_err("%s expected %d bytes got %d", name, n, i); 319 + p_err("%s expected %u bytes got %u", name, n, i); 320 320 return NULL; 321 321 } 322 322 ··· 462 462 jsonw_string_field(wtr, "name", info->name); 463 463 464 464 jsonw_name(wtr, "flags"); 465 - jsonw_printf(wtr, "%d", info->map_flags); 465 + jsonw_printf(wtr, "%u", info->map_flags); 466 466 } 467 467 468 468 static int show_map_close_json(int fd, struct bpf_map_info *info) ··· 588 588 if (prog_type_str) 589 589 printf("owner_prog_type %s ", prog_type_str); 590 590 else 591 - printf("owner_prog_type %d ", prog_type); 591 + printf("owner_prog_type %u ", prog_type); 592 592 } 593 593 if (owner_jited) 594 594 printf("owner%s jited", ··· 615 615 printf("\n\t"); 616 616 617 617 if (info->btf_id) 618 - printf("btf_id %d", info->btf_id); 618 + printf("btf_id %u", info->btf_id); 619 619 620 620 if (frozen) 621 621 printf("%sfrozen", info->btf_id ? " " : "");