@@ -330,35 +330,34 @@ static void cache_btf_id(struct bpf_iter_target_info *tinfo,
330330bool bpf_iter_prog_supported (struct bpf_prog * prog )
331331{
332332 const char * attach_fname = prog -> aux -> attach_func_name ;
333+ struct bpf_iter_target_info * tinfo = NULL , * iter ;
333334 u32 prog_btf_id = prog -> aux -> attach_btf_id ;
334335 const char * prefix = BPF_ITER_FUNC_PREFIX ;
335- struct bpf_iter_target_info * tinfo ;
336336 int prefix_len = strlen (prefix );
337- bool supported = false;
338337
339338 if (strncmp (attach_fname , prefix , prefix_len ))
340339 return false;
341340
342341 mutex_lock (& targets_mutex );
343- list_for_each_entry (tinfo , & targets , list ) {
344- if (tinfo -> btf_id && tinfo -> btf_id == prog_btf_id ) {
345- supported = true ;
342+ list_for_each_entry (iter , & targets , list ) {
343+ if (iter -> btf_id && iter -> btf_id == prog_btf_id ) {
344+ tinfo = iter ;
346345 break ;
347346 }
348- if (!strcmp (attach_fname + prefix_len , tinfo -> reg_info -> target )) {
349- cache_btf_id (tinfo , prog );
350- supported = true ;
347+ if (!strcmp (attach_fname + prefix_len , iter -> reg_info -> target )) {
348+ cache_btf_id (iter , prog );
349+ tinfo = iter ;
351350 break ;
352351 }
353352 }
354353 mutex_unlock (& targets_mutex );
355354
356- if (supported ) {
355+ if (tinfo ) {
357356 prog -> aux -> ctx_arg_info_size = tinfo -> reg_info -> ctx_arg_info_size ;
358357 prog -> aux -> ctx_arg_info = tinfo -> reg_info -> ctx_arg_info ;
359358 }
360359
361- return supported ;
360+ return tinfo != NULL ;
362361}
363362
364363const struct bpf_func_proto *
@@ -499,12 +498,11 @@ bool bpf_link_is_iter(struct bpf_link *link)
499498int bpf_iter_link_attach (const union bpf_attr * attr , bpfptr_t uattr ,
500499 struct bpf_prog * prog )
501500{
501+ struct bpf_iter_target_info * tinfo = NULL , * iter ;
502502 struct bpf_link_primer link_primer ;
503- struct bpf_iter_target_info * tinfo ;
504503 union bpf_iter_link_info linfo ;
505504 struct bpf_iter_link * link ;
506505 u32 prog_btf_id , linfo_len ;
507- bool existed = false;
508506 bpfptr_t ulinfo ;
509507 int err ;
510508
@@ -530,14 +528,14 @@ int bpf_iter_link_attach(const union bpf_attr *attr, bpfptr_t uattr,
530528
531529 prog_btf_id = prog -> aux -> attach_btf_id ;
532530 mutex_lock (& targets_mutex );
533- list_for_each_entry (tinfo , & targets , list ) {
534- if (tinfo -> btf_id == prog_btf_id ) {
535- existed = true ;
531+ list_for_each_entry (iter , & targets , list ) {
532+ if (iter -> btf_id == prog_btf_id ) {
533+ tinfo = iter ;
536534 break ;
537535 }
538536 }
539537 mutex_unlock (& targets_mutex );
540- if (!existed )
538+ if (!tinfo )
541539 return - ENOENT ;
542540
543541 link = kzalloc (sizeof (* link ), GFP_USER | __GFP_NOWARN );
0 commit comments