Skip to content

Commit 266a0a7

Browse files
arndbdavem330
authored andcommitted
bpf: avoid warning for wrong pointer cast
Two new functions in bpf contain a cast from a 'u64' to a pointer. This works on 64-bit architectures but causes a warning on all 32-bit architectures: kernel/trace/bpf_trace.c: In function 'bpf_perf_event_output_tp': kernel/trace/bpf_trace.c:350:13: error: cast to pointer from integer of different size [-Werror=int-to-pointer-cast] u64 ctx = *(long *)r1; This changes the cast to first convert the u64 argument into a uintptr_t, which is guaranteed to be the same size as a pointer. Signed-off-by: Arnd Bergmann <[email protected]> Fixes: 9940d67 ("bpf: support bpf_get_stackid() and bpf_perf_event_output() in tracepoint programs") Acked-by: Alexei Starovoitov <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent b520bd0 commit 266a0a7

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

kernel/trace/bpf_trace.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ static u64 bpf_perf_event_output_tp(u64 r1, u64 r2, u64 index, u64 r4, u64 size)
351351
* from bpf program and contain a pointer to 'struct pt_regs'. Fetch it
352352
* from there and call the same bpf_perf_event_output() helper
353353
*/
354-
u64 ctx = *(long *)r1;
354+
u64 ctx = *(long *)(uintptr_t)r1;
355355

356356
return bpf_perf_event_output(ctx, r2, index, r4, size);
357357
}
@@ -369,7 +369,7 @@ static const struct bpf_func_proto bpf_perf_event_output_proto_tp = {
369369

370370
static u64 bpf_get_stackid_tp(u64 r1, u64 r2, u64 r3, u64 r4, u64 r5)
371371
{
372-
u64 ctx = *(long *)r1;
372+
u64 ctx = *(long *)(uintptr_t)r1;
373373

374374
return bpf_get_stackid(ctx, r2, r3, r4, r5);
375375
}

0 commit comments

Comments
 (0)