Commit 9490991482a2091a828d997adbc088e24c310a4d

Authored by Borislav Petkov
Committed by Linus Torvalds
1 parent a8127717cb

Add unitialized_var() macro for suppressing gcc warnings

Introduce a macro for suppressing gcc from generating a warning about a
probable uninitialized state of a variable.

Example:

-	spinlock_t *ptl;
+	spinlock_t *uninitialized_var(ptl);

Not a happy solution, but those warnings are obnoxious.

- Using the usual pointlessly-set-it-to-zero approach wastes several
  bytes of text.

- Using a macro means we can (hopefully) do something else if gcc changes
  cause the `x = x' hack to stop working

- Using a macro means that people who are worried about hiding true bugs
  can easily turn it off.

Signed-off-by: Borislav Petkov <bbpetkov@yahoo.de>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

Showing 4 changed files with 15 additions and 1 deletions Side-by-side Diff

include/linux/compiler-gcc3.h
... ... @@ -13,5 +13,11 @@
13 13 #define __must_check __attribute__((warn_unused_result))
14 14 #endif
15 15  
  16 +/*
  17 + * A trick to suppress uninitialized variable warning without generating any
  18 + * code
  19 + */
  20 +#define uninitialized_var(x) x = x
  21 +
16 22 #define __always_inline inline __attribute__((always_inline))
include/linux/compiler-gcc4.h
... ... @@ -16,4 +16,10 @@
16 16 #define __must_check __attribute__((warn_unused_result))
17 17 #define __compiler_offsetof(a,b) __builtin_offsetof(a,b)
18 18 #define __always_inline inline __attribute__((always_inline))
  19 +
  20 +/*
  21 + * A trick to suppress uninitialized variable warning without generating any
  22 + * code
  23 + */
  24 +#define uninitialized_var(x) x = x
include/linux/compiler-intel.h
... ... @@ -22,4 +22,6 @@
22 22 (typeof(ptr)) (__ptr + (off)); })
23 23  
24 24 #endif
  25 +
  26 +#define uninitialized_var(x) x
... ... @@ -1455,7 +1455,7 @@
1455 1455 pte_t *pte;
1456 1456 int err;
1457 1457 struct page *pmd_page;
1458   - spinlock_t *ptl = ptl; /* Suppress gcc warning */
  1458 + spinlock_t *uninitialized_var(ptl);
1459 1459  
1460 1460 pte = (mm == &init_mm) ?
1461 1461 pte_alloc_kernel(pmd, addr) :