/* We have to be careful about racing with the incoming path. sock_orphan() sets SOCK_DEAD and we use that as an indicator to the rx path that new messages shouldn't be queued.  */
static int rds_release(struct socket *sock)
/* We have to be careful about racing with the incoming path. sock_orphan() sets SOCK_DEAD and we use that as an indicator to the rx path that new messages shouldn't be queued.  */
static int rds_release(struct socket *sock)
{
	struct sock *sk = sock->sk;
	struct rds_sock *rs;
	unsigned long flags;
	if (sk == NULL)
		goto out;
	rs = rds_sk_to_rs(sk);
	sock_orphan(sk);
	rds_clear_recv_queue(rs);
	rds_cong_remove_socket(rs);
	rds_remove_bound(rs);
	rds_send_drop_to(rs, NULL);
	rds_rdma_drop_keys(rs);
	rds_notify_queue_get(rs, NULL);
	spin_lock_irqsave(&rds_sock_lock, flags);
	list_del_init(&rs->rs_item);
	rds_sock_count--;
	spin_unlock_irqrestore(&rds_sock_lock, flags);
	sock->sk = NULL;
	sock_put(sk);
out:
	return 0;
}