From: Yajun Deng <yajun.deng@linux.dev>
To: davem@davemloft.net, kuba@kernel.org
Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
Yajun Deng <yajun.deng@linux.dev>
Subject: [PATCH net-next] net: sock: add the case if sk is NULL
Date: Fri, 6 Aug 2021 14:38:15 +0800 [thread overview]
Message-ID: <20210806063815.21541-1-yajun.deng@linux.dev> (raw)
Add the case if sk is NULL in sock_{put, hold},
The caller is free to use it.
Signed-off-by: Yajun Deng <yajun.deng@linux.dev>
---
include/net/sock.h | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/include/net/sock.h b/include/net/sock.h
index 6e761451c927..8821ec0d4147 100644
--- a/include/net/sock.h
+++ b/include/net/sock.h
@@ -699,7 +699,8 @@ static inline bool __sk_del_node_init(struct sock *sk)
static __always_inline void sock_hold(struct sock *sk)
{
- refcount_inc(&sk->sk_refcnt);
+ if (sk)
+ refcount_inc(&sk->sk_refcnt);
}
/* Ungrab socket in the context, which assumes that socket refcnt
@@ -1811,7 +1812,7 @@ void sock_init_data(struct socket *sock, struct sock *sk);
/* Ungrab socket and destroy it, if it was the last reference. */
static inline void sock_put(struct sock *sk)
{
- if (refcount_dec_and_test(&sk->sk_refcnt))
+ if (sk && refcount_dec_and_test(&sk->sk_refcnt))
sk_free(sk);
}
/* Generic version of sock_put(), dealing with all sockets
--
2.32.0
next reply other threads:[~2021-08-06 6:38 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-08-06 6:38 Yajun Deng [this message]
2021-08-06 13:11 ` [PATCH net-next] net: sock: add the case if sk is NULL Jakub Kicinski
2021-08-09 6:12 ` yajun.deng
2021-08-09 9:34 ` Eric Dumazet
2021-08-09 10:28 ` Leon Romanovsky
2021-08-09 9:15 ` Eric Dumazet
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210806063815.21541-1-yajun.deng@linux.dev \
--to=yajun.deng@linux.dev \
--cc=davem@davemloft.net \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).