Skip to contentSkip to conversation

bpf: fix dump_stack() type cast

PATCH In review Arnd Bergmann 2 participants 2 messages Jul 8, 2025 BPF

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 bpf: fix dump_stack() type cast

From: Arnd Bergmann <[email protected]>

Passing a pointer as a 'u64' variable requires a double cast when converting it back to a pointer:

kernel/bpf/stream.c: In function 'dump_stack_cb':
kernel/bpf/stream.c:505:64: error: cast to pointer from integer of different size [-Werror=int-to-pointer-cast]
505 | ctxp->err = bpf_stream_stage_printk(ctxp->ss, "%pS\n", (void *)ip);
| ^

Fixes d7c431cafcb4 ("bpf: Add dump_stack() analogue to print to BPF stderr")
---
 kernel/bpf/stream.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
kernel/bpf/stream.c +2 -2
index 8c842f845245..24433cdf6ede 100644
@@ -498,11 +498,11 @@ static bool dump_stack_cb(void *cookie, u64 ip, u64 sp, u64 bp)
 		if (ret < 0)
 			goto end;
 		ctxp->err = bpf_stream_stage_printk(ctxp->ss, "%pS\n  %s @ %s:%d\n",
-						    (void *)ip, line, file, num);
+					    (void *)(uintptr_t)ip, line, file, num);
 		return !ctxp->err;
 	}
 end:
-	ctxp->err = bpf_stream_stage_printk(ctxp->ss, "%pS\n", (void *)ip);
+	ctxp->err = bpf_stream_stage_printk(ctxp->ss, "%pS\n", (void *)(uintptr_t)ip);
 	return !ctxp->err;
 }
 
Signature · 1 line
2.39.5
maintainer
#1 lore raw
Quoted 5 lines · Arnd Bergmann

From: Arnd Bergmann <[email protected]>

Passing a pointer as a 'u64' variable requires a double cast when converting it back to a pointer:

Quoted 8 lines

kernel/bpf/stream.c: In function 'dump_stack_cb':
kernel/bpf/stream.c:505:64: error: cast to pointer from integer of different size [-Werror=int-to-pointer-cast]
505 | ctxp->err = bpf_stream_stage_printk(ctxp->ss, "%pS\n", (void *)ip);
| ^

Fixes d7c431cafcb4 ("bpf: Add dump_stack() analogue to print to BPF stderr")

---

This warning is already fixed in
bfa2bb9abd99be ("bpf: Fix improper int-to-ptr cast in dump_stack_cb"), which landed in bpf-next yesterday.

[...]