Skip to contentSkip to conversation

libbpf: Remove redundant check in btf_fixup_datasec()

PATCH Applied Yuntao Wang 3 participants 5 messages Feb 20, 2022 – Feb 22, 2022

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 libbpf: Remove redundant check in btf_fixup_datasec()

The check 't->size && t->size != size' is redundant because if t->size compares unequal to 0, we will just skip straight to sorting variables.

---
 tools/lib/bpf/libbpf.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/lib/bpf/libbpf.c +1 -1
index ad43b6ce825e..7e978feaf822 100644
@@ -2795,7 +2795,7 @@ static int btf_fixup_datasec(struct bpf_object *obj, struct btf *btf,
 		goto sort_vars;
 
 	ret = find_elf_sec_sz(obj, name, &size);
-	if (ret || !size || (t->size && t->size != size)) {
+	if (ret || !size) {
 		pr_debug("Invalid size for section %s: %u bytes\n", name, size);
 		return -ENOENT;
 	}
Signature · 1 line
2.35.1
#1 lore raw
Quoted 14 lines · Yuntao Wang

The check 't->size && t->size != size' is redundant because if t->size compares unequal to 0, we will just skip straight to sorting variables.

---
 tools/lib/bpf/libbpf.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/lib/bpf/libbpf.c +0 -0
index ad43b6ce825e..7e978feaf822 100644

tools/lib/bpf/libbpf.c static int btf_fixup_datasec(struct bpf_object *obj, struct btf *btf, · line 2798

Quoted 4 lines
tools/lib/bpf/libbpf.c +0 -1
@@ -2795,7 +2795,7 @@ static int btf_fixup_datasec(struct bpf_object *obj, struct btf *btf,
                goto sort_vars;
 
        ret = find_elf_sec_sz(obj, name, &size);
-       if (ret || !size || (t->size && t->size != size)) {

t->size check is redundant, but (t->size != size) is not

Quoted 7 lines
tools/lib/bpf/libbpf.c +1 -1
+       if (ret || !size) {
                pr_debug("Invalid size for section %s: %u bytes\n", name, size);
                return -ENOENT;
        }
--

2.35.1

#2 lore raw
Quoted 18 lines · Andrii Nakryiko
Quoted 16 lines · Yuntao Wang

The check 't->size && t->size != size' is redundant because if t->size compares unequal to 0, we will just skip straight to sorting variables.

---
 tools/lib/bpf/libbpf.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/lib/bpf/libbpf.c +0 -0
index ad43b6ce825e..7e978feaf822 100644
@@ -2795,7 +2795,7 @@ static int btf_fixup_datasec(struct bpf_object *obj, struct btf *btf,
                goto sort_vars;
 
Quoted 4 lines

tools/lib/bpf/libbpf.c static int btf_fixup_datasec(struct bpf_object *obj, struct btf *btf, · line 2798

Quoted 2 lines
tools/lib/bpf/libbpf.c +0 -1
        ret = find_elf_sec_sz(obj, name, &size);
-       if (ret || !size || (t->size && t->size != size)) {

t->size check is redundant, but (t->size != size) is not

ah, never mind :) applied to bpf-next

Quoted 8 lines
Quoted 8 lines
tools/lib/bpf/libbpf.c +1 -1
+       if (ret || !size) {
                pr_debug("Invalid size for section %s: %u bytes\n", name, size);
                return -ENOENT;
        }
--

2.35.1

#3 lore raw
Quoted 21 lines · Andrii Nakryiko
Quoted 17 lines · Andrii Nakryiko
Quoted 16 lines · Yuntao Wang

The check 't->size && t->size != size' is redundant because if t->size compares unequal to 0, we will just skip straight to sorting variables.

---
 tools/lib/bpf/libbpf.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/lib/bpf/libbpf.c +0 -0
index ad43b6ce825e..7e978feaf822 100644
@@ -2795,7 +2795,7 @@ static int btf_fixup_datasec(struct bpf_object *obj, struct btf *btf,
                goto sort_vars;
 
Quoted 15 lines
Quoted 4 lines

tools/lib/bpf/libbpf.c static int btf_fixup_datasec(struct bpf_object *obj, struct btf *btf, · line 2798

Quoted 2 lines
tools/lib/bpf/libbpf.c +0 -1
        ret = find_elf_sec_sz(obj, name, &size);
-       if (ret || !size || (t->size && t->size != size)) {

t->size check is redundant, but (t->size != size) is not

ah, never mind :) applied to bpf-next

Quoted 8 lines
Quoted 8 lines
tools/lib/bpf/libbpf.c +1 -1
+       if (ret || !size) {
                pr_debug("Invalid size for section %s: %u bytes\n", name, size);
                return -ENOENT;
        }
--

2.35.1

Thanks for your reply.

It seems that the patch has not been applied to bpf-next yet, I can't find it in the commits on the master branch.

Is there anything else I need to do?

#4 lore raw
In reply to Yuntao Wang
This patch was applied to bpf/bpf-next.git (master) by Andrii Nakryiko <[email protected]>:

Hello:

This patch was applied to bpf/bpf-next.git (master) by Andrii Nakryiko <[email protected]>:

Quoted 7 lines · On Sun, 20 Feb 2022 15:27:50 +0800 you wrote:

The check 't->size && t->size != size' is redundant because if t->size compares unequal to 0, we will just skip straight to sorting variables.

---
 tools/lib/bpf/libbpf.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Here is the summary with links:
- [bpf-next] libbpf: Remove redundant check in btf_fixup_datasec()

    https://git.kernel.org/bpf/bpf-next/c/6966d4c4425b

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html