Coverity: __sock_gen_cookie(): Error handling issues

From: coverity-bot
Date: Thu Nov 17 2022 - 17:24:35 EST


Hello!

This is an experimental semi-automated report about issues detected by
Coverity from a scan of next-20221117 as part of the linux-next scan project:
https://scan.coverity.com/projects/linux-next-weekly-scan

You're getting this email because you were associated with the identified
lines of code (noted below) that were touched by commits:

Wed Nov 16 12:42:01 2022 +0000
4ebf802cf1c6 ("net: __sock_gen_cookie() cleanup")

Coverity reported the following:

*** CID 1527347: Error handling issues (CHECKED_RETURN)
net/core/sock_diag.c:33 in __sock_gen_cookie()
27 {
28 u64 res = atomic64_read(&sk->sk_cookie);
29
30 if (!res) {
31 u64 new = gen_cookie_next(&sock_cookie);
32
vvv CID 1527347: Error handling issues (CHECKED_RETURN)
vvv Calling "atomic64_try_cmpxchg" without checking return value (as is done elsewhere 8 out of 9 times).
33 atomic64_try_cmpxchg(&sk->sk_cookie, &res, new);
34 }
35 return res;
36 }
37
38 int sock_diag_check_cookie(struct sock *sk, const __u32 *cookie)

If this is a false positive, please let us know so we can mark it as
such, or teach the Coverity rules to be smarter. If not, please make
sure fixes get into linux-next. :) For patches fixing this, please
include these lines (but double-check the "Fixes" first):

Reported-by: coverity-bot <keescook+coverity-bot@xxxxxxxxxxxx>
Addresses-Coverity-ID: 1527347 ("Error handling issues")
Fixes: 4ebf802cf1c6 ("net: __sock_gen_cookie() cleanup")

Thanks for your attention!

--
Coverity-bot