Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1380622

[PATCH] bpf: avoid warning for wrong pointer cast

From Arnd Bergmann <arnd@arndb.de>
Newsgroups linux.kernel
Subject [PATCH] bpf: avoid warning for wrong pointer cast
Date 2016-04-16 22:40 +0200
Message-ID <roFaz-WA-29@gated-at.bofh.it> (permalink)
Organization linux.* mail to news gateway

Show all headers | View raw


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 <arnd@arndb.de>
Fixes: 9940d67c93b5 ("bpf: support bpf_get_stackid() and bpf_perf_event_output() in tracepoint programs")
---
 kernel/trace/bpf_trace.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c
index 413ec5614180..c082313a523a 100644
--- a/kernel/trace/bpf_trace.c
+++ b/kernel/trace/bpf_trace.c
@@ -347,7 +347,7 @@ static u64 bpf_perf_event_output_tp(u64 r1, u64 r2, u64 index, u64 r4, u64 size)
 	 * from bpf program and contain a pointer to 'struct pt_regs'. Fetch it
 	 * from there and call the same bpf_perf_event_output() helper
 	 */
-	u64 ctx = *(long *)r1;
+	u64 ctx = *(long *)(uintptr_t)r1;
 
 	return bpf_perf_event_output(ctx, r2, index, r4, size);
 }
@@ -365,7 +365,7 @@ static const struct bpf_func_proto bpf_perf_event_output_proto_tp = {
 
 static u64 bpf_get_stackid_tp(u64 r1, u64 r2, u64 r3, u64 r4, u64 r5)
 {
-	u64 ctx = *(long *)r1;
+	u64 ctx = *(long *)(uintptr_t)r1;
 
 	return bpf_get_stackid(ctx, r2, r3, r4, r5);
 }
-- 
2.7.0

Back to linux.kernel | Previous | NextNext in thread | Find similar | Unroll thread


Thread

[PATCH] bpf: avoid warning for wrong pointer cast Arnd Bergmann <arnd@arndb.de> - 2016-04-16 22:40 +0200
  Re: [PATCH] bpf: avoid warning for wrong pointer cast Alexei Starovoitov <alexei.starovoitov@gmail.com> - 2016-04-17 02:50 +0200
    Re: [PATCH] bpf: avoid warning for wrong pointer cast Fengguang Wu <fengguang.wu@intel.com> - 2016-04-19 04:40 +0200
      Re: [PATCH] bpf: avoid warning for wrong pointer cast Philip Li <philip.li@intel.com> - 2016-04-19 12:10 +0200
        Re: [PATCH] bpf: avoid warning for wrong pointer cast Alexei Starovoitov <ast@fb.com> - 2016-04-19 18:30 +0200
  Re: [PATCH] bpf: avoid warning for wrong pointer cast David Miller <davem@davemloft.net> - 2016-04-18 06:10 +0200

csiph-web