tracing/probes: Clarify btf_find_struct_member() container parameter and add kernel-doc
Masami Hiramatsu (Google)
maintainerPATCH 1/1 tracing/probes: Clarify btf_find_struct_member() container parameter and add kernel-doc
From: Masami Hiramatsu (Google) <[email protected]>
btf_find_struct_member() returns the containing structure or union type (which can be an inner anonymous struct/union rather than the outer passed type) via its last parameter. However, the parameter was named @member_type, which easily confuses readers and static analyzers into thinking it returns the member field's own datatype.
Rename @member_type to @container_type in the prototype, definition, and callers to make the relationship explicit. Also convert the comment above btf_find_struct_member() to standard kernel-doc format, documenting all parameters and return values.
Assisted-by LLM
Signed-off-by Masami Hiramatsu (Google) <[email protected]>
--- kernel/trace/trace_btf.c | 34 ++++++++++++++++++++++++---------- kernel/trace/trace_btf.h | 2 +- kernel/trace/trace_probe.c | 6 +++--- 3 files changed, 28 insertions(+), 14 deletions(-)
kernel/trace/trace_btf.c +24 -10
@@ -59,19 +59,33 @@ struct btf_anon_stack {u32 offset; }; -/* -* Find a member of data structure/union by name and return it. -* Return NULL if not found, or ERR_PTR(-EINVAL) if parameter is invalid. -* If the member is a member of an anonymous union/structure, the bit offset -* of that anonymous union/structure is stored into @anon_offset. -* If @member_type is non-NULL, the actual containing structure/union type -* of the found member is stored into @member_type. +/** +* btf_find_struct_member() - Find a member of data structure/union by name +* @btf: Pointer to BTF object. +* @type: Pointer to the struct/union BTF type to search within. +* @member_name: Name of the member to find. +* @anon_offset: Pointer to store bit offset of enclosing anonymous union/struct. +* @container_type: Pointer to store the actual containing struct/union type. +* +* Find a member of data structure/union by name, traversing into anonymous +* unions and structures if necessary. +* +* If the member is inside an anonymous union/structure, the bit offset +* of that anonymous union/structure from @type is stored into @anon_offset. +* If @container_type is non-NULL, the actual struct/union BTF type that +* directly contains the found member is stored into @container_type. +* +* Return: +* * Pointer to &struct btf_member on success. +* * %NULL if the member was not found. +* * %ERR_PTR(-EINVAL) if @type is not a struct/union. +* * %ERR_PTR(-ENOMEM) if memory allocation failed. */ const struct btf_member *btf_find_struct_member (struct btf *btf,const struct btf_type *type,const char *member_name,u32 *anon_offset, -const struct btf_type **member_type) +const struct btf_type **container_type) {struct btf_anon_stack *anon_stack;const struct btf_member *member;
@@ -103,8 +117,8 @@ const struct btf_member *btf_find_struct_member(struct btf *btf,if (name && !strcmp (member_name, name)) {if (anon_offset) *anon_offset = cur_offset; -if (member_type) - *member_type = type; +if (container_type) + *container_type = type; goto out; } }
kernel/trace/trace_btf.h +1 -1
@@ -9,4 +9,4 @@ const struct btf_member *btf_find_struct_member(struct btf *btf,const struct btf_type *type, const char *member_name, u32 *anon_offset, - const struct btf_type **member_type); + const struct btf_type **container_type);
kernel/trace/trace_probe.c +3 -3
@@ -625,7 +625,7 @@ static int get_bitoffset_of_field(char **pfieldname, const struct btf_type **pty {const struct btf_type *type = *ptype;const struct btf_member *field; -const struct btf_type *mtype; +const struct btf_type *container_type;struct btf *btf =ctx_btf (ctx);char *fieldname = *pfieldname;int bitoffs =0 ;
@@ -641,7 +641,7 @@ static int get_bitoffset_of_field(char **pfieldname, const struct btf_type **pty anon_offs =0 ; field =btf_find_struct_member (btf, type, fieldname, - &anon_offs, &mtype); + &anon_offs, &container_type);if (IS_ERR (field)) {trace_probe_log_err (ctx->offset,BAD_BTF_TID );return PTR_ERR (field);
@@ -654,7 +654,7 @@ static int get_bitoffset_of_field(char **pfieldname, const struct btf_type **pty bitoffs += anon_offs;/* Accumulate the bit-offsets of the dot-connected fields */ -if (btf_type_kflag (mtype)) { +if (btf_type_kflag (container_type)) { bitoffs +=BTF_MEMBER_BIT_OFFSET (field->offset); ctx->last_bitsize =BTF_MEMBER_BITFIELD_SIZE (field->offset); }else {