Skip to content

Commit

Permalink
tools, bpftool: Fix warning on ignored return value for 'read'
Browse files Browse the repository at this point in the history
When building bpftool, a warning was introduced by commit a943646
("bpftool: Allow to read btf as raw data"), because the return value
from a call to 'read()' is ignored. Let's address it.

Signed-off-by: Quentin Monnet <quentin.monnet@netronome.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Reviewed-by: Jakub Kicinski <jakub.kicinski@netronome.com>
Acked-by: Andrii Nakryiko <andriin@fb.com>
Link: https://lore.kernel.org/bpf/20191119111706.22440-1-quentin.monnet@netronome.com
  • Loading branch information
Quentin Monnet authored and Alexei Starovoitov committed Nov 25, 2019
1 parent 5d946c5 commit a0f17cc
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions tools/bpf/bpftool/btf.c
Original file line number Diff line number Diff line change
Expand Up @@ -428,15 +428,15 @@ static struct btf *btf__parse_raw(const char *file)
static bool is_btf_raw(const char *file)
{
__u16 magic = 0;
int fd;
int fd, nb_read;

fd = open(file, O_RDONLY);
if (fd < 0)
return false;

read(fd, &magic, sizeof(magic));
nb_read = read(fd, &magic, sizeof(magic));
close(fd);
return magic == BTF_MAGIC;
return nb_read == sizeof(magic) && magic == BTF_MAGIC;
}

static int do_dump(int argc, char **argv)
Expand Down

0 comments on commit a0f17cc

Please sign in to comment.