net: fix sock compilation error under CONFIG_PREEMPT_RT
Subsystems (4)
PATCH 1/1 net: fix sock compilation error under CONFIG_PREEMPT_RT
From: Jiayuan Chen <[email protected]>
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).
--- net/core/sock.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-)
net/core/sock.c +4 -6
@@ -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 ;
Signature · 1 line
2.43.0
Quoted 31 lines · Jiayuan Chen
From: Jiayuan Chen <[email protected]>
When
CONFIG_PREEMPT_RTis 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 <[email protected]>--- net/core/sock.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-)net/core/sock.c +0
-3@@ -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);
net/core/sock.c void noinline lock_sock_nested(struct sock *sk, int subclass) · line 3791
Quoted 10 lines
net/core/sock.c +4
-3- 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)
net/core/sock.c +0 -0
100644
net/core/sock.c +0 -0
@@ -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;Quoted 45 lines · Eric Dumazet
Quoted 33 lines · Jiayuan Chen
From: Jiayuan Chen <[email protected]>
When
CONFIG_PREEMPT_RTis 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 <[email protected]>---
net/core/sock.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-)diff --git
a/net/core/sock.cb/net/core/sock.c
index9d841975a7a1..2461aba7b18a100644
---a/net/core/sock.c
+++b/net/core/sock.c
@@ -3782,12 +3782,10 @@ void noinlinelock_sock_nested(struct sock *sk, int subclass)might_sleep();
#ifdefCONFIG_64BIT
if (sizeof(struct slock_owned)== sizeof(long)) {
-socket_lock_ttmp, old;
-
- tmp.slock =__SPIN_LOCK_UNLOCKED(tmp.slock);
- tmp.owned = 1;
- old.slock =__SPIN_LOCK_UNLOCKED(old.slock);Quoted 9 lines
- old.owned = 0;
+socket_lock_ttmp = { .slock =__SPIN_LOCK_UNLOCKED(tmp.slock),
+ .owned = 1 };
+socket_lock_told = { .slock =__SPIN_LOCK_UNLOCKED(old.slock),
+ .owned = 0 };
if (likely(try_cmpxchg(&sk->sk_lock.combined, &old.combined, tmp.combined)))
return;
Quoted 2 lines
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.
Quoted 28 lines
net/core/sock.c +0
-0100644
net/core/sock.c +8
-5@@ -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;