@@ -5568,13 +5568,21 @@ int btf_check_type_match(struct bpf_verifier_log *log, const struct bpf_prog *pr
5568
5568
return btf_check_func_type_match (log , btf1 , t1 , btf2 , t2 );
5569
5569
}
5570
5570
5571
- static u32 * reg2btf_ids [__BPF_REG_TYPE_MAX ] = {
5571
+ static u32 * reg2btf_ids (enum bpf_reg_type type )
5572
+ {
5573
+ switch (type ) {
5572
5574
#ifdef CONFIG_NET
5573
- [PTR_TO_SOCKET ] = & btf_sock_ids [BTF_SOCK_TYPE_SOCK ],
5574
- [PTR_TO_SOCK_COMMON ] = & btf_sock_ids [BTF_SOCK_TYPE_SOCK_COMMON ],
5575
- [PTR_TO_TCP_SOCK ] = & btf_sock_ids [BTF_SOCK_TYPE_TCP ],
5575
+ case PTR_TO_SOCKET :
5576
+ return & btf_sock_ids [BTF_SOCK_TYPE_SOCK ];
5577
+ case PTR_TO_SOCK_COMMON :
5578
+ return & btf_sock_ids [BTF_SOCK_TYPE_SOCK_COMMON ];
5579
+ case PTR_TO_TCP_SOCK :
5580
+ return & btf_sock_ids [BTF_SOCK_TYPE_TCP ];
5576
5581
#endif
5577
- };
5582
+ default :
5583
+ return NULL ;
5584
+ }
5585
+ }
5578
5586
5579
5587
/* Returns true if struct is composed of scalars, 4 levels of nesting allowed */
5580
5588
static bool __btf_type_is_scalar_struct (struct bpf_verifier_log * log ,
@@ -5688,7 +5696,7 @@ static int btf_check_func_arg_match(struct bpf_verifier_env *env,
5688
5696
}
5689
5697
if (check_ptr_off_reg (env , reg , regno ))
5690
5698
return - EINVAL ;
5691
- } else if (is_kfunc && (reg -> type == PTR_TO_BTF_ID || reg2btf_ids [ reg -> type ] )) {
5699
+ } else if (is_kfunc && (reg -> type == PTR_TO_BTF_ID || reg2btf_ids ( reg -> type ) )) {
5692
5700
const struct btf_type * reg_ref_t ;
5693
5701
const struct btf * reg_btf ;
5694
5702
const char * reg_ref_tname ;
@@ -5706,7 +5714,7 @@ static int btf_check_func_arg_match(struct bpf_verifier_env *env,
5706
5714
reg_ref_id = reg -> btf_id ;
5707
5715
} else {
5708
5716
reg_btf = btf_vmlinux ;
5709
- reg_ref_id = * reg2btf_ids [ reg -> type ] ;
5717
+ reg_ref_id = * reg2btf_ids ( reg -> type ) ;
5710
5718
}
5711
5719
5712
5720
reg_ref_t = btf_type_skip_modifiers (reg_btf , reg_ref_id ,
0 commit comments