libbpf-tools: Enable compilation warnings for BPF programs
authorHengqi Chen <chenhengqi@outlook.com>
Fri, 15 Oct 2021 05:50:43 +0000 (13:50 +0800)
committerHengqi Chen <chenhengqi@outlook.com>
Fri, 15 Oct 2021 05:50:43 +0000 (13:50 +0800)
Enable -Wall option when compile BPF programs and fix all
compilation warnings.

Signed-off-by: Hengqi Chen <chenhengqi@outlook.com>
libbpf-tools/Makefile
libbpf-tools/biopattern.bpf.c
libbpf-tools/biosnoop.bpf.c
libbpf-tools/biostacks.bpf.c
libbpf-tools/filelife.bpf.c
libbpf-tools/fsdist.bpf.c
libbpf-tools/gethostlatency.bpf.c
libbpf-tools/ksnoop.bpf.c
libbpf-tools/syscount.bpf.c

index 5f21d3ddefbc207cf2323fe188f1512ec1825378..5f7a929535b6620e5ce8918bbe3bcec422497902 100644 (file)
@@ -104,7 +104,7 @@ $(OUTPUT)/%.skel.h: $(OUTPUT)/%.bpf.o | $(OUTPUT)
 
 $(OUTPUT)/%.bpf.o: %.bpf.c $(LIBBPF_OBJ) $(wildcard %.h) $(ARCH)/vmlinux.h | $(OUTPUT)
        $(call msg,BPF,$@)
-       $(Q)$(CLANG) -g -O2 -target bpf -D__TARGET_ARCH_$(ARCH)               \
+       $(Q)$(CLANG) $(CFLAGS) -target bpf -D__TARGET_ARCH_$(ARCH)            \
                     -I$(ARCH)/ $(INCLUDES) -c $(filter %.c,$^) -o $@ &&      \
        $(LLVM_STRIP) -g $@
 
index 3608d362d5840834db7eb4174892d5fc6117e35f..775455bd08f088677e264a844c632a5a83e06e3b 100644 (file)
@@ -19,7 +19,7 @@ struct {
 SEC("tracepoint/block/block_rq_complete")
 int handle__block_rq_complete(struct trace_event_raw_block_rq_complete *ctx)
 {
-       sector_t *last_sectorp,  sector = ctx->sector;
+       sector_t sector = ctx->sector;
        struct counter *counterp, zero = {};
        u32 nr_sector = ctx->nr_sector;
        dev_t dev = ctx->dev;
index 25e1f5462e29014412171d8241a9f65bf9d2d9a9..1c340357fb30815c30616b739b55c5e1347916e4 100644 (file)
@@ -126,7 +126,7 @@ SEC("tp_btf/block_rq_complete")
 int BPF_PROG(block_rq_complete, struct request *rq, int error,
             unsigned int nr_bytes)
 {
-       u64 slot, ts = bpf_ktime_get_ns();
+       u64 ts = bpf_ktime_get_ns();
        struct piddata *piddatap;
        struct event event = {};
        struct stage *stagep;
index f02a1ac5ec21d6ba56ebfe3ab63520bc24d8bb76..69353bc4d45d2bab8e9369f5e7b21b9df78e2711 100644 (file)
@@ -84,7 +84,6 @@ int BPF_PROG(blk_account_io_done, struct request *rq)
 {
        u64 slot, ts = bpf_ktime_get_ns();
        struct internal_rqinfo *i_rqinfop;
-       struct rqinfo *rqinfop;
        struct hist *histp;
        s64 delta;
 
index c2007053dea5b317e63d7c1c30b3b8a1fa4e8f9e..98579b28582d396353875e5e46de42e2de07a6a6 100644 (file)
@@ -57,7 +57,6 @@ int BPF_KPROBE(vfs_unlink, struct inode *dir, struct dentry *dentry)
        const u8 *qs_name_ptr;
        u32 tgid = id >> 32;
        u64 *tsp, delta_ns;
-       u32 qs_len;
 
        tsp = bpf_map_lookup_elem(&start, &dentry);
        if (!tsp)
@@ -67,7 +66,6 @@ int BPF_KPROBE(vfs_unlink, struct inode *dir, struct dentry *dentry)
        bpf_map_delete_elem(&start, &dentry);
 
        qs_name_ptr = BPF_CORE_READ(dentry, d_name.name);
-       qs_len = BPF_CORE_READ(dentry, d_name.len);
        bpf_probe_read_kernel_str(&event.file, sizeof(event.file), qs_name_ptr);
        bpf_get_current_comm(&event.task, sizeof(event.task));
        event.delta_ns = delta_ns;
index 4321e3b3950fd5c29cfff926791a7c63d57ec96b..052e4cd40ff21e69219d2c9044c11001e2afde18 100644 (file)
@@ -37,9 +37,7 @@ static int probe_entry()
 
 static int probe_return(enum fs_file_op op)
 {
-       __u64 pid_tgid = bpf_get_current_pid_tgid();
-       __u32 pid = pid_tgid >> 32;
-       __u32 tid = (__u32)pid_tgid;
+       __u32 tid = (__u32)bpf_get_current_pid_tgid();
        __u64 ts = bpf_ktime_get_ns();
        __u64 *tsp, slot;
        __s64 delta;
index aa3fbd329f4a7cbf8e25b210616ec30187e5af16..2ed5de1fd4b32a74c4eb793374d0f930a16006ef 100644 (file)
@@ -46,9 +46,7 @@ static int probe_entry(struct pt_regs *ctx)
 
 static int probe_return(struct pt_regs *ctx)
 {
-       __u64 pid_tgid = bpf_get_current_pid_tgid();
-       __u32 pid = pid_tgid >> 32;
-       __u32 tid = (__u32)pid_tgid;
+       __u32 tid = (__u32)bpf_get_current_pid_tgid();
        struct event *eventp;
 
        eventp = bpf_map_lookup_elem(&starts, &tid);
index 13342e5eb5653915aaff571e65aed7a45a9783c0..f20b13819280cb813ad28a2fef48a149124eeafd 100644 (file)
@@ -221,7 +221,7 @@ static void output_stashed_traces(struct pt_regs *ctx,
 {
        struct func_stack *func_stack;
        struct trace *trace = NULL;
-       __u8 stack_depth, i;
+       __u8 i;
        __u64 task = 0;
 
        task = bpf_get_current_task();
@@ -229,8 +229,6 @@ static void output_stashed_traces(struct pt_regs *ctx,
        if (!func_stack)
                return;
 
-       stack_depth = func_stack->stack_depth;
-
        if (entry) {
                /* iterate from bottom to top of stack, outputting stashed
                 * data we find.  This corresponds to the set of functions
@@ -294,9 +292,7 @@ static int ksnoop(struct pt_regs *ctx, bool entry)
 {
        void *data_ptr = NULL;
        struct trace *trace;
-       struct func *func;
-       __u16 trace_len;
-       __u64 data, pg;
+       __u64 data;
        __u32 currpid;
        int ret;
        __u8 i;
@@ -305,8 +301,6 @@ static int ksnoop(struct pt_regs *ctx, bool entry)
        if (!trace)
                return 0;
 
-       func = &trace->func;
-
        /* make sure we want events from this pid */
        currpid = bpf_get_current_pid_tgid();
        if (trace->filter_pid && trace->filter_pid != currpid)
@@ -399,7 +393,7 @@ static int ksnoop(struct pt_regs *ctx, bool entry)
                        if (!ok) {
                                clear_trace(trace);
                                return 0;
-                       }       
+                       }
                }
 
                if (currtrace->flags & (KSNOOP_F_PTR | KSNOOP_F_MEMBER))
index d6909dcf49b7f29b9dc80f0a1758e902645df56c..312d33b67ef1c79647b69f3c25d8968a0fe17afc 100644 (file)
@@ -62,7 +62,6 @@ int sys_enter(struct trace_event_raw_sys_enter *args)
 SEC("tracepoint/raw_syscalls/sys_exit")
 int sys_exit(struct trace_event_raw_sys_exit *args)
 {
-       struct task_struct *current;
        u64 id = bpf_get_current_pid_tgid();
        static const struct data_t zero;
        pid_t pid = id >> 32;