From: Eric Dumazet Date: Tue, 15 Nov 2022 09:11:01 +0000 (+0000) Subject: net: __sock_gen_cookie() cleanup X-Git-Tag: v6.6.7~3913^2~205^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=4ebf802cf1c6a87fd14e7936728c99e18d7ba794;p=platform%2Fkernel%2Flinux-starfive.git net: __sock_gen_cookie() cleanup Adopt atomic64_try_cmpxchg() and remove the loop, to make the intent more obvious. Signed-off-by: Eric Dumazet Signed-off-by: David S. Miller --- diff --git a/net/core/sock_diag.c b/net/core/sock_diag.c index f7cf74c..b11593c 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)