Factoring bpf_trampoline_put function and adding new __bpf_trampoline_put function without locking trampoline_mutex. It will be needed in following changes. Signed-off-by: Jiri Olsa <jolsa@xxxxxxxxxx> --- kernel/bpf/trampoline.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/kernel/bpf/trampoline.c b/kernel/bpf/trampoline.c index 15801f6c5071..b6b57aa09364 100644 --- a/kernel/bpf/trampoline.c +++ b/kernel/bpf/trampoline.c @@ -928,22 +928,19 @@ struct bpf_trampoline *bpf_trampoline_get(u64 key, return tr; } -void bpf_trampoline_put(struct bpf_trampoline *tr) +static void __bpf_trampoline_put(struct bpf_trampoline *tr) { int i; - if (!tr) - return; - mutex_lock(&trampoline_mutex); if (!refcount_dec_and_test(&tr->refcnt)) - goto out; + return; WARN_ON_ONCE(mutex_is_locked(&tr->mutex)); for (i = 0; i < BPF_TRAMP_MAX; i++) { if (!tr->progs_array[i]) continue; if (WARN_ON_ONCE(!bpf_prog_array_is_empty(tr->progs_array[i]))) - goto out; + return; } /* This code will be executed even when the last bpf_tramp_image @@ -958,7 +955,14 @@ void bpf_trampoline_put(struct bpf_trampoline *tr) kfree(tr->fops); } kfree(tr); -out: +} + +void bpf_trampoline_put(struct bpf_trampoline *tr) +{ + if (!tr) + return; + mutex_lock(&trampoline_mutex); + __bpf_trampoline_put(tr); mutex_unlock(&trampoline_mutex); } -- 2.37.1