Commit 58e443b7 authored by Jiayuan Chen's avatar Jiayuan Chen Committed by Jakub Kicinski
Browse files

net: fix sock compilation error under CONFIG_PREEMPT_RT



When CONFIG_PREEMPT_RT is enabled, __SPIN_LOCK_UNLOCKED() expands to a
brace-enclosed initializer rather than a compound literal, which cannot
be used in assignment expressions. This causes a build failure:

  net/core/sock.c:3787:29: error: expected expression before '{' token
   3787 |                 tmp.slock = __SPIN_LOCK_UNLOCKED(tmp.slock);

Use declaration-with-initializer instead of assignment, consistent with
how __SPIN_LOCK_UNLOCKED() is used elsewhere in the kernel (e.g.
DEFINE_SPINLOCK).

Fixes: 5151ec54 ("net: use try_cmpxchg() in lock_sock_nested()")
Suggested-by: default avatarEric Dumazet <edumazet@google.com>
Signed-off-by: default avatarJiayuan Chen <jiayuan.chen@shopee.com>
Reviewed-by: default avatarEric Dumazet <edumazet@google.com>
Link: https://patch.msgid.link/20260228111319.79506-1-jiayuan.chen@linux.dev


Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent 1e08faf9
Loading
Loading
Loading
Loading
+8 −5
Original line number Diff line number Diff line
@@ -3782,12 +3782,15 @@ void noinline lock_sock_nested(struct sock *sk, int subclass)
	might_sleep();
#ifdef CONFIG_64BIT
	if (sizeof(struct slock_owned) == sizeof(long)) {
		socket_lock_t tmp, old;
		socket_lock_t tmp = {
			.slock = __SPIN_LOCK_UNLOCKED(tmp.slock),
			.owned = 1,
		};
		socket_lock_t old = {
			.slock = __SPIN_LOCK_UNLOCKED(old.slock),
			.owned = 0,
		};

		tmp.slock = __SPIN_LOCK_UNLOCKED(tmp.slock);
		tmp.owned = 1;
		old.slock = __SPIN_LOCK_UNLOCKED(old.slock);
		old.owned = 0;
		if (likely(try_cmpxchg(&sk->sk_lock.combined,
				       &old.combined, tmp.combined)))
			return;