libbpf/backport-libbpf-Fix-is_pow_of_2.patch
2023-12-08 10:38:57 +08:00

68 lines
2.0 KiB
Diff

From ad0783c4309a37690810a152a8902c3d12b086b5 Mon Sep 17 00:00:00 2001
From: Yuze Chi <chiyuze@google.com>
Date: Thu, 2 Jun 2022 22:51:56 -0700
Subject: [PATCH] libbpf: Fix is_pow_of_2
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
---
src/libbpf.c | 5 -----
src/libbpf_internal.h | 5 +++++
src/linker.c | 5 -----
3 files changed, 5 insertions(+), 10 deletions(-)
diff --git a/src/libbpf.c b/src/libbpf.c
index 5afe4cbd6..b03165687 100644
--- a/src/libbpf.c
+++ b/src/libbpf.c
@@ -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);
diff --git a/src/libbpf_internal.h b/src/libbpf_internal.h
index 4abdbe2fe..ef5d97507 100644
--- a/src/libbpf_internal.h
+++ b/src/libbpf_internal.h
@@ -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 */
diff --git a/src/linker.c b/src/linker.c
index 9aa016fb5..85c0fddf5 100644
--- a/src/linker.c
+++ b/src/linker.c
@@ -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;
--
2.33.0