[RFC PATCH v2 14/26] perf bpf: Add -Wextra to cflags for more warnings and fix them

From: He Kuang
Date: Sun Jun 26 2016 - 07:23:04 EST


Since -Wextra is used in perf tools, this patch adopts this cflags
into lib/bpf. It also fixes 'comparison between signed and unsigned
integer' errors reported afterward.

Signed-off-by: He Kuang <hekuang@xxxxxxxxxx>
---
tools/lib/bpf/Makefile | 2 +-
tools/lib/bpf/libbpf.c | 7 ++++---
2 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/tools/lib/bpf/Makefile b/tools/lib/bpf/Makefile
index 1fb098d..65a64d8 100644
--- a/tools/lib/bpf/Makefile
+++ b/tools/lib/bpf/Makefile
@@ -126,7 +126,7 @@ endif

# Append required CFLAGS
override CFLAGS += $(EXTRA_WARNINGS)
-override CFLAGS += -Werror -Wall
+override CFLAGS += -Werror -Wall -Wextra
override CFLAGS += -fPIC
override CFLAGS += $(INCLUDES)

diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
index a53cb579..ddbba35 100644
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@ -443,7 +443,7 @@ bpf_object__init_maps(struct bpf_object *obj, void *data,
size_t size)
{
size_t nr_maps;
- int i;
+ unsigned int i;

nr_maps = size / sizeof(struct bpf_map_def);
if (!data || !nr_maps) {
@@ -480,7 +480,7 @@ bpf_object__init_maps(struct bpf_object *obj, void *data,
static int
bpf_object__init_maps_name(struct bpf_object *obj)
{
- int i;
+ unsigned int i;
Elf_Data *symbols = obj->efile.symbols;

if (!symbols || obj->efile.maps_shndx < 0)
@@ -521,7 +521,8 @@ static int bpf_object__elf_collect(struct bpf_object *obj)
Elf *elf = obj->efile.elf;
GElf_Ehdr *ep = &obj->efile.ehdr;
Elf_Scn *scn = NULL;
- int idx = 0, err = 0;
+ unsigned int idx = 0;
+ int err = 0;

/* Elf is corrupted/truncated, avoid calling elf_strptr. */
if (!elf_rawdata(elf_getscn(elf, ep->e_shstrndx), NULL)) {
--
1.8.5.2