Skip to contentSkip to conversation

libbpf: Fix build warning on ref_ctr_off

PATCH Applied Khem Raj 2 participants 2 messages Dec 19, 2022 – Dec 21, 2022

Subsystems (2)
lore
Share & tools
lore

Khem Raj

author
#0 lore raw

PATCH v2 1/1 libbpf: Fix build warning on ref_ctr_off

Clang warns on 32-bit ARM on this comparision

libbpf.c:10497:18: error: result of comparison of constant 4294967296 with expression of type 'size_t' (aka 'unsigned int') is always false [-Werror,-Wtautological-constant-out-of-range-compare]

        if (ref_ctr_off >= (1ULL << PERF_UPROBE_REF_CTR_OFFSET_BITS))
            ~~~~~~~~~~~ ^  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

typecast ref_ctr_off to __u64 in the check conditional, it is false on 32bit anyways.

Cc Alexei Starovoitov <[email protected]>
Cc Daniel Borkmann <[email protected]>
Cc Song Liu <[email protected]>
Cc Yonghong Song <[email protected]>
Cc Jiri Olsa <[email protected]>
Cc Paul Walmsley <[email protected]>
Cc Palmer Dabbelt <[email protected]>
Cc Nathan Chancellor <[email protected]>
Cc Nick Desaulniers <[email protected]>
Cc Andrii Nakryiko <[email protected]>

---
v2: Typecast ref_ctr_off to __u64 instead of checking platform word size

 tools/lib/bpf/libbpf.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/lib/bpf/libbpf.c +1 -1
index 2a82f49ce16f..a5c67a3c93c5 100644
@@ -9903,7 +9903,7 @@ static int perf_event_open_probe(bool uprobe, bool retprobe, const char *name,
 	char errmsg[STRERR_BUFSIZE];
 	int type, pfd;
 
-	if (ref_ctr_off >= (1ULL << PERF_UPROBE_REF_CTR_OFFSET_BITS))
+	if ((__u64)ref_ctr_off >= (1ULL << PERF_UPROBE_REF_CTR_OFFSET_BITS))
 		return -EINVAL;
 
 	memset(&attr, 0, attr_sz);
Signature · 1 line
2.39.0
#1 lore raw
This patch was applied to bpf/bpf-next.git (master) by Andrii Nakryiko <[email protected]>:

Hello:

This patch was applied to bpf/bpf-next.git (master) by Andrii Nakryiko <[email protected]>:

Quoted 9 lines · On Mon, 19 Dec 2022 11:15:26 -0800 you wrote:

Clang warns on 32-bit ARM on this comparision

libbpf.c:10497:18: error: result of comparison of constant 4294967296 with expression of type 'size_t' (aka 'unsigned int') is always false [-Werror,-Wtautological-constant-out-of-range-compare]

        if (ref_ctr_off >= (1ULL << PERF_UPROBE_REF_CTR_OFFSET_BITS))
            ~~~~~~~~~~~ ^  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

typecast ref_ctr_off to __u64 in the check conditional, it is false on 32bit anyways.

[...]

Here is the summary with links:
- [v2] libbpf: Fix build warning on ref_ctr_off

    https://git.kernel.org/bpf/bpf-next/c/1520e8466d68

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html