libbpf: Fix is_pow_of_2
authorYuze Chi <chiyuze@google.com>
Fri, 3 Jun 2022 05:51:56 +0000 (22:51 -0700)
committerAndrii Nakryiko <andrii@kernel.org>
Fri, 3 Jun 2022 21:53:33 +0000 (14:53 -0700)
Move the correct definition from linker.c into libbpf_internal.h.

Fixes: 0087a681fa8c ("libbpf: Automatically fix up BPF_MAP_TYPE_RINGBUF size, if necessary")
Reported-by: Yuze Chi <chiyuze@google.com>
Signed-off-by: Yuze Chi <chiyuze@google.com>
Signed-off-by: Ian Rogers <irogers@google.com>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/bpf/20220603055156.2830463-1-irogers@google.com
tools/lib/bpf/libbpf.c
tools/lib/bpf/libbpf_internal.h
tools/lib/bpf/linker.c

index 5afe4cbd684f14f622fd8177650a5223fb132fcd..b03165687936c5da84020524a31007384627038c 100644 (file)
@@ -5071,11 +5071,6 @@ bpf_object__populate_internal_map(struct bpf_object *obj, struct bpf_map *map)
 
 static void bpf_map__destroy(struct bpf_map *map);
 
-static bool is_pow_of_2(size_t x)
-{
-       return x && (x & (x - 1));
-}
-
 static size_t adjust_ringbuf_sz(size_t sz)
 {
        __u32 page_sz = sysconf(_SC_PAGE_SIZE);
index 4abdbe2fea9d7bca1253ec34d578c12858104c66..ef5d975078e595c03094122d9d90d63ab17aad00 100644 (file)
@@ -580,4 +580,9 @@ struct bpf_link * usdt_manager_attach_usdt(struct usdt_manager *man,
                                           const char *usdt_provider, const char *usdt_name,
                                           __u64 usdt_cookie);
 
+static inline bool is_pow_of_2(size_t x)
+{
+       return x && (x & (x - 1)) == 0;
+}
+
 #endif /* __LIBBPF_LIBBPF_INTERNAL_H */
index 9aa016fb55aa6a345a4d92cab5b06a0cad184f1c..85c0fddf55d12147437270f0ee49fcd3463df844 100644 (file)
@@ -697,11 +697,6 @@ static int linker_load_obj_file(struct bpf_linker *linker, const char *filename,
        return err;
 }
 
-static bool is_pow_of_2(size_t x)
-{
-       return x && (x & (x - 1)) == 0;
-}
-
 static int linker_sanity_check_elf(struct src_obj *obj)
 {
        struct src_sec *sec;