Commit b4cb4a13 authored by Eric Dumazet's avatar Eric Dumazet Committed by Paolo Abeni
Browse files

net: use unrcu_pointer() helper



Toke mentioned unrcu_pointer() existence, allowing
to remove some of the ugly casts we have when using
xchg() for rcu protected pointers.

Also make inet_rcv_compat const.

Signed-off-by: default avatarEric Dumazet <edumazet@google.com>
Cc: Toke Høiland-Jørgensen <toke@redhat.com>
Reviewed-by: default avatarToke Høiland-Jørgensen <toke@redhat.com>
Link: https://lore.kernel.org/r/20240604111603.45871-1-edumazet@google.com


Signed-off-by: default avatarPaolo Abeni <pabeni@redhat.com>
parent 59d0f481
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -2095,7 +2095,7 @@ sk_dst_set(struct sock *sk, struct dst_entry *dst)

	sk_tx_queue_clear(sk);
	WRITE_ONCE(sk->sk_dst_pending_confirm, 0);
	old_dst = xchg((__force struct dst_entry **)&sk->sk_dst_cache, dst);
	old_dst = unrcu_pointer(xchg(&sk->sk_dst_cache, RCU_INITIALIZER(dst)));
	dst_release(old_dst);
}

+1 −1
Original line number Diff line number Diff line
@@ -206,7 +206,7 @@ void gen_kill_estimator(struct net_rate_estimator __rcu **rate_est)
{
	struct net_rate_estimator *est;

	est = xchg((__force struct net_rate_estimator **)rate_est, NULL);
	est = unrcu_pointer(xchg(rate_est, NULL));
	if (est) {
		timer_shutdown_sync(&est->timer);
		kfree_rcu(est, rcu);
+3 −5
Original line number Diff line number Diff line
@@ -18,7 +18,7 @@

static const struct sock_diag_handler __rcu *sock_diag_handlers[AF_MAX];

static struct sock_diag_inet_compat __rcu *inet_rcv_compat;
static const struct sock_diag_inet_compat __rcu *inet_rcv_compat;

static struct workqueue_struct *broadcast_wq;

@@ -187,8 +187,7 @@ void sock_diag_broadcast_destroy(struct sock *sk)

void sock_diag_register_inet_compat(const struct sock_diag_inet_compat *ptr)
{
	xchg((__force const struct sock_diag_inet_compat **)&inet_rcv_compat,
	     ptr);
	xchg(&inet_rcv_compat, RCU_INITIALIZER(ptr));
}
EXPORT_SYMBOL_GPL(sock_diag_register_inet_compat);

@@ -196,8 +195,7 @@ void sock_diag_unregister_inet_compat(const struct sock_diag_inet_compat *ptr)
{
	const struct sock_diag_inet_compat *old;

	old = xchg((__force const struct sock_diag_inet_compat **)&inet_rcv_compat,
		   NULL);
	old = unrcu_pointer(xchg(&inet_rcv_compat, NULL));
	WARN_ON_ONCE(old != ptr);
}
EXPORT_SYMBOL_GPL(sock_diag_unregister_inet_compat);
+1 −1
Original line number Diff line number Diff line
@@ -1953,7 +1953,7 @@ int cipso_v4_req_setattr(struct request_sock *req,
	buf = NULL;

	req_inet = inet_rsk(req);
	opt = xchg((__force struct ip_options_rcu **)&req_inet->ireq_opt, opt);
	opt = unrcu_pointer(xchg(&req_inet->ireq_opt, RCU_INITIALIZER(opt)));
	if (opt)
		kfree_rcu(opt, rcu);

+1 −1
Original line number Diff line number Diff line
@@ -3081,7 +3081,7 @@ int tcp_disconnect(struct sock *sk, int flags)
	icsk->icsk_ack.rcv_mss = TCP_MIN_MSS;
	memset(&tp->rx_opt, 0, sizeof(tp->rx_opt));
	__sk_dst_reset(sk);
	dst_release(xchg((__force struct dst_entry **)&sk->sk_rx_dst, NULL));
	dst_release(unrcu_pointer(xchg(&sk->sk_rx_dst, NULL)));
	tcp_saved_syn_free(tp);
	tp->compressed_ack = 0;
	tp->segs_in = 0;
Loading