Skip to content

Commit cf8c1e9

Browse files
JiaweiHawkkuba-moo
authored andcommitted
net: refactor bpf_sk_reuseport_detach()
Refactor sk_user_data dereference using more generic function __rcu_dereference_sk_user_data_with_flags(), which improve its maintainability Suggested-by: Jakub Kicinski <[email protected]> Signed-off-by: Hawkins Jiawei <[email protected]> Reviewed-by: Jakub Sitnicki <[email protected]> Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 2a01337 commit cf8c1e9

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

kernel/bpf/reuseport_array.c

+3-6
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,11 @@ static struct reuseport_array *reuseport_array(struct bpf_map *map)
2121
/* The caller must hold the reuseport_lock */
2222
void bpf_sk_reuseport_detach(struct sock *sk)
2323
{
24-
uintptr_t sk_user_data;
24+
struct sock __rcu **socks;
2525

2626
write_lock_bh(&sk->sk_callback_lock);
27-
sk_user_data = (uintptr_t)sk->sk_user_data;
28-
if (sk_user_data & SK_USER_DATA_BPF) {
29-
struct sock __rcu **socks;
30-
31-
socks = (void *)(sk_user_data & SK_USER_DATA_PTRMASK);
27+
socks = __rcu_dereference_sk_user_data_with_flags(sk, SK_USER_DATA_BPF);
28+
if (socks) {
3229
WRITE_ONCE(sk->sk_user_data, NULL);
3330
/*
3431
* Do not move this NULL assignment outside of

0 commit comments

Comments
 (0)