Skip to content

Commit

Permalink
samples: bpf: Fix conflicting types in fds_example
Browse files Browse the repository at this point in the history
Fix the following samples/bpf build error appeared after the
introduction of bpf_map_create() in libbpf:

  CC  samples/bpf/fds_example.o
samples/bpf/fds_example.c:49:12: error: static declaration of 'bpf_map_create' follows non-static declaration
static int bpf_map_create(void)
           ^
samples/bpf/libbpf/include/bpf/bpf.h:55:16: note: previous declaration is here
LIBBPF_API int bpf_map_create(enum bpf_map_type map_type,
               ^
samples/bpf/fds_example.c:82:23: error: too few arguments to function call, expected 6, have 0
                fd = bpf_map_create();
                     ~~~~~~~~~~~~~~ ^
samples/bpf/libbpf/include/bpf/bpf.h:55:16: note: 'bpf_map_create' declared here
LIBBPF_API int bpf_map_create(enum bpf_map_type map_type,
               ^
2 errors generated.

fds_example by accident has a static function with the same name.
It's not worth it to separate a single call into its own function,
so just embed it.

Fixes: 992c422 ("libbpf: Unify low-level map creation APIs w/ new bpf_map_create()")
Signed-off-by: Alexander Lobakin <alexandr.lobakin@intel.com>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Reviewed-by: Maciej Fijalkowski <maciej.fijalkowski@intel.com>
Acked-by: Toke Høiland-Jørgensen <toke@redhat.com>
Link: https://lore.kernel.org/bpf/20211201164931.47357-1-alexandr.lobakin@intel.com
  • Loading branch information
Alexander Lobakin authored and Andrii Nakryiko committed Dec 1, 2021
1 parent 436d404 commit 64b5b97
Showing 1 changed file with 2 additions and 7 deletions.
9 changes: 2 additions & 7 deletions samples/bpf/fds_example.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,6 @@ static void usage(void)
printf(" -h Display this help.\n");
}

static int bpf_map_create(void)
{
return bpf_create_map(BPF_MAP_TYPE_ARRAY, sizeof(uint32_t),
sizeof(uint32_t), 1024, 0);
}

static int bpf_prog_create(const char *object)
{
static struct bpf_insn insns[] = {
Expand Down Expand Up @@ -79,7 +73,8 @@ static int bpf_do_map(const char *file, uint32_t flags, uint32_t key,
int fd, ret;

if (flags & BPF_F_PIN) {
fd = bpf_map_create();
fd = bpf_create_map(BPF_MAP_TYPE_ARRAY, sizeof(uint32_t),
sizeof(uint32_t), 1024, 0);
printf("bpf: map fd:%d (%s)\n", fd, strerror(errno));
assert(fd > 0);

Expand Down

0 comments on commit 64b5b97

Please sign in to comment.