diff options
author | Eric Dumazet <edumazet@google.com> | 2022-11-15 12:11:01 +0300 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2022-11-16 15:42:01 +0300 |
commit | 4ebf802cf1c6a87fd14e7936728c99e18d7ba794 (patch) | |
tree | 0c745a13b644805bdb6f08f99251d486f1800911 /net/core/sock_diag.c | |
parent | 4ffa1d1c6842a97e84cfbe56bfcf70edb23608e2 (diff) | |
download | linux-4ebf802cf1c6a87fd14e7936728c99e18d7ba794.tar.xz |
net: __sock_gen_cookie() cleanup
Adopt atomic64_try_cmpxchg() and remove the loop,
to make the intent more obvious.
Signed-off-by: Eric Dumazet <edumazet@google.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/core/sock_diag.c')
-rw-r--r-- | net/core/sock_diag.c | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/net/core/sock_diag.c b/net/core/sock_diag.c index f7cf74cdd3db..b11593cae5a0 100644 --- a/net/core/sock_diag.c +++ b/net/core/sock_diag.c @@ -25,14 +25,14 @@ DEFINE_COOKIE(sock_cookie); u64 __sock_gen_cookie(struct sock *sk) { - while (1) { - u64 res = atomic64_read(&sk->sk_cookie); + u64 res = atomic64_read(&sk->sk_cookie); - if (res) - return res; - res = gen_cookie_next(&sock_cookie); - atomic64_cmpxchg(&sk->sk_cookie, 0, res); + if (!res) { + u64 new = gen_cookie_next(&sock_cookie); + + atomic64_try_cmpxchg(&sk->sk_cookie, &res, new); } + return res; } int sock_diag_check_cookie(struct sock *sk, const __u32 *cookie) |