* [PATCH net-next v1] net: fix sock compilation error under CONFIG_PREEMPT_RT
@ 2026-02-28 9:06 Jiayuan Chen
2026-02-28 10:43 ` Eric Dumazet
0 siblings, 1 reply; 3+ messages in thread
From: Jiayuan Chen @ 2026-02-28 9:06 UTC (permalink / raw)
To: netdev
Cc: jiayuan.chen, Jiayuan Chen, Eric Dumazet, Kuniyuki Iwashima,
Paolo Abeni, Willem de Bruijn, David S. Miller, Jakub Kicinski,
Simon Horman, Sebastian Andrzej Siewior, Clark Williams,
Steven Rostedt, Jason Xing, linux-kernel, linux-rt-devel
From: Jiayuan Chen <jiayuan.chen@shopee.com>
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: 5151ec54f586 ("net: use try_cmpxchg() in lock_sock_nested()")
Signed-off-by: Jiayuan Chen <jiayuan.chen@shopee.com>
---
net/core/sock.c | 10 ++++------
1 file changed, 4 insertions(+), 6 deletions(-)
diff --git a/net/core/sock.c b/net/core/sock.c
index 9d841975a7a1..2461aba7b18a 100644
--- a/net/core/sock.c
+++ b/net/core/sock.c
@@ -3782,12 +3782,10 @@ 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;
-
- tmp.slock = __SPIN_LOCK_UNLOCKED(tmp.slock);
- tmp.owned = 1;
- old.slock = __SPIN_LOCK_UNLOCKED(old.slock);
- old.owned = 0;
+ socket_lock_t tmp = { .slock = __SPIN_LOCK_UNLOCKED(tmp.slock),
+ .owned = 1 };
+ socket_lock_t old = { .slock = __SPIN_LOCK_UNLOCKED(old.slock),
+ .owned = 0 };
if (likely(try_cmpxchg(&sk->sk_lock.combined,
&old.combined, tmp.combined)))
return;
--
2.43.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH net-next v1] net: fix sock compilation error under CONFIG_PREEMPT_RT
2026-02-28 9:06 [PATCH net-next v1] net: fix sock compilation error under CONFIG_PREEMPT_RT Jiayuan Chen
@ 2026-02-28 10:43 ` Eric Dumazet
2026-02-28 10:48 ` Jiayuan Chen
0 siblings, 1 reply; 3+ messages in thread
From: Eric Dumazet @ 2026-02-28 10:43 UTC (permalink / raw)
To: Jiayuan Chen
Cc: netdev, Jiayuan Chen, Kuniyuki Iwashima, Paolo Abeni,
Willem de Bruijn, David S. Miller, Jakub Kicinski, Simon Horman,
Sebastian Andrzej Siewior, Clark Williams, Steven Rostedt,
Jason Xing, linux-kernel, linux-rt-devel
On Sat, Feb 28, 2026 at 10:07 AM Jiayuan Chen <jiayuan.chen@linux.dev> wrote:
>
> From: Jiayuan Chen <jiayuan.chen@shopee.com>
>
> 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: 5151ec54f586 ("net: use try_cmpxchg() in lock_sock_nested()")
> Signed-off-by: Jiayuan Chen <jiayuan.chen@shopee.com>
> ---
> net/core/sock.c | 10 ++++------
> 1 file changed, 4 insertions(+), 6 deletions(-)
>
> diff --git a/net/core/sock.c b/net/core/sock.c
> index 9d841975a7a1..2461aba7b18a 100644
> --- a/net/core/sock.c
> +++ b/net/core/sock.c
> @@ -3782,12 +3782,10 @@ 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;
> -
> - tmp.slock = __SPIN_LOCK_UNLOCKED(tmp.slock);
> - tmp.owned = 1;
> - old.slock = __SPIN_LOCK_UNLOCKED(old.slock);
> - old.owned = 0;
> + socket_lock_t tmp = { .slock = __SPIN_LOCK_UNLOCKED(tmp.slock),
> + .owned = 1 };
> + socket_lock_t old = { .slock = __SPIN_LOCK_UNLOCKED(old.slock),
> + .owned = 0 };
> if (likely(try_cmpxchg(&sk->sk_lock.combined,
> &old.combined, tmp.combined)))
> return;
Thanks for your patch, could you please use a nicer formatting ?
(And keep an empty line between variables and code)
diff --git a/net/core/sock.c b/net/core/sock.c
index 9d841975a7a14a12769450a8d937af96f7777070..fba4d5b8553c58f700bda3dbd82ce68ec74187da
100644
--- a/net/core/sock.c
+++ b/net/core/sock.c
@@ -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;
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH net-next v1] net: fix sock compilation error under CONFIG_PREEMPT_RT
2026-02-28 10:43 ` Eric Dumazet
@ 2026-02-28 10:48 ` Jiayuan Chen
0 siblings, 0 replies; 3+ messages in thread
From: Jiayuan Chen @ 2026-02-28 10:48 UTC (permalink / raw)
To: Eric Dumazet
Cc: netdev, Jiayuan Chen, Kuniyuki Iwashima, Paolo Abeni,
Willem de Bruijn, David S. Miller, Jakub Kicinski, Simon Horman,
Sebastian Andrzej Siewior, Clark Williams, Steven Rostedt,
Jason Xing, linux-kernel, linux-rt-devel
February 28, 2026 at 18:43, "Eric Dumazet" <edumazet@google.com mailto:edumazet@google.com?to=%22Eric%20Dumazet%22%20%3Cedumazet%40google.com%3E > wrote:
>
> On Sat, Feb 28, 2026 at 10:07 AM Jiayuan Chen <jiayuan.chen@linux.dev> wrote:
>
> >
> > From: Jiayuan Chen <jiayuan.chen@shopee.com>
> >
> > 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: 5151ec54f586 ("net: use try_cmpxchg() in lock_sock_nested()")
> > Signed-off-by: Jiayuan Chen <jiayuan.chen@shopee.com>
> > ---
> > net/core/sock.c | 10 ++++------
> > 1 file changed, 4 insertions(+), 6 deletions(-)
> >
> > diff --git a/net/core/sock.c b/net/core/sock.c
> > index 9d841975a7a1..2461aba7b18a 100644
> > --- a/net/core/sock.c
> > +++ b/net/core/sock.c
> > @@ -3782,12 +3782,10 @@ 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;
> > -
> > - tmp.slock = __SPIN_LOCK_UNLOCKED(tmp.slock);
> > - tmp.owned = 1;
> > - old.slock = __SPIN_LOCK_UNLOCKED(old.slock);
> > - old.owned = 0;
> > + socket_lock_t tmp = { .slock = __SPIN_LOCK_UNLOCKED(tmp.slock),
> > + .owned = 1 };
> > + socket_lock_t old = { .slock = __SPIN_LOCK_UNLOCKED(old.slock),
> > + .owned = 0 };
> > if (likely(try_cmpxchg(&sk->sk_lock.combined,
> > &old.combined, tmp.combined)))
> > return;
> >
> Thanks for your patch, could you please use a nicer formatting ?
> (And keep an empty line between variables and code)
Ack. I will send it later.
> diff --git a/net/core/sock.c b/net/core/sock.c
> index 9d841975a7a14a12769450a8d937af96f7777070..fba4d5b8553c58f700bda3dbd82ce68ec74187da
> 100644
> --- a/net/core/sock.c
> +++ b/net/core/sock.c
> @@ -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;
>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-02-28 10:48 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-02-28 9:06 [PATCH net-next v1] net: fix sock compilation error under CONFIG_PREEMPT_RT Jiayuan Chen
2026-02-28 10:43 ` Eric Dumazet
2026-02-28 10:48 ` Jiayuan Chen
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox