Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5627cc8b authored by David Howells's avatar David Howells
Browse files

rxrpc: Provide more refcount helper functions



Provide refcount helper functions for connections so that the code doesn't
touch local or connection usage counts directly.

Also make it such that local and peer put functions can take a NULL
pointer.

Signed-off-by: default avatarDavid Howells <dhowells@redhat.com>
parent 985a5c82
Loading
Loading
Loading
Loading
+2 −5
Original line number Diff line number Diff line
@@ -674,11 +674,8 @@ static int rxrpc_release_sock(struct sock *sk)
	flush_workqueue(rxrpc_workqueue);
	rxrpc_purge_queue(&sk->sk_receive_queue);

	if (rx->local) {
	rxrpc_put_local(rx->local);
	rx->local = NULL;
	}

	key_put(rx->key);
	rx->key = NULL;
	key_put(rx->securities);
+13 −2
Original line number Diff line number Diff line
@@ -597,6 +597,17 @@ static inline bool rxrpc_conn_is_service(const struct rxrpc_connection *conn)
	return conn->proto.in_clientflag;
}

static inline void rxrpc_get_connection(struct rxrpc_connection *conn)
{
	atomic_inc(&conn->usage);
}

static inline
struct rxrpc_connection *rxrpc_get_connection_maybe(struct rxrpc_connection *conn)
{
	return atomic_inc_not_zero(&conn->usage) ? conn : NULL;
}

/*
 * input.c
 */
@@ -645,7 +656,7 @@ struct rxrpc_local *rxrpc_get_local_maybe(struct rxrpc_local *local)

static inline void rxrpc_put_local(struct rxrpc_local *local)
{
	if (atomic_dec_and_test(&local->usage))
	if (local && atomic_dec_and_test(&local->usage))
		__rxrpc_put_local(local);
}

@@ -702,7 +713,7 @@ struct rxrpc_peer *rxrpc_get_peer_maybe(struct rxrpc_peer *peer)
extern void __rxrpc_put_peer(struct rxrpc_peer *peer);
static inline void rxrpc_put_peer(struct rxrpc_peer *peer)
{
	if (atomic_dec_and_test(&peer->usage))
	if (peer && atomic_dec_and_test(&peer->usage))
		__rxrpc_put_peer(peer);
}

+1 −1
Original line number Diff line number Diff line
@@ -141,7 +141,7 @@ static int rxrpc_accept_incoming_call(struct rxrpc_local *local,
			_debug("await conn sec");
			list_add_tail(&call->accept_link, &rx->secureq);
			call->conn->state = RXRPC_CONN_SERVER_CHALLENGING;
			atomic_inc(&call->conn->usage);
			rxrpc_get_connection(call->conn);
			set_bit(RXRPC_CONN_CHALLENGE, &call->conn->events);
			rxrpc_queue_conn(call->conn);
		} else {
+1 −1
Original line number Diff line number Diff line
@@ -515,7 +515,7 @@ struct rxrpc_call *rxrpc_incoming_call(struct rxrpc_sock *rx,
	rb_insert_color(&call->conn_node, &conn->calls);
	conn->channels[call->channel] = call;
	sock_hold(&rx->sk);
	atomic_inc(&conn->usage);
	rxrpc_get_connection(conn);
	write_unlock_bh(&conn->lock);

	spin_lock(&conn->params.peer->lock);
+1 −1
Original line number Diff line number Diff line
@@ -263,7 +263,7 @@ void rxrpc_process_connection(struct work_struct *work)

	_enter("{%d}", conn->debug_id);

	atomic_inc(&conn->usage);
	rxrpc_get_connection(conn);

	if (test_and_clear_bit(RXRPC_CONN_CHALLENGE, &conn->events)) {
		rxrpc_secure_connection(conn);
Loading