Re: [PATCH bpf-next v1 3/4] resolve_btfids: introduce enum btf_id_kind

From: bot+bpf-ci

Date: Tue Nov 25 2025 - 21:10:52 EST


> diff --git a/tools/bpf/resolve_btfids/main.c b/tools/bpf/resolve_btfids/main.c
> index b7b44e72e..7f5a9f7dd 100644
> --- a/tools/bpf/resolve_btfids/main.c
> +++ b/tools/bpf/resolve_btfids/main.c

[ ... ]

> @@ -260,26 +266,33 @@ static char *get_id(const char *prefix_end)
> return id;
> }
>
> -static struct btf_id *add_set(struct object *obj, char *name, bool is_set8)
> +static struct btf_id *add_set(struct object *obj, char *name, enum btf_id_kind kind)
> {
> /*
> * __BTF_ID__set__name
> * name = ^
> * id = ^
> */
> - char *id = name + (is_set8 ? sizeof(BTF_SET8 "__") : sizeof(BTF_SET "__")) - 1;
> + int prefixlen = kind == BTF_ID_KIND_SET8 ? sizeof(BTF_SET8 "__") : sizeof(BTF_SET "__");
> + char *id = name + prefixlen - 1;
> int len = strlen(name);
> + struct btf_id *btf_id;
>
> if (id >= name + len) {
> pr_err("FAILED to parse set name: %s\n", name);
> return NULL;
> }
>
> - return btf_id__add(&obj->sets, id, true);
> + btf_id = btf_id__add(&obj->sets, id, true);
> + if (btf_id)
> + btf_id->kind = kind;
> +
> + return btf_id;
> }
>
> static struct btf_id *add_symbol(struct rb_root *root, char *name, size_t size)
> {
> + struct btf_id *btf_id;
> char *id;
>
> id = get_id(name + size);
> @@ -288,7 +301,10 @@ static struct btf_id *add_symbol(struct rb_root *root, char *name, size_t size)
> return NULL;
> }
>
> - return btf_id__add(root, id, false);
> + btf_id = btf_id__add(root, id, false);
> + btf_id->kind = BTF_ID_KIND_SYM;
^^^^

Can add_symbol() dereference a NULL pointer here? The function
btf_id__add() can return NULL on allocation failure (when zalloc fails),
but the new code sets btf_id->kind before checking if btf_id is NULL.

In contrast, add_set() checks for NULL before setting the kind field.
Should add_symbol() do the same?

> +
> + return btf_id;
> }

[ ... ]


---
AI reviewed your patch. Please fix the bug or email reply why it's not a bug.
See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md

CI run summary: https://github.com/kernel-patches/bpf/actions/runs/19689674924