@@ -215,6 +215,16 @@ static bool htab_has_extra_elems(struct bpf_htab *htab)
215215 return !htab_is_percpu (htab ) && !htab_is_lru (htab ) && !is_fd_htab (htab );
216216}
217217
218+ static void htab_free_internal_structs (struct bpf_htab * htab , struct htab_elem * elem )
219+ {
220+ if (btf_record_has_field (htab -> map .record , BPF_TIMER ))
221+ bpf_obj_free_timer (htab -> map .record ,
222+ htab_elem_value (elem , htab -> map .key_size ));
223+ if (btf_record_has_field (htab -> map .record , BPF_WORKQUEUE ))
224+ bpf_obj_free_workqueue (htab -> map .record ,
225+ htab_elem_value (elem , htab -> map .key_size ));
226+ }
227+
218228static void htab_free_prealloced_timers_and_wq (struct bpf_htab * htab )
219229{
220230 u32 num_entries = htab -> map .max_entries ;
@@ -227,12 +237,7 @@ static void htab_free_prealloced_timers_and_wq(struct bpf_htab *htab)
227237 struct htab_elem * elem ;
228238
229239 elem = get_htab_elem (htab , i );
230- if (btf_record_has_field (htab -> map .record , BPF_TIMER ))
231- bpf_obj_free_timer (htab -> map .record ,
232- htab_elem_value (elem , htab -> map .key_size ));
233- if (btf_record_has_field (htab -> map .record , BPF_WORKQUEUE ))
234- bpf_obj_free_workqueue (htab -> map .record ,
235- htab_elem_value (elem , htab -> map .key_size ));
240+ htab_free_internal_structs (htab , elem );
236241 cond_resched ();
237242 }
238243}
@@ -1502,12 +1507,7 @@ static void htab_free_malloced_timers_and_wq(struct bpf_htab *htab)
15021507
15031508 hlist_nulls_for_each_entry (l , n , head , hash_node ) {
15041509 /* We only free timer on uref dropping to zero */
1505- if (btf_record_has_field (htab -> map .record , BPF_TIMER ))
1506- bpf_obj_free_timer (htab -> map .record ,
1507- htab_elem_value (l , htab -> map .key_size ));
1508- if (btf_record_has_field (htab -> map .record , BPF_WORKQUEUE ))
1509- bpf_obj_free_workqueue (htab -> map .record ,
1510- htab_elem_value (l , htab -> map .key_size ));
1510+ htab_free_internal_structs (htab , l );
15111511 }
15121512 cond_resched_rcu ();
15131513 }
0 commit comments