Skip to contentSkip to conversation

lockdep: avoid bogus clang warning

PATCH In review Arnd Bergmann 4 participants 4 messages Mar 25, 2019 – Apr 18, 2019 Locking primitives

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 lockdep: avoid bogus clang warning

When lockdep is enabled, and -Wuninitialized warnings are enabled, clang produces a silly warning for every file we compile:

In file included from kernel/sched/fair.c:23:
kernel/sched/sched.h:1094:15: error: variable 'cookie' is uninitialized when used here [-Werror,-Wuninitialized]

        rf->cookie = lockdep_pin_lock(&rq->lock);
                     ^~~~~~~~~~~~~~~~~~~~~~~~~~~
 include/linux/lockdep.h:474:60: note: expanded from macro 'lockdep_pin_lock'
 #define lockdep_pin_lock(l)                     ({ struct pin_cookie cookie; cookie; })
                                                                             ^~~~~~
 kernel/sched/sched.h:1094:15: note: variable 'cookie' is declared here
 include/linux/lockdep.h:474:34: note: expanded from macro 'lockdep_pin_lock'
 #define lockdep_pin_lock(l)                     ({ struct pin_cookie cookie; cookie; })
                                                   ^

As the 'struct pin_cookie' structure is empty in this configuration, there is no need to initialize it for correctness, but it also does not hurt to set it to an empty structure, so do that to avoid the warning.

---
 include/linux/lockdep.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/lockdep.h +1 -1
index 79c3873d58ac..31d7549933eb 100644
@@ -471,7 +471,7 @@ struct pin_cookie { };
 
 #define NIL_COOKIE (struct pin_cookie){ }
 
-#define lockdep_pin_lock(l)			({ struct pin_cookie cookie; cookie; })
+#define lockdep_pin_lock(l)			({ struct pin_cookie cookie = {}; cookie; })
 #define lockdep_repin_lock(l, c)		do { (void)(l); (void)(c); } while (0)
 #define lockdep_unpin_lock(l, c)		do { (void)(l); (void)(c); } while (0)
 
Signature · 1 line
2.20.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 7 lines · On Mon, 25 Mar 2019 13:57:57 +0100 Arnd Bergmann <[email protected]> wrote:

When lockdep is enabled, and -Wuninitialized warnings are enabled, clang produces a silly warning for every file we compile:

In file included from kernel/sched/fair.c:23:
kernel/sched/sched.h:1094:15: error: variable 'cookie' is uninitialized when used here [-Werror,-Wuninitialized]

        rf->cookie = lockdep_pin_lock(&rq->lock);
                     ^~~~~~~~~~~~~~~~~~~~~~~~~~~

Sad it warns as struct pin_cookie is of size zero. But hey.

Quoted 22 lines

include/linux/lockdep.h:474:60: note: expanded from macro 'lockdep_pin_lock'

 #define lockdep_pin_lock(l)                     ({ struct pin_cookie cookie; cookie; })
                                                                             ^~~~~~
 kernel/sched/sched.h:1094:15: note: variable 'cookie' is declared here
 include/linux/lockdep.h:474:34: note: expanded from macro 'lockdep_pin_lock'
 #define lockdep_pin_lock(l)                     ({ struct pin_cookie cookie; cookie; })
                                                   ^

As the 'struct pin_cookie' structure is empty in this configuration, there is no need to initialize it for correctness, but it also does not hurt to set it to an empty structure, so do that to avoid the warning.

---
 include/linux/lockdep.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/lockdep.h +0 -0
index 79c3873d58ac..31d7549933eb 100644

include/linux/lockdep.h struct pin_cookie { }; · line 474

Quoted 5 lines
include/linux/lockdep.h +1 -1
@@ -471,7 +471,7 @@ struct pin_cookie { };
 
 #define NIL_COOKIE (struct pin_cookie){ }
 
-#define lockdep_pin_lock(l)			({ struct pin_cookie cookie; cookie; })
+#define lockdep_pin_lock(l)			({ struct pin_cookie cookie = {}; cookie; })

-- Steve

Quoted 3 lines
include/linux/lockdep.h +0 -0
 #define lockdep_repin_lock(l, c)		do { (void)(l); (void)(c); } while (0)
 #define lockdep_unpin_lock(l, c)		do { (void)(l); (void)(c); } while (0)
 
Acked-by on v1 1/1
#2 lore raw
In reply to Arnd Bergmann
Quoted 29 lines · Arnd Bergmann

When lockdep is enabled, and -Wuninitialized warnings are enabled, clang produces a silly warning for every file we compile:

In file included from kernel/sched/fair.c:23:
kernel/sched/sched.h:1094:15: error: variable 'cookie' is uninitialized when used here [-Werror,-Wuninitialized]

        rf->cookie = lockdep_pin_lock(&rq->lock);
                     ^~~~~~~~~~~~~~~~~~~~~~~~~~~
 include/linux/lockdep.h:474:60: note: expanded from macro 'lockdep_pin_lock'
 #define lockdep_pin_lock(l)                     ({ struct pin_cookie cookie; cookie; })
                                                                             ^~~~~~
 kernel/sched/sched.h:1094:15: note: variable 'cookie' is declared here
 include/linux/lockdep.h:474:34: note: expanded from macro 'lockdep_pin_lock'
 #define lockdep_pin_lock(l)                     ({ struct pin_cookie cookie; cookie; })
                                                   ^

As the 'struct pin_cookie' structure is empty in this configuration, there is no need to initialize it for correctness, but it also does not hurt to set it to an empty structure, so do that to avoid the warning.

---
 include/linux/lockdep.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/lockdep.h +0 -0
index 79c3873d58ac..31d7549933eb 100644

include/linux/lockdep.h struct pin_cookie { }; · line 476

Quoted 7 lines
include/linux/lockdep.h +1 -1
@@ -471,7 +471,7 @@ struct pin_cookie { };
 
 #define NIL_COOKIE (struct pin_cookie){ }
 
-#define lockdep_pin_lock(l)			({ struct pin_cookie cookie; cookie; })
+#define lockdep_pin_lock(l)			({ struct pin_cookie cookie = {}; cookie; })
 #define lockdep_repin_lock(l, c)		do { (void)(l); (void)(c); } while (0)
 #define lockdep_unpin_lock(l, c)		do { (void)(l); (void)(c); } while (0)

Will

#3 lore raw

[tip:locking/core] locking/lockdep: Avoid bogus Clang warning

In reply to Arnd Bergmann
locking/lockdep: Avoid bogus Clang warning
Commit-ID:  3771b0fe9dfc3801eac0142d1af6ba94dee83c6c
Gitweb:     https://git.kernel.org/tip/3771b0fe9dfc3801eac0142d1af6ba94dee83c6c
Author:     Arnd Bergmann <[email protected]>
AuthorDate: Mon, 25 Mar 2019 13:57:57 +0100
Committer:  Ingo Molnar <[email protected]>
CommitDate: Thu, 18 Apr 2019 14:01:17 +0200

locking/lockdep: Avoid bogus Clang warning

When lockdep is enabled, and -Wuninitialized warnings are enabled, Clang produces a silly warning for every file we compile:

In file included from kernel/sched/fair.c:23:
kernel/sched/sched.h:1094:15: error: variable 'cookie' is uninitialized when used here [-Werror,-Wuninitialized]

         rf->cookie = lockdep_pin_lock(&rq->lock);
                      ^~~~~~~~~~~~~~~~~~~~~~~~~~~
  include/linux/lockdep.h:474:60: note: expanded from macro 'lockdep_pin_lock'
  #define lockdep_pin_lock(l)                     ({ struct pin_cookie cookie; cookie; })
                                                                             ^~~~~~
  kernel/sched/sched.h:1094:15: note: variable 'cookie' is declared here
  include/linux/lockdep.h:474:34: note: expanded from macro 'lockdep_pin_lock'
  #define lockdep_pin_lock(l)                     ({ struct pin_cookie cookie; cookie; })
                                                    ^

As the 'struct pin_cookie' structure is empty in this configuration, there is no need to initialize it for correctness, but it also does not hurt to set it to an empty structure, so do that to avoid the warning.

Cc Bart Van Assche <[email protected]>
Cc Joel Fernandes (Google) <[email protected]>
Cc Linus Torvalds <[email protected]>
Cc Nathan Chancellor <[email protected]>
Cc Nick Desaulniers <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Steven Rostedt (VMware) <[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc Waiman Long <[email protected]>
---
 include/linux/lockdep.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/lockdep.h +1 -1
index 79c3873d58ac..21725a91442b 100644
@@ -471,7 +471,7 @@ struct pin_cookie { };
 
 #define NIL_COOKIE (struct pin_cookie){ }
 
-#define lockdep_pin_lock(l)			({ struct pin_cookie cookie; cookie; })
+#define lockdep_pin_lock(l)			({ struct pin_cookie cookie = { }; cookie; })
 #define lockdep_repin_lock(l, c)		do { (void)(l); (void)(c); } while (0)
 #define lockdep_unpin_lock(l, c)		do { (void)(l); (void)(c); } while (0)