bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH bpf-next] tools: bpftool: fix warning on ignored return value for 'read'
@ 2019-11-19 11:17 Quentin Monnet
  2019-11-20 18:14 ` Andrii Nakryiko
  2019-11-21  8:48 ` Daniel Borkmann
  0 siblings, 2 replies; 3+ messages in thread
From: Quentin Monnet @ 2019-11-19 11:17 UTC (permalink / raw)
  To: Alexei Starovoitov, Daniel Borkmann
  Cc: bpf, netdev, oss-drivers, Quentin Monnet, Jiri Olsa

When building bpftool, a warning was introduced by commit a94364603610
("bpftool: Allow to read btf as raw data"), because the return value
from a call to 'read()' is ignored. Let's address it.

Cc: Jiri Olsa <jolsa@kernel.org>
Signed-off-by: Quentin Monnet <quentin.monnet@netronome.com>
Reviewed-by: Jakub Kicinski <jakub.kicinski@netronome.com>
---
 tools/bpf/bpftool/btf.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/tools/bpf/bpftool/btf.c b/tools/bpf/bpftool/btf.c
index a7b8bf233cf5..e5bc97b71ceb 100644
--- a/tools/bpf/bpftool/btf.c
+++ b/tools/bpf/bpftool/btf.c
@@ -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)
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH bpf-next] tools: bpftool: fix warning on ignored return value for 'read'
  2019-11-19 11:17 [PATCH bpf-next] tools: bpftool: fix warning on ignored return value for 'read' Quentin Monnet
@ 2019-11-20 18:14 ` Andrii Nakryiko
  2019-11-21  8:48 ` Daniel Borkmann
  1 sibling, 0 replies; 3+ messages in thread
From: Andrii Nakryiko @ 2019-11-20 18:14 UTC (permalink / raw)
  To: Quentin Monnet
  Cc: Alexei Starovoitov, Daniel Borkmann, bpf, Networking,
	oss-drivers, Jiri Olsa

On Tue, Nov 19, 2019 at 3:18 AM Quentin Monnet
<quentin.monnet@netronome.com> wrote:
>
> When building bpftool, a warning was introduced by commit a94364603610
> ("bpftool: Allow to read btf as raw data"), because the return value
> from a call to 'read()' is ignored. Let's address it.
>
> Cc: Jiri Olsa <jolsa@kernel.org>
> Signed-off-by: Quentin Monnet <quentin.monnet@netronome.com>
> Reviewed-by: Jakub Kicinski <jakub.kicinski@netronome.com>
> ---


Acked-by: Andrii Nakryiko <andriin@fb.com>

>  tools/bpf/bpftool/btf.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
>

[...]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH bpf-next] tools: bpftool: fix warning on ignored return value for 'read'
  2019-11-19 11:17 [PATCH bpf-next] tools: bpftool: fix warning on ignored return value for 'read' Quentin Monnet
  2019-11-20 18:14 ` Andrii Nakryiko
@ 2019-11-21  8:48 ` Daniel Borkmann
  1 sibling, 0 replies; 3+ messages in thread
From: Daniel Borkmann @ 2019-11-21  8:48 UTC (permalink / raw)
  To: Quentin Monnet; +Cc: Alexei Starovoitov, bpf, netdev, oss-drivers, Jiri Olsa

On Tue, Nov 19, 2019 at 11:17:06AM +0000, Quentin Monnet wrote:
> When building bpftool, a warning was introduced by commit a94364603610
> ("bpftool: Allow to read btf as raw data"), because the return value
> from a call to 'read()' is ignored. Let's address it.
> 
> Cc: Jiri Olsa <jolsa@kernel.org>
> Signed-off-by: Quentin Monnet <quentin.monnet@netronome.com>
> Reviewed-by: Jakub Kicinski <jakub.kicinski@netronome.com>

Applied, thanks!

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2019-11-21  8:48 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-19 11:17 [PATCH bpf-next] tools: bpftool: fix warning on ignored return value for 'read' Quentin Monnet
2019-11-20 18:14 ` Andrii Nakryiko
2019-11-21  8:48 ` Daniel Borkmann

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).