On Thu, Dec 12, 2024 at 02:24:46PM -0800, Andrii Nakryiko wrote: > On Mon, Dec 9, 2024 at 8:04 PM D. Wythe <alibuda@xxxxxxxxxxxxxxxxx> wrote: > > > > When a struct_ops named xxx_ops was registered by a module, and > > it will be used in both built-in modules and the module itself, > > so that the btf_type of xxx_ops will be present in btf_vmlinux > > instead of using find_btf_by_prefix_kind, let's have: > > 1) snprintf(STRUCT_OPS_VALUE_PREFIX, tname) right here in this > function, so we have expected type constructed and ready to be used > and reused, if necessary > 2) call btf__find_by_name_kind() instead of find_btf_by_prefix_kind() > 3) if (kern_vtype_id < 0 && !*mod_btf) > kern_vtype_id = find_ksym_btf_id(...) > 4) if (kern_vtype_id < 0) /* now emit error and error out */ Got it. This looks more concise, I will modify it in the next version in this way. Thanks, D. Wythe > > > if (kern_vtype_id < 0) { > > - pr_warn("struct_ops init_kern: struct %s%s is not found in kernel BTF\n", > > - STRUCT_OPS_VALUE_PREFIX, tname); > > - return kern_vtype_id; > > + if (kern_vtype_id == -ENOENT && !*mod_btf) > > + kern_vtype_id = > > + find_ksym_btf_id_by_prefix_kind(obj, STRUCT_OPS_VALUE_PREFIX, > > + tname, BTF_KIND_STRUCT, &btf, > > + mod_btf); > > + if (kern_vtype_id < 0) { > > + pr_warn("struct_ops init_kern: struct %s%s is not found in kernel BTF\n", > > + STRUCT_OPS_VALUE_PREFIX, tname); > > + return kern_vtype_id; > > + } > > } > > kern_vtype = btf__type_by_id(btf, kern_vtype_id); > > > > -- > > 2.45.0 > >