@@ -140,17 +140,22 @@ void inet_sock_destruct(struct sock *sk)
sk_mem_reclaim(sk);
- if (sk->sk_type == SOCK_STREAM && sk->sk_state != TCP_CLOSE) {
- pr_err("Attempt to release TCP socket in state %d %p\n",
- sk->sk_state, sk);
- return;
- }
if (!sock_flag(sk, SOCK_DEAD)) {
pr_err("Attempt to release alive inet socket %p\n", sk);
return;
}
- if (sk->sk_protocol == IPPROTO_TCP)
- kfree(inet_csk(sk)->icsk_accept_queue.fastopenq);
+ if (sk->sk_type == SOCK_STREAM) {
+ if (sk->sk_state != TCP_CLOSE) {
+ pr_err("Attempt to release TCP socket in state %d %p\n",
+ sk->sk_state, sk);
+ return;
+ }
+ /* Only TCP sockets (either v4 or v6) may have a valid
+ * icsk_accept_queue.fastopenq that must be freed.
+ */
+ if (sk->sk_protocol == IPPROTO_TCP)
+ kfree(inet_csk(sk)->icsk_accept_queue.fastopenq);
+ }
WARN_ON(atomic_read(&sk->sk_rmem_alloc));
WARN_ON(atomic_read(&sk->sk_wmem_alloc));
@@ -216,10 +221,11 @@ int inet_listen(struct socket *sock, int backlog)
if (old_state != TCP_LISTEN) {
/* Check special setups for testing purpose to enable TFO w/o
* requiring TCP_FASTOPEN sockopt.
- * Note that only TCP sockets (SOCK_STREAM) will reach here.
- * Also fastopenq may already been allocated because this
- * socket was in TCP_LISTEN state previously but was
- * shutdown() (rather than close()).
+ *
+ * Note that only TCP sockets will reach here. Also fastopenq
+ * may already been allocated because this socket was in
+ * TCP_LISTEN state previously but was shutdown() (rather
+ * than close()).
*/
if ((sysctl_tcp_fastopen & TFO_SERVER_ENABLE) != 0 &&
inet_csk(sk)->icsk_accept_queue.fastopenq == NULL) {