Skip to content

Commit 5627cc8

Browse files
committed
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: David Howells <[email protected]>
1 parent 985a5c8 commit 5627cc8

File tree

8 files changed

+26
-18
lines changed

8 files changed

+26
-18
lines changed

net/rxrpc/af_rxrpc.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -674,11 +674,8 @@ static int rxrpc_release_sock(struct sock *sk)
674674
flush_workqueue(rxrpc_workqueue);
675675
rxrpc_purge_queue(&sk->sk_receive_queue);
676676

677-
if (rx->local) {
678-
rxrpc_put_local(rx->local);
679-
rx->local = NULL;
680-
}
681-
677+
rxrpc_put_local(rx->local);
678+
rx->local = NULL;
682679
key_put(rx->key);
683680
rx->key = NULL;
684681
key_put(rx->securities);

net/rxrpc/ar-internal.h

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -597,6 +597,17 @@ static inline bool rxrpc_conn_is_service(const struct rxrpc_connection *conn)
597597
return conn->proto.in_clientflag;
598598
}
599599

600+
static inline void rxrpc_get_connection(struct rxrpc_connection *conn)
601+
{
602+
atomic_inc(&conn->usage);
603+
}
604+
605+
static inline
606+
struct rxrpc_connection *rxrpc_get_connection_maybe(struct rxrpc_connection *conn)
607+
{
608+
return atomic_inc_not_zero(&conn->usage) ? conn : NULL;
609+
}
610+
600611
/*
601612
* input.c
602613
*/
@@ -645,7 +656,7 @@ struct rxrpc_local *rxrpc_get_local_maybe(struct rxrpc_local *local)
645656

646657
static inline void rxrpc_put_local(struct rxrpc_local *local)
647658
{
648-
if (atomic_dec_and_test(&local->usage))
659+
if (local && atomic_dec_and_test(&local->usage))
649660
__rxrpc_put_local(local);
650661
}
651662

@@ -702,7 +713,7 @@ struct rxrpc_peer *rxrpc_get_peer_maybe(struct rxrpc_peer *peer)
702713
extern void __rxrpc_put_peer(struct rxrpc_peer *peer);
703714
static inline void rxrpc_put_peer(struct rxrpc_peer *peer)
704715
{
705-
if (atomic_dec_and_test(&peer->usage))
716+
if (peer && atomic_dec_and_test(&peer->usage))
706717
__rxrpc_put_peer(peer);
707718
}
708719

net/rxrpc/call_accept.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ static int rxrpc_accept_incoming_call(struct rxrpc_local *local,
141141
_debug("await conn sec");
142142
list_add_tail(&call->accept_link, &rx->secureq);
143143
call->conn->state = RXRPC_CONN_SERVER_CHALLENGING;
144-
atomic_inc(&call->conn->usage);
144+
rxrpc_get_connection(call->conn);
145145
set_bit(RXRPC_CONN_CHALLENGE, &call->conn->events);
146146
rxrpc_queue_conn(call->conn);
147147
} else {

net/rxrpc/call_object.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,7 @@ struct rxrpc_call *rxrpc_incoming_call(struct rxrpc_sock *rx,
515515
rb_insert_color(&call->conn_node, &conn->calls);
516516
conn->channels[call->channel] = call;
517517
sock_hold(&rx->sk);
518-
atomic_inc(&conn->usage);
518+
rxrpc_get_connection(conn);
519519
write_unlock_bh(&conn->lock);
520520

521521
spin_lock(&conn->params.peer->lock);

net/rxrpc/conn_event.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ void rxrpc_process_connection(struct work_struct *work)
263263

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

266-
atomic_inc(&conn->usage);
266+
rxrpc_get_connection(conn);
267267

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

net/rxrpc/conn_object.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ static int rxrpc_connect_exclusive(struct rxrpc_sock *rx,
333333
* channel.
334334
*/
335335
chan = 0;
336-
atomic_inc(&conn->usage);
336+
rxrpc_get_connection(conn);
337337
conn->avail_calls = RXRPC_MAXCALLS - 1;
338338
conn->channels[chan] = call;
339339
conn->call_counter = 1;
@@ -392,7 +392,7 @@ int rxrpc_connect_call(struct rxrpc_sock *rx,
392392
conn->channels[1] == NULL ||
393393
conn->channels[2] == NULL ||
394394
conn->channels[3] == NULL);
395-
atomic_inc(&conn->usage);
395+
rxrpc_get_connection(conn);
396396
break;
397397
}
398398

@@ -412,7 +412,7 @@ int rxrpc_connect_call(struct rxrpc_sock *rx,
412412
conn->channels[1] == NULL &&
413413
conn->channels[2] == NULL &&
414414
conn->channels[3] == NULL);
415-
atomic_inc(&conn->usage);
415+
rxrpc_get_connection(conn);
416416
list_move(&conn->bundle_link, &bundle->avail_conns);
417417
break;
418418
}
@@ -629,7 +629,7 @@ rxrpc_incoming_connection(struct rxrpc_transport *trans, struct sk_buff *skb)
629629
read_unlock_bh(&trans->conn_lock);
630630
goto security_mismatch;
631631
}
632-
atomic_inc(&conn->usage);
632+
rxrpc_get_connection(conn);
633633
read_unlock_bh(&trans->conn_lock);
634634
goto success;
635635

@@ -639,7 +639,7 @@ rxrpc_incoming_connection(struct rxrpc_transport *trans, struct sk_buff *skb)
639639
write_unlock_bh(&trans->conn_lock);
640640
goto security_mismatch;
641641
}
642-
atomic_inc(&conn->usage);
642+
rxrpc_get_connection(conn);
643643
write_unlock_bh(&trans->conn_lock);
644644
kfree(candidate);
645645
goto success;
@@ -698,7 +698,7 @@ struct rxrpc_connection *rxrpc_find_connection(struct rxrpc_transport *trans,
698698
return NULL;
699699

700700
found:
701-
atomic_inc(&conn->usage);
701+
rxrpc_get_connection(conn);
702702
read_unlock_bh(&trans->conn_lock);
703703
_leave(" = %p", conn);
704704
return conn;

net/rxrpc/input.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -580,7 +580,7 @@ static void rxrpc_post_packet_to_conn(struct rxrpc_connection *conn,
580580
{
581581
_enter("%p,%p", conn, skb);
582582

583-
atomic_inc(&conn->usage);
583+
rxrpc_get_connection(conn);
584584
skb_queue_tail(&conn->rx_queue, skb);
585585
rxrpc_queue_conn(conn);
586586
}

net/rxrpc/local_object.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ struct rxrpc_local *rxrpc_lookup_local(const struct sockaddr_rxrpc *srx)
209209
* bind the transport socket may still fail if we're attempting
210210
* to use a local address that the dying object is still using.
211211
*/
212-
if (!atomic_inc_not_zero(&local->usage)) {
212+
if (!rxrpc_get_local_maybe(local)) {
213213
cursor = cursor->next;
214214
list_del_init(&local->link);
215215
break;

0 commit comments

Comments
 (0)