Skip to content

Commit

Permalink
net: refactor bpf_sk_reuseport_detach()
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
JiaweiHawk authored and kuba-moo committed Aug 11, 2022
1 parent 2a01337 commit cf8c1e9
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions kernel/bpf/reuseport_array.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit cf8c1e9

Please sign in to comment.