]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
rxrpc: Provide more refcount helper functions
authorDavid Howells <dhowells@redhat.com>
Mon, 4 Apr 2016 13:00:38 +0000 (14:00 +0100)
committerDavid Howells <dhowells@redhat.com>
Wed, 22 Jun 2016 08:17:51 +0000 (09:17 +0100)
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: David Howells <dhowells@redhat.com>
net/rxrpc/af_rxrpc.c
net/rxrpc/ar-internal.h
net/rxrpc/call_accept.c
net/rxrpc/call_object.c
net/rxrpc/conn_event.c
net/rxrpc/conn_object.c
net/rxrpc/input.c
net/rxrpc/local_object.c

index b29bb50af5de8ff2d08cf4063c5828987a471ef2..57dcbfc061e4749b14e8a35c506543fa97aa0638 100644 (file)
@@ -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;
-       }
-
+       rxrpc_put_local(rx->local);
+       rx->local = NULL;
        key_put(rx->key);
        rx->key = NULL;
        key_put(rx->securities);
index cfbd028aa551e80f82fd5006b105ff32b9541fc1..c0ed5e7f22ef592806ac63e7080d91ff26aa9bda 100644 (file)
@@ -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);
 }
 
index 5a70dc4e28c6f17c78ba3d11ca1e821d9e933c39..833ad0622b61336449aa618ca425bd698f47b939 100644 (file)
@@ -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 {
index d83f2cbb80a94b586e201829036e60bc74a05043..45849a66bc56ad503cd8dcb84fa9beb3c0002272 100644 (file)
@@ -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);
index a022439f6f5a37425b428ca44126563ac3a7f2a4..bf6971555eaceced982850a50148e609a976f3aa 100644 (file)
@@ -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);
index 312b75091d29bc3b114725685b377dfab6d739a8..1754f2e2e16bf103f2dbaf12caee02869f64a224 100644 (file)
@@ -333,7 +333,7 @@ static int rxrpc_connect_exclusive(struct rxrpc_sock *rx,
         * channel.
         */
        chan = 0;
-       atomic_inc(&conn->usage);
+       rxrpc_get_connection(conn);
        conn->avail_calls = RXRPC_MAXCALLS - 1;
        conn->channels[chan] = call;
        conn->call_counter = 1;
@@ -392,7 +392,7 @@ int rxrpc_connect_call(struct rxrpc_sock *rx,
                               conn->channels[1] == NULL ||
                               conn->channels[2] == NULL ||
                               conn->channels[3] == NULL);
-                       atomic_inc(&conn->usage);
+                       rxrpc_get_connection(conn);
                        break;
                }
 
@@ -412,7 +412,7 @@ int rxrpc_connect_call(struct rxrpc_sock *rx,
                               conn->channels[1] == NULL &&
                               conn->channels[2] == NULL &&
                               conn->channels[3] == NULL);
-                       atomic_inc(&conn->usage);
+                       rxrpc_get_connection(conn);
                        list_move(&conn->bundle_link, &bundle->avail_conns);
                        break;
                }
@@ -629,7 +629,7 @@ rxrpc_incoming_connection(struct rxrpc_transport *trans, struct sk_buff *skb)
                read_unlock_bh(&trans->conn_lock);
                goto security_mismatch;
        }
-       atomic_inc(&conn->usage);
+       rxrpc_get_connection(conn);
        read_unlock_bh(&trans->conn_lock);
        goto success;
 
@@ -639,7 +639,7 @@ rxrpc_incoming_connection(struct rxrpc_transport *trans, struct sk_buff *skb)
                write_unlock_bh(&trans->conn_lock);
                goto security_mismatch;
        }
-       atomic_inc(&conn->usage);
+       rxrpc_get_connection(conn);
        write_unlock_bh(&trans->conn_lock);
        kfree(candidate);
        goto success;
@@ -698,7 +698,7 @@ struct rxrpc_connection *rxrpc_find_connection(struct rxrpc_transport *trans,
        return NULL;
 
 found:
-       atomic_inc(&conn->usage);
+       rxrpc_get_connection(conn);
        read_unlock_bh(&trans->conn_lock);
        _leave(" = %p", conn);
        return conn;
index cf540efa9c174cb39a8c33f3ce362754981b8a16..799aec18aa7b26a114d6f36df6550c6636068bd0 100644 (file)
@@ -580,7 +580,7 @@ static void rxrpc_post_packet_to_conn(struct rxrpc_connection *conn,
 {
        _enter("%p,%p", conn, skb);
 
-       atomic_inc(&conn->usage);
+       rxrpc_get_connection(conn);
        skb_queue_tail(&conn->rx_queue, skb);
        rxrpc_queue_conn(conn);
 }
index 009b321712bc7ea98b11858f215cc41e0634d424..5703b0d18ed4095b9533a63224119cd5ae2cb07e 100644 (file)
@@ -209,7 +209,7 @@ struct rxrpc_local *rxrpc_lookup_local(const struct sockaddr_rxrpc *srx)
                 * bind the transport socket may still fail if we're attempting
                 * to use a local address that the dying object is still using.
                 */
-               if (!atomic_inc_not_zero(&local->usage)) {
+               if (!rxrpc_get_local_maybe(local)) {
                        cursor = cursor->next;
                        list_del_init(&local->link);
                        break;