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

bpf: Replace [u]int32_t and [u]int64_t in libbpf

This patch replaces [u]int32_t and [u]int64_t usage with
__[su]32 and __[su]64. The same change goes for [u]int16_t
and [u]int8_t.

Fixes: 8a138aed4a80 ("bpf: btf: Add BTF support to libbpf")
Signed-off-by: Martin KaFai Lau <kafai@fb.com>
Acked-by: Yonghong Song <yhs@fb.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>

authored by

Martin KaFai Lau and committed by
Daniel Borkmann
5b891af7 64bb5684

+28 -30
+16 -18
tools/lib/bpf/btf.c
··· 2 2 /* Copyright (c) 2018 Facebook */ 3 3 4 4 #include <stdlib.h> 5 - #include <stdint.h> 6 5 #include <string.h> 7 6 #include <unistd.h> 8 7 #include <errno.h> ··· 26 27 struct btf_type **types; 27 28 const char *strings; 28 29 void *nohdr_data; 29 - uint32_t nr_types; 30 - uint32_t types_size; 31 - uint32_t data_size; 30 + __u32 nr_types; 31 + __u32 types_size; 32 + __u32 data_size; 32 33 int fd; 33 34 }; 34 35 35 - static const char *btf_name_by_offset(const struct btf *btf, uint32_t offset) 36 + static const char *btf_name_by_offset(const struct btf *btf, __u32 offset) 36 37 { 37 38 if (offset < btf->hdr->str_len) 38 39 return &btf->strings[offset]; ··· 44 45 { 45 46 if (btf->types_size - btf->nr_types < 2) { 46 47 struct btf_type **new_types; 47 - u32 expand_by, new_size; 48 + __u32 expand_by, new_size; 48 49 49 50 if (btf->types_size == BTF_MAX_NR_TYPES) 50 51 return -E2BIG; ··· 71 72 static int btf_parse_hdr(struct btf *btf, btf_print_fn_t err_log) 72 73 { 73 74 const struct btf_header *hdr = btf->hdr; 74 - u32 meta_left; 75 + __u32 meta_left; 75 76 76 77 if (btf->data_size < sizeof(struct btf_header)) { 77 78 elog("BTF header not found\n"); ··· 150 151 151 152 while (next_type < end_type) { 152 153 struct btf_type *t = next_type; 153 - uint16_t vlen = BTF_INFO_VLEN(t->info); 154 + __u16 vlen = BTF_INFO_VLEN(t->info); 154 155 int err; 155 156 156 157 next_type += sizeof(*t); ··· 190 191 } 191 192 192 193 static const struct btf_type *btf_type_by_id(const struct btf *btf, 193 - uint32_t type_id) 194 + __u32 type_id) 194 195 { 195 196 if (type_id > btf->nr_types) 196 197 return NULL; ··· 208 209 return !t || btf_type_is_void(t); 209 210 } 210 211 211 - static int64_t btf_type_size(const struct btf_type *t) 212 + static __s64 btf_type_size(const struct btf_type *t) 212 213 { 213 214 switch (BTF_INFO_KIND(t->info)) { 214 215 case BTF_KIND_INT: ··· 225 226 226 227 #define MAX_RESOLVE_DEPTH 32 227 228 228 - int64_t btf__resolve_size(const struct btf *btf, uint32_t type_id) 229 + __s64 btf__resolve_size(const struct btf *btf, __u32 type_id) 229 230 { 230 231 const struct btf_array *array; 231 232 const struct btf_type *t; 232 - uint32_t nelems = 1; 233 - int64_t size = -1; 233 + __u32 nelems = 1; 234 + __s64 size = -1; 234 235 int i; 235 236 236 237 t = btf_type_by_id(btf, type_id); ··· 270 271 return nelems * size; 271 272 } 272 273 273 - int32_t btf__find_by_name(const struct btf *btf, const char *type_name) 274 + __s32 btf__find_by_name(const struct btf *btf, const char *type_name) 274 275 { 275 - uint32_t i; 276 + __u32 i; 276 277 277 278 if (!strcmp(type_name, "void")) 278 279 return 0; ··· 301 302 free(btf); 302 303 } 303 304 304 - struct btf *btf__new(uint8_t *data, uint32_t size, 305 - btf_print_fn_t err_log) 305 + struct btf *btf__new(__u8 *data, __u32 size, btf_print_fn_t err_log) 306 306 { 307 - uint32_t log_buf_size = 0; 307 + __u32 log_buf_size = 0; 308 308 char *log_buf = NULL; 309 309 struct btf *btf; 310 310 int err;
+4 -4
tools/lib/bpf/btf.h
··· 4 4 #ifndef __BPF_BTF_H 5 5 #define __BPF_BTF_H 6 6 7 - #include <stdint.h> 7 + #include <linux/types.h> 8 8 9 9 #define BTF_ELF_SEC ".BTF" 10 10 ··· 14 14 __attribute__((format(printf, 1, 2))); 15 15 16 16 void btf__free(struct btf *btf); 17 - struct btf *btf__new(uint8_t *data, uint32_t size, btf_print_fn_t err_log); 18 - int32_t btf__find_by_name(const struct btf *btf, const char *type_name); 19 - int64_t btf__resolve_size(const struct btf *btf, uint32_t type_id); 17 + struct btf *btf__new(__u8 *data, __u32 size, btf_print_fn_t err_log); 18 + __s32 btf__find_by_name(const struct btf *btf, const char *type_name); 19 + __s64 btf__resolve_size(const struct btf *btf, __u32 type_id); 20 20 int btf__fd(const struct btf *btf); 21 21 22 22 #endif
+6 -6
tools/lib/bpf/libbpf.c
··· 216 216 size_t offset; 217 217 int map_ifindex; 218 218 struct bpf_map_def def; 219 - uint32_t btf_key_type_id; 220 - uint32_t btf_value_type_id; 219 + __u32 btf_key_type_id; 220 + __u32 btf_value_type_id; 221 221 void *priv; 222 222 bpf_map_clear_priv_t clear_priv; 223 223 }; ··· 1016 1016 { 1017 1017 struct bpf_map_def *def = &map->def; 1018 1018 const size_t max_name = 256; 1019 - int64_t key_size, value_size; 1020 - int32_t key_id, value_id; 1019 + __s64 key_size, value_size; 1020 + __s32 key_id, value_id; 1021 1021 char name[max_name]; 1022 1022 1023 1023 /* Find key type by name from BTF */ ··· 2089 2089 return map ? map->name : NULL; 2090 2090 } 2091 2091 2092 - uint32_t bpf_map__btf_key_type_id(const struct bpf_map *map) 2092 + __u32 bpf_map__btf_key_type_id(const struct bpf_map *map) 2093 2093 { 2094 2094 return map ? map->btf_key_type_id : 0; 2095 2095 } 2096 2096 2097 - uint32_t bpf_map__btf_value_type_id(const struct bpf_map *map) 2097 + __u32 bpf_map__btf_value_type_id(const struct bpf_map *map) 2098 2098 { 2099 2099 return map ? map->btf_value_type_id : 0; 2100 2100 }
+2 -2
tools/lib/bpf/libbpf.h
··· 244 244 int bpf_map__fd(struct bpf_map *map); 245 245 const struct bpf_map_def *bpf_map__def(struct bpf_map *map); 246 246 const char *bpf_map__name(struct bpf_map *map); 247 - uint32_t bpf_map__btf_key_type_id(const struct bpf_map *map); 248 - uint32_t bpf_map__btf_value_type_id(const struct bpf_map *map); 247 + __u32 bpf_map__btf_key_type_id(const struct bpf_map *map); 248 + __u32 bpf_map__btf_value_type_id(const struct bpf_map *map); 249 249 250 250 typedef void (*bpf_map_clear_priv_t)(struct bpf_map *, void *); 251 251 int bpf_map__set_priv(struct bpf_map *map, void *priv,