Commit 63a0895d authored by Kees Cook's avatar Kees Cook

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 78a5255f
("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/20200603174714.192027-1-glider@google.com/
[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: default avatarLinus Torvalds <torvalds@linux-foundation.org>
Reviewed-by: default avatarBart van Assche <bvanassche@acm.org>
Reviewed-by: default avatarMiguel Ojeda <miguel.ojeda.sandonis@gmail.com>
Tested-by: default avatarNathan Chancellor <natechancellor@gmail.com>
Tested-by: default avatarSedat Dilek <sedat.dilek@gmail.com>
Signed-off-by: default avatarKees Cook <keescook@chromium.org>
parent 3f649ab7
...@@ -5,8 +5,6 @@ ...@@ -5,8 +5,6 @@
/* Compiler specific definitions for Clang compiler */ /* Compiler specific definitions for Clang compiler */
#define uninitialized_var(x) x = *(&(x))
/* same as gcc, this was present in clang-2.6 so we can assume it works /* same as gcc, this was present in clang-2.6 so we can assume it works
* with any version that can compile the kernel * with any version that can compile the kernel
*/ */
......
...@@ -59,12 +59,6 @@ ...@@ -59,12 +59,6 @@
(typeof(ptr)) (__ptr + (off)); \ (typeof(ptr)) (__ptr + (off)); \
}) })
/*
* A trick to suppress uninitialized variable warning without generating any
* code
*/
#define uninitialized_var(x) x = x
#ifdef CONFIG_RETPOLINE #ifdef CONFIG_RETPOLINE
#define __noretpoline __attribute__((__indirect_branch__("keep"))) #define __noretpoline __attribute__((__indirect_branch__("keep")))
#endif #endif
......
...@@ -111,8 +111,6 @@ ...@@ -111,8 +111,6 @@
# define noinline # define noinline
#endif #endif
#define uninitialized_var(x) x = *(&(x))
#include <linux/types.h> #include <linux/types.h>
/* /*
......
...@@ -110,8 +110,6 @@ static inline void free_page(unsigned long addr) ...@@ -110,8 +110,6 @@ static inline void free_page(unsigned long addr)
const typeof( ((type *)0)->member ) *__mptr = (ptr); \ const typeof( ((type *)0)->member ) *__mptr = (ptr); \
(type *)( (char *)__mptr - offsetof(type,member) );}) (type *)( (char *)__mptr - offsetof(type,member) );})
#define uninitialized_var(x) x = x
# ifndef likely # ifndef likely
# define likely(x) (__builtin_expect(!!(x), 1)) # define likely(x) (__builtin_expect(!!(x), 1))
# endif # endif
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment