]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
bpf: Remove unnecessary call to btf_field_type_size().
authorKui-Feng Lee <thinker.li@gmail.com>
Thu, 23 May 2024 17:41:55 +0000 (10:41 -0700)
committerAlexei Starovoitov <ast@kernel.org>
Tue, 4 Jun 2024 03:52:42 +0000 (20:52 -0700)
field->size has been initialized by bpf_parse_fields() with the value
returned by btf_field_type_size(). Use it instead of calling
btf_field_type_size() again.

Acked-by: Eduard Zingerman <eddyz87@gmail.com>
Signed-off-by: Kui-Feng Lee <thinker.li@gmail.com>
Link: https://lore.kernel.org/r/20240523174202.461236-3-thinker.li@gmail.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
kernel/bpf/btf.c
kernel/bpf/verifier.c

index 821063660d9f9db1e4a5efac43cc9b59d8327378..226138bd139af8f68b690a94e288ed5bae817573 100644 (file)
@@ -6693,7 +6693,7 @@ int btf_struct_access(struct bpf_verifier_log *log,
                for (i = 0; i < rec->cnt; i++) {
                        struct btf_field *field = &rec->fields[i];
                        u32 offset = field->offset;
-                       if (off < offset + btf_field_type_size(field->type) && offset < off + size) {
+                       if (off < offset + field->size && offset < off + size) {
                                bpf_log(log,
                                        "direct access to %s is disallowed\n",
                                        btf_field_type_name(field->type));
index 57c0c255bf4c6148c3cb0ad4549a434ffcff1b95..81a3d2ced78d538b72bba1afeb1d68622c5b5bc8 100644 (file)
@@ -5448,7 +5448,7 @@ static int check_map_access(struct bpf_verifier_env *env, u32 regno,
                 * this program. To check that [x1, x2) overlaps with [y1, y2),
                 * it is sufficient to check x1 < y2 && y1 < x2.
                 */
-               if (reg->smin_value + off < p + btf_field_type_size(field->type) &&
+               if (reg->smin_value + off < p + field->size &&
                    p < reg->umax_value + off + size) {
                        switch (field->type) {
                        case BPF_KPTR_UNREF: