]> git.baikalelectronics.ru Git - kernel.git/commitdiff
net: refactor bpf_sk_reuseport_detach()
authorHawkins Jiawei <yin31149@gmail.com>
Fri, 5 Aug 2022 07:48:36 +0000 (15:48 +0800)
committerJakub Kicinski <kuba@kernel.org>
Thu, 11 Aug 2022 04:48:04 +0000 (21:48 -0700)
Refactor sk_user_data dereference using more generic function
__rcu_dereference_sk_user_data_with_flags(), which improve its
maintainability

Suggested-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Hawkins Jiawei <yin31149@gmail.com>
Reviewed-by: Jakub Sitnicki <jakub@cloudflare.com>
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
kernel/bpf/reuseport_array.c

index e2618fb5870e758ca7c9787882ce9b11c823f730..85fa9dbfa8bf88be026494b1a663912b968b1c26 100644 (file)
@@ -21,14 +21,11 @@ static struct reuseport_array *reuseport_array(struct bpf_map *map)
 /* The caller must hold the reuseport_lock */
 void bpf_sk_reuseport_detach(struct sock *sk)
 {
-       uintptr_t sk_user_data;
+       struct sock __rcu **socks;
 
        write_lock_bh(&sk->sk_callback_lock);
-       sk_user_data = (uintptr_t)sk->sk_user_data;
-       if (sk_user_data & SK_USER_DATA_BPF) {
-               struct sock __rcu **socks;
-
-               socks = (void *)(sk_user_data & SK_USER_DATA_PTRMASK);
+       socks = __rcu_dereference_sk_user_data_with_flags(sk, SK_USER_DATA_BPF);
+       if (socks) {
                WRITE_ONCE(sk->sk_user_data, NULL);
                /*
                 * Do not move this NULL assignment outside of