Skip to contentSkip to conversation

tools, bpftool: Avoid array index warnings.

PATCH In review Ian Rogers 3 participants 6 messages Oct 28, 2020

Subsystems (4)
lore
Share & tools
lore

Ian Rogers

author
#0 lore raw

PATCH 1/2 tools, bpftool: Avoid array index warnings.

The bpf_caps array is shorter without CAP_BPF, avoid out of bounds reads if this isn't defined. Working around this avoids -Wno-array-bounds with clang.

---
 tools/bpf/bpftool/feature.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
tools/bpf/bpftool/feature.c +6 -1
index a43a6f10b564..359960a8f1de 100644
@@ -843,9 +843,14 @@ static int handle_perms(void)
 		else
 			p_err("missing %s%s%s%s%s%s%s%srequired for full feature probing; run as root or use 'unprivileged'",
 			      capability_msg(bpf_caps, 0),
+#ifdef CAP_BPF
 			      capability_msg(bpf_caps, 1),
 			      capability_msg(bpf_caps, 2),
-			      capability_msg(bpf_caps, 3));
+			      capability_msg(bpf_caps, 3)
+#else
+				"", "", "", "", "", ""
+#endif /* CAP_BPF */
+				);
 		goto exit_free;
 	}
 
Signature · 1 line
2.29.0.rc2.309.g374f81d7ae-goog
author
#1 lore raw

PATCH 2/2 tools, bpftool: Remove two unused variables.

Avoid an unused variable warning.

---
 tools/bpf/bpftool/skeleton/profiler.bpf.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
tools/bpf/bpftool/skeleton/profiler.bpf.c +2 -2
index 4e3512f700c0..ce5b65e07ab1 100644
@@ -70,7 +70,7 @@ int BPF_PROG(fentry_XXX)
 static inline void
 fexit_update_maps(u32 id, struct bpf_perf_event_value *after)
 {
-	struct bpf_perf_event_value *before, diff, *accum;
+	struct bpf_perf_event_value *before, diff;
 
 	before = bpf_map_lookup_elem(&fentry_readings, &id);
 	/* only account samples with a valid fentry_reading */
@@ -95,7 +95,7 @@ int BPF_PROG(fexit_XXX)
 {
 	struct bpf_perf_event_value readings[MAX_NUM_MATRICS];
 	u32 cpu = bpf_get_smp_processor_id();
-	u32 i, one = 1, zero = 0;
+	u32 i, zero = 0;
 	int err;
 	u64 *count;
 
Signature · 1 line
2.29.0.rc2.309.g374f81d7ae-goog
Acked-by on v1 2/2
#2 lore raw

Re: [PATCH 2/2] tools, bpftool: Remove two unused variables.

Quoted 5 lines · Ian Rogers

Avoid an unused variable warning.

---

Quoted 28 lines
 tools/bpf/bpftool/skeleton/profiler.bpf.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
tools/bpf/bpftool/skeleton/profiler.bpf.c +2 -3
index 4e3512f700c0..ce5b65e07ab1 100644
@@ -70,7 +70,7 @@ int BPF_PROG(fentry_XXX)
 static inline void
 fexit_update_maps(u32 id, struct bpf_perf_event_value *after)
 {
-       struct bpf_perf_event_value *before, diff, *accum;
+       struct bpf_perf_event_value *before, diff;
 
        before = bpf_map_lookup_elem(&fentry_readings, &id);
        /* only account samples with a valid fentry_reading */
@@ -95,7 +95,7 @@ int BPF_PROG(fexit_XXX)
 {
        struct bpf_perf_event_value readings[MAX_NUM_MATRICS];
        u32 cpu = bpf_get_smp_processor_id();
-       u32 i, one = 1, zero = 0;
+       u32 i, zero = 0;
        int err;
        u64 *count;
 
--

2.29.0.rc2.309.g374f81d7ae-goog

Acked-by on v1 1/2
#4 lore raw
In reply to Ian Rogers
Quoted 7 lines · Ian Rogers

The bpf_caps array is shorter without CAP_BPF, avoid out of bounds reads if this isn't defined. Working around this avoids -Wno-array-bounds with clang.

---

Quoted 26 lines
 tools/bpf/bpftool/feature.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
tools/bpf/bpftool/feature.c +6 -2
index a43a6f10b564..359960a8f1de 100644
@@ -843,9 +843,14 @@ static int handle_perms(void)
                else
                        p_err("missing %s%s%s%s%s%s%s%srequired for full feature probing; run as root or use 'unprivileged'",
                              capability_msg(bpf_caps, 0),
+#ifdef CAP_BPF
                              capability_msg(bpf_caps, 1),
                              capability_msg(bpf_caps, 2),
-                             capability_msg(bpf_caps, 3));
+                             capability_msg(bpf_caps, 3)
+#else
+                               "", "", "", "", "", ""
+#endif /* CAP_BPF */
+                               );
                goto exit_free;
        }
 
--

2.29.0.rc2.309.g374f81d7ae-goog