public inbox for netdev@vger.kernel.org
 help / color / mirror / Atom feed
From: Yonghong Song <yhs@fb.com>
To: Martin KaFai Lau <kafai@fb.com>, <netdev@vger.kernel.org>
Cc: Alexei Starovoitov <ast@fb.com>,
	Daniel Borkmann <daniel@iogearbox.net>, <kernel-team@fb.com>
Subject: Re: [PATCH v2 bpf 2/3] bpf: Replace [u]int32_t and [u]int64_t in libbpf
Date: Mon, 23 Jul 2018 11:04:34 -0700	[thread overview]
Message-ID: <f9f7ad47-b53b-35c7-d0ab-119d01c2cf41@fb.com> (raw)
In-Reply-To: <20180721182043.1401089-3-kafai@fb.com>



On 7/21/18 11:20 AM, Martin KaFai Lau wrote:
> 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>
> ---
>   tools/lib/bpf/btf.c    | 28 +++++++++++++---------------
>   tools/lib/bpf/btf.h    |  8 ++++----
>   tools/lib/bpf/libbpf.c | 12 ++++++------
>   tools/lib/bpf/libbpf.h |  4 ++--
>   4 files changed, 25 insertions(+), 27 deletions(-)
> 
> diff --git a/tools/lib/bpf/btf.c b/tools/lib/bpf/btf.c
> index 8c54a4b6f187..ce77b5b57912 100644
> --- a/tools/lib/bpf/btf.c
> +++ b/tools/lib/bpf/btf.c
> @@ -2,7 +2,6 @@
>   /* Copyright (c) 2018 Facebook */
>   
>   #include <stdlib.h>
> -#include <stdint.h>
>   #include <string.h>
>   #include <unistd.h>
>   #include <errno.h>
> @@ -27,13 +26,13 @@ struct btf {
>   	struct btf_type **types;
>   	const char *strings;
>   	void *nohdr_data;
> -	uint32_t nr_types;
> -	uint32_t types_size;
> -	uint32_t data_size;
> +	__u32 nr_types;
> +	__u32 types_size;
> +	__u32 data_size;
>   	int fd;
>   };
>   
> -static const char *btf_name_by_offset(const struct btf *btf, uint32_t offset)
> +static const char *btf_name_by_offset(const struct btf *btf, __u32 offset)
>   {
>   	if (offset < btf->hdr->str_len)
>   		return &btf->strings[offset];
> @@ -151,7 +150,7 @@ static int btf_parse_type_sec(struct btf *btf, btf_print_fn_t err_log)
>   
>   	while (next_type < end_type) {
>   		struct btf_type *t = next_type;
> -		uint16_t vlen = BTF_INFO_VLEN(t->info);
> +		__u16 vlen = BTF_INFO_VLEN(t->info);
>   		int err;
>   
>   		next_type += sizeof(*t);
> @@ -191,7 +190,7 @@ static int btf_parse_type_sec(struct btf *btf, btf_print_fn_t err_log)
>   }
>   
>   static const struct btf_type *btf_type_by_id(const struct btf *btf,
> -					     uint32_t type_id)
> +					     __u32 type_id)
>   {
>   	if (type_id > btf->nr_types)
>   		return NULL;
> @@ -226,12 +225,12 @@ static int64_t btf_type_size(const struct btf_type *t)

Missing this one:
    static int64_t btf_type_size(const struct btf_type *t)

There are a couple of instances of using u32 instead of __u32, better to 
use __u32 everywhere in the same file:
                 u32 expand_by, new_size;
         u32 meta_left;


>   
>   #define MAX_RESOLVE_DEPTH 32
>   
> -int64_t btf__resolve_size(const struct btf *btf, uint32_t type_id)
> +__s64 btf__resolve_size(const struct btf *btf, __u32 type_id)
>   {
>   	const struct btf_array *array;
>   	const struct btf_type *t;
> -	uint32_t nelems = 1;
> -	int64_t size = -1;
> +	__u32 nelems = 1;
> +	__s64 size = -1;
>   	int i;
>   
>   	t = btf_type_by_id(btf, type_id);
> @@ -271,9 +270,9 @@ int64_t btf__resolve_size(const struct btf *btf, uint32_t type_id)
>   	return nelems * size;
>   }
>   
> -int32_t btf__find_by_name(const struct btf *btf, const char *type_name)
> +__s32 btf__find_by_name(const struct btf *btf, const char *type_name)
>   {
> -	uint32_t i;
> +	__u32 i;
>   
>   	if (!strcmp(type_name, "void"))
>   		return 0;
> @@ -302,10 +301,9 @@ void btf__free(struct btf *btf)
>   	free(btf);
>   }
>   
> -struct btf *btf__new(uint8_t *data, uint32_t size,
> -		     btf_print_fn_t err_log)
> +struct btf *btf__new(__u8 *data, __u32 size, btf_print_fn_t err_log)
>   {
> -	uint32_t log_buf_size = 0;
> +	__u32 log_buf_size = 0;
>   	char *log_buf = NULL;
>   	struct btf *btf;
>   	int err;
> diff --git a/tools/lib/bpf/btf.h b/tools/lib/bpf/btf.h
> index 74bb344035bb..ed3a84370ccc 100644
> --- a/tools/lib/bpf/btf.h
> +++ b/tools/lib/bpf/btf.h
> @@ -4,7 +4,7 @@
>   #ifndef __BPF_BTF_H
>   #define __BPF_BTF_H
>   
> -#include <stdint.h>
> +#include <linux/types.h>
>   
>   #define BTF_ELF_SEC ".BTF"
>   
> @@ -14,9 +14,9 @@ typedef int (*btf_print_fn_t)(const char *, ...)
>   	__attribute__((format(printf, 1, 2)));
>   
>   void btf__free(struct btf *btf);
> -struct btf *btf__new(uint8_t *data, uint32_t size, btf_print_fn_t err_log);
> -int32_t btf__find_by_name(const struct btf *btf, const char *type_name);
> -int64_t btf__resolve_size(const struct btf *btf, uint32_t type_id);
> +struct btf *btf__new(__u8 *data, __u32 size, btf_print_fn_t err_log);
> +__s32 btf__find_by_name(const struct btf *btf, const char *type_name);
> +__s64 btf__resolve_size(const struct btf *btf, __u32 type_id);
>   int btf__fd(const struct btf *btf);
>   
>   #endif
> diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
> index a1e96b5de5ff..6deb4fe4fffe 100644
> --- a/tools/lib/bpf/libbpf.c
> +++ b/tools/lib/bpf/libbpf.c
> @@ -216,8 +216,8 @@ struct bpf_map {
>   	size_t offset;
>   	int map_ifindex;
>   	struct bpf_map_def def;
> -	uint32_t btf_key_type_id;
> -	uint32_t btf_value_type_id;
> +	__u32 btf_key_type_id;
> +	__u32 btf_value_type_id;
>   	void *priv;
>   	bpf_map_clear_priv_t clear_priv;
>   };
> @@ -1016,8 +1016,8 @@ static int bpf_map_find_btf_info(struct bpf_map *map, const struct btf *btf)
>   {
>   	struct bpf_map_def *def = &map->def;
>   	const size_t max_name = 256;
> -	int64_t key_size, value_size;
> -	int32_t key_id, value_id;
> +	__s64 key_size, value_size;
> +	__s32 key_id, value_id;
>   	char name[max_name];
>   
>   	/* Find key type by name from BTF */
> @@ -2089,12 +2089,12 @@ const char *bpf_map__name(struct bpf_map *map)
>   	return map ? map->name : NULL;
>   }
>   
> -uint32_t bpf_map__btf_key_type_id(const struct bpf_map *map)
> +__u32 bpf_map__btf_key_type_id(const struct bpf_map *map)
>   {
>   	return map ? map->btf_key_type_id : 0;
>   }
>   
> -uint32_t bpf_map__btf_value_type_id(const struct bpf_map *map)
> +__u32 bpf_map__btf_value_type_id(const struct bpf_map *map)
>   {
>   	return map ? map->btf_value_type_id : 0;
>   }
> diff --git a/tools/lib/bpf/libbpf.h b/tools/lib/bpf/libbpf.h
> index 09976531aa74..b33ae02f7d0e 100644
> --- a/tools/lib/bpf/libbpf.h
> +++ b/tools/lib/bpf/libbpf.h
> @@ -244,8 +244,8 @@ bpf_map__next(struct bpf_map *map, struct bpf_object *obj);
>   int bpf_map__fd(struct bpf_map *map);
>   const struct bpf_map_def *bpf_map__def(struct bpf_map *map);
>   const char *bpf_map__name(struct bpf_map *map);
> -uint32_t bpf_map__btf_key_type_id(const struct bpf_map *map);
> -uint32_t bpf_map__btf_value_type_id(const struct bpf_map *map);
> +__u32 bpf_map__btf_key_type_id(const struct bpf_map *map);
> +__u32 bpf_map__btf_value_type_id(const struct bpf_map *map);
>   
>   typedef void (*bpf_map_clear_priv_t)(struct bpf_map *, void *);
>   int bpf_map__set_priv(struct bpf_map *map, void *priv,
> 

  reply	other threads:[~2018-07-23 19:07 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-07-21 18:20 [PATCH v2 bpf 0/3] Introduce BPF_ANNOTATE_KV_PAIR Martin KaFai Lau
2018-07-21 18:20 ` [PATCH v2 bpf 1/3] bpf: btf: Sync uapi btf.h to tools Martin KaFai Lau
2018-07-23 17:58   ` Yonghong Song
2018-07-21 18:20 ` [PATCH v2 bpf 2/3] bpf: Replace [u]int32_t and [u]int64_t in libbpf Martin KaFai Lau
2018-07-23 18:04   ` Yonghong Song [this message]
2018-07-23 18:41     ` Martin KaFai Lau
2018-07-21 18:20 ` [PATCH v2 bpf 3/3] bpf: Introduce BPF_ANNOTATE_KV_PAIR Martin KaFai Lau
2018-07-23 18:31   ` Yonghong Song
2018-07-23 18:41     ` Martin KaFai Lau

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=f9f7ad47-b53b-35c7-d0ab-119d01c2cf41@fb.com \
    --to=yhs@fb.com \
    --cc=ast@fb.com \
    --cc=daniel@iogearbox.net \
    --cc=kafai@fb.com \
    --cc=kernel-team@fb.com \
    --cc=netdev@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox