BPF List
 help / color / mirror / Atom feed
* [PATCH bpf-next] libbpf: Remove redundant check in btf_ext__new()
@ 2022-03-12 17:13 Yuntao Wang
  2022-03-15 18:36 ` Andrii Nakryiko
  0 siblings, 1 reply; 6+ messages in thread
From: Yuntao Wang @ 2022-03-12 17:13 UTC (permalink / raw)
  To: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko
  Cc: Martin KaFai Lau, Song Liu, Yonghong Song, John Fastabend,
	KP Singh, netdev, bpf, linux-kernel, Yuntao Wang

Since 'core_relo_len' is the last field of 'struct btf_ext_header', if
'xxx->hdr_len' is not less than 'offsetofend(xxx, core_relo_len)', then
'xxx->hdr_len' must also be not less than 'offsetofend(xxx, line_info_len)'.

We can check 'xxx->hdr_len < offsetofend(xxx, core_relo_len)' first, if it
passes, the 'xxx->hdr_len < offsetofend(xxx, line_info_len)' check will be
redundant, it can be removed.

Signed-off-by: Yuntao Wang <ytcoode@gmail.com>
---
 tools/lib/bpf/btf.c | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)

diff --git a/tools/lib/bpf/btf.c b/tools/lib/bpf/btf.c
index 1383e26c5d1f..d55b44124c3e 100644
--- a/tools/lib/bpf/btf.c
+++ b/tools/lib/bpf/btf.c
@@ -2813,7 +2813,7 @@ struct btf_ext *btf_ext__new(const __u8 *data, __u32 size)
 	if (err)
 		goto done;
 
-	if (btf_ext->hdr->hdr_len < offsetofend(struct btf_ext_header, line_info_len)) {
+	if (btf_ext->hdr->hdr_len < offsetofend(struct btf_ext_header, core_relo_len)) {
 		err = -EINVAL;
 		goto done;
 	}
@@ -2826,11 +2826,6 @@ struct btf_ext *btf_ext__new(const __u8 *data, __u32 size)
 	if (err)
 		goto done;
 
-	if (btf_ext->hdr->hdr_len < offsetofend(struct btf_ext_header, core_relo_len)) {
-		err = -EINVAL;
-		goto done;
-	}
-
 	err = btf_ext_setup_core_relos(btf_ext);
 	if (err)
 		goto done;
-- 
2.35.1


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

end of thread, other threads:[~2022-04-04  1:30 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-03-12 17:13 [PATCH bpf-next] libbpf: Remove redundant check in btf_ext__new() Yuntao Wang
2022-03-15 18:36 ` Andrii Nakryiko
2022-03-16 14:52   ` [PATCH bpf-next v2] libbpf: Don't return -EINVAL if hdr_len < offsetofend(core_relo_len) Yuntao Wang
2022-04-03 23:10     ` Andrii Nakryiko
2022-04-04  0:53       ` [PATCH bpf-next v3] " Yuntao Wang
2022-04-04  1:30         ` patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox