Skip to content

Commit 63a0895

Browse files
committed
compiler: Remove uninitialized_var() macro
Using uninitialized_var() is dangerous as it papers over real bugs[1] (or can in the future), and suppresses unrelated compiler warnings (e.g. "unused variable"). If the compiler thinks it is uninitialized, either simply initialize the variable or make compiler changes. As recommended[2] by[3] Linus[4], remove the macro. With the recent change to disable -Wmaybe-uninitialized in v5.7 in commit 78a5255 ("Stop the ad-hoc games with -Wno-maybe-initialized"), this is likely the best time to make this treewide change. [1] https://lore.kernel.org/lkml/[email protected]/ [2] https://lore.kernel.org/lkml/CA+55aFw+Vbj0i=1TGqCR5vQkCzWJ0QxK6CernOU6eedsudAixw@mail.gmail.com/ [3] https://lore.kernel.org/lkml/CA+55aFwgbgqhbp1fkxvRKEpzyR5J8n1vKT1VZdz9knmPuXhOeg@mail.gmail.com/ [4] https://lore.kernel.org/lkml/CA+55aFz2500WfbKXAx8s67wrm9=yVJu65TpLgN_ybYNv0VEOKA@mail.gmail.com/ Suggested-by: Linus Torvalds <[email protected]> Reviewed-by: Bart van Assche <[email protected]> Reviewed-by: Miguel Ojeda <[email protected]> Tested-by: Nathan Chancellor <[email protected]> Tested-by: Sedat Dilek <[email protected]> Signed-off-by: Kees Cook <[email protected]>
1 parent 3f649ab commit 63a0895

File tree

4 files changed

+0
-12
lines changed

4 files changed

+0
-12
lines changed

include/linux/compiler-clang.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55

66
/* Compiler specific definitions for Clang compiler */
77

8-
#define uninitialized_var(x) x = *(&(x))
9-
108
/* same as gcc, this was present in clang-2.6 so we can assume it works
119
* with any version that can compile the kernel
1210
*/

include/linux/compiler-gcc.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,6 @@
5959
(typeof(ptr)) (__ptr + (off)); \
6060
})
6161

62-
/*
63-
* A trick to suppress uninitialized variable warning without generating any
64-
* code
65-
*/
66-
#define uninitialized_var(x) x = x
67-
6862
#ifdef CONFIG_RETPOLINE
6963
#define __noretpoline __attribute__((__indirect_branch__("keep")))
7064
#endif

tools/include/linux/compiler.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,6 @@
111111
# define noinline
112112
#endif
113113

114-
#define uninitialized_var(x) x = *(&(x))
115-
116114
#include <linux/types.h>
117115

118116
/*

tools/virtio/linux/kernel.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,6 @@ static inline void free_page(unsigned long addr)
110110
const typeof( ((type *)0)->member ) *__mptr = (ptr); \
111111
(type *)( (char *)__mptr - offsetof(type,member) );})
112112

113-
#define uninitialized_var(x) x = x
114-
115113
# ifndef likely
116114
# define likely(x) (__builtin_expect(!!(x), 1))
117115
# endif

0 commit comments

Comments
 (0)