seqlock: avoid -Wshadow warnings
Subsystems (2)
PATCH 1/1 seqlock: avoid -Wshadow warnings
From: Arnd Bergmann <[email protected]>
When building with W=2, there is a flood of warnings about the seqlock macros shadowing local variables:
19806 linux/seqlock.h:331:11: warning: declaration of 'seq' shadows a previous local [-Wshadow]
48 linux/seqlock.h:348:11: warning: declaration of 'seq' shadows a previous local [-Wshadow]
8 linux/seqlock.h:379:11: warning: declaration of 'seq' shadows a previous local [-Wshadow]
Prefix the local variables to make the warning useful elsewhere again.
--- include/linux/seqlock.h | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-)
include/linux/seqlock.h +7 -7
@@ -328,13 +328,13 @@ SEQCOUNT_LOCKNAME(ww_mutex, struct ww_mutex, true, &s->lock->base, ww_mu*/ #define __read_seqcount_begin (s) \ ({ \ - unsigned seq; \ + unsigned __seq; \ \ - while ((seq = __seqcount_sequence(s)) & 1) \ + while ((__seq = __seqcount_sequence(s)) & 1) \ cpu_relax(); \ \ kcsan_atomic_next(KCSAN_SEQLOCK_REGION_MAX); \ - seq; \ + __seq; \ })/**
@@ -345,10 +345,10 @@ SEQCOUNT_LOCKNAME(ww_mutex, struct ww_mutex, true, &s->lock->base, ww_mu*/ #define raw_read_seqcount_begin (s) \ ({ \ - unsigned seq = __read_seqcount_begin(s); \ + unsigned _seq = __read_seqcount_begin(s); \ \ smp_rmb(); \ - seq; \ + _seq; \ })/**
@@ -376,11 +376,11 @@ SEQCOUNT_LOCKNAME(ww_mutex, struct ww_mutex, true, &s->lock->base, ww_mu*/ #define raw_read_seqcount (s) \ ({ \ - unsigned seq = __seqcount_sequence(s); \ + unsigned __seq = __seqcount_sequence(s); \ \ smp_rmb(); \ kcsan_atomic_next(KCSAN_SEQLOCK_REGION_MAX); \ - seq; \ + __seq; \ })/**
Signature · 1 line
2.27.0
Peter Zijlstra
maintainerReview
Quoted 8 lines · Arnd Bergmann
(quoted diff) +3
-3- unsigned seq; \ + unsigned __seq; \ - unsigned seq = __read_seqcount_begin(s); \ + unsigned _seq = __read_seqcount_begin(s); \ - unsigned seq = __seqcount_sequence(s); \ + unsigned __seq = __seqcount_sequence(s); \
Can we have a consistent number of leading '_' ?
Also, I suppose you're going to find the explicit shadow in ___wait_event(), that one's not going to be trivial to fix.
Quoted 6 lines · Peter Zijlstra
Quoted 2 lines · Arnd Bergmann
(quoted diff) +1
-1- unsigned seq; \ + unsigned __seq; \
Quoted 7 lines
Review
Quoted 5 lines
(quoted diff) +2
-2- unsigned seq = __read_seqcount_begin(s); \ + unsigned _seq = __read_seqcount_begin(s); \ - unsigned seq = __seqcount_sequence(s); \ + unsigned __seq = __seqcount_sequence(s); \Can we have a consistent number of leading '_' ?
Not really ;-)
The warning comes from raw_read_seqcount_begin() calling __read_seqcount_begin() and both using the same variable name. I could rename one of them and use double-underscores for both, but I haven't come up with a good alternative name that wouldn't make it less consistent in the process.
Quoted 2 lines
Also, I suppose you're going to find the explicit shadow in
___wait_event(), that one's not going to be trivial to fix.
I have this patch in my tree at the moment but did not send that yet because that caused a regression on powerpc:
include/linux/wait.h +0 -0
@@ -265,7 +265,11 @@ extern void init_wait_entry(struct
wait_queue_entry *wq_entry, int flags);
({
\
__label__ __out;
\
struct wait_queue_entry __wq_entry;
\
- long __ret = ret; /* explicit shadow */
\
+ __diag_push()
\
+ __diag_ignore(GCC, 8, "-Wshadow", "explicit shadow")
\
+ __diag_ignore(CLANG, 9, "-Wshadow", "explicit shadow")
\
+ long __ret = ret;
\
+ __diag_pop();
\
\
init_wait_entry(&__wq_entry, exclusive ? WQ_FLAG_EXCLUSIVE :
0); \
for (;;) {
\Still looking at alternative approaches.
Arnd
Peter Zijlstra
maintainerQuoted 10 lines · Arnd Bergmann
Quoted 9 lines · Peter Zijlstra
Quoted 5 lines · Arnd Bergmann
(quoted diff) +2
-2- unsigned seq; \ + unsigned __seq; \ - unsigned seq = __read_seqcount_begin(s); \ + unsigned _seq = __read_seqcount_begin(s); \
Quoted 6 lines
Quoted 4 lines
Review
Quoted 2 lines
(quoted diff) +1
-1- unsigned seq = __seqcount_sequence(s); \ + unsigned __seq = __seqcount_sequence(s); \Can we have a consistent number of leading '_' ?
Not really ;-)
Duh.. ok, I'll take it as is.
Quoted 15 lines · Arnd Bergmann
Quoted 6 lines · Peter Zijlstra
Quoted 2 lines · Arnd Bergmann
(quoted diff) +1
-1- unsigned seq; \ + unsigned __seq; \Quoted 7 lines
Review
Quoted 5 lines
(quoted diff) +2
-2- unsigned seq = __read_seqcount_begin(s); \ + unsigned _seq = __read_seqcount_begin(s); \ - unsigned seq = __seqcount_sequence(s); \ + unsigned __seq = __seqcount_sequence(s); \Can we have a consistent number of leading '_' ?
Quoted 7 lines
Not really ;-)
The warning comes from
raw_read_seqcount_begin()calling__read_seqcount_begin()and both using the same variable name. I could rename one of them and use double-underscores for both, but I haven't come up with a good alternative name that wouldn't make it less consistent in the process.
At least x86's put_user and get_user use _pu/_gu suffixes on their local variables, so perhaps that could be made a weak default convention?
__seq_rsb__seq_rrsb__seq_rrs
Hm, or perhaps not. But it's still better than triplicating each macro to do a UNIQUE_ID dance.
Rasmus
The following commit has been merged into the locking/core branch of tip:
The following commit has been merged into the locking/core branch of tip:
Commit-ID: a07c45312f06e288417049208c344ad76074627d Gitweb: https://git.kernel.org/tip/a07c45312f06e288417049208c344ad76074627d Author: Arnd Bergmann <[email protected]> AuthorDate: Mon, 26 Oct 2020 17:50:38 +01:00 Committer: Peter Zijlstra <[email protected]> CommitterDate: Thu, 03 Dec 2020 11:20:50 +01:00
seqlock: avoid -Wshadow warnings
When building with W=2, there is a flood of warnings about the seqlock macros shadowing local variables:
19806 linux/seqlock.h:331:11: warning: declaration of 'seq' shadows a previous local [-Wshadow]
48 linux/seqlock.h:348:11: warning: declaration of 'seq' shadows a previous local [-Wshadow]
8 linux/seqlock.h:379:11: warning: declaration of 'seq' shadows a previous local [-Wshadow]
Prefix the local variables to make the warning useful elsewhere again.
--- include/linux/seqlock.h | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-)
include/linux/seqlock.h +7 -7
@@ -328,13 +328,13 @@ SEQCOUNT_LOCKNAME(ww_mutex, struct ww_mutex, true, &s->lock->base, ww_mu*/ #define __read_seqcount_begin (s) \ ({ \ - unsigned seq; \ + unsigned __seq; \ \ - while ((seq = __seqcount_sequence(s)) & 1) \ + while ((__seq = __seqcount_sequence(s)) & 1) \ cpu_relax(); \ \ kcsan_atomic_next(KCSAN_SEQLOCK_REGION_MAX); \ - seq; \ + __seq; \ })/**
@@ -345,10 +345,10 @@ SEQCOUNT_LOCKNAME(ww_mutex, struct ww_mutex, true, &s->lock->base, ww_mu*/ #define raw_read_seqcount_begin (s) \ ({ \ - unsigned seq = __read_seqcount_begin(s); \ + unsigned _seq = __read_seqcount_begin(s); \ \ smp_rmb(); \ - seq; \ + _seq; \ })/**
@@ -376,11 +376,11 @@ SEQCOUNT_LOCKNAME(ww_mutex, struct ww_mutex, true, &s->lock->base, ww_mu*/ #define raw_read_seqcount (s) \ ({ \ - unsigned seq = __seqcount_sequence(s); \ + unsigned __seq = __seqcount_sequence(s); \ \ smp_rmb(); \ kcsan_atomic_next(KCSAN_SEQLOCK_REGION_MAX); \ - seq; \ + __seq; \ })/**