On 12/8/23 4:26 PM, thinker.li@xxxxxxxxx wrote:
+const struct bpf_struct_ops_desc *btf_get_struct_ops(struct btf *btf, u32 *ret_cnt)
+{
+ if (!btf)
+ return NULL;
+ if (!btf->struct_ops_tab)
*ret_cnt = 0;
unless the later patch checks the return value NULL before using *ret_cnt.
Anyway, better to set *ret_cnt to 0 if the btf has no struct_ops.
The same should go for the "!btf" case above but I suspect the above !btf check
is unnecessary also and the caller should have checked for !btf itself instead
of expecting a list of struct_ops from a NULL btf. Lets continue the review on
the later patches for now to confirm where the above !btf case might happen.
+ return NULL;
+
+ *ret_cnt = btf->struct_ops_tab->cnt;
+ return (const struct bpf_struct_ops_desc *)btf->struct_ops_tab->ops;
+}