Skip to content

Commit

Permalink
Add unitialized_var() macro for suppressing gcc warnings
Browse files Browse the repository at this point in the history
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 <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
Borislav Petkov authored and Linus Torvalds committed May 7, 2007
1 parent a812771 commit 9490991
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 1 deletion.
6 changes: 6 additions & 0 deletions include/linux/compiler-gcc3.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,10 @@
#define __must_check __attribute__((warn_unused_result))
#endif

/*
* A trick to suppress uninitialized variable warning without generating any
* code
*/
#define uninitialized_var(x) x = x

#define __always_inline inline __attribute__((always_inline))
6 changes: 6 additions & 0 deletions include/linux/compiler-gcc4.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,9 @@
#define __must_check __attribute__((warn_unused_result))
#define __compiler_offsetof(a,b) __builtin_offsetof(a,b)
#define __always_inline inline __attribute__((always_inline))

/*
* A trick to suppress uninitialized variable warning without generating any
* code
*/
#define uninitialized_var(x) x = x
2 changes: 2 additions & 0 deletions include/linux/compiler-intel.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,5 @@
(typeof(ptr)) (__ptr + (off)); })

#endif

#define uninitialized_var(x) x
2 changes: 1 addition & 1 deletion mm/memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -1455,7 +1455,7 @@ static int apply_to_pte_range(struct mm_struct *mm, pmd_t *pmd,
pte_t *pte;
int err;
struct page *pmd_page;
spinlock_t *ptl = ptl; /* Suppress gcc warning */
spinlock_t *uninitialized_var(ptl);

pte = (mm == &init_mm) ?
pte_alloc_kernel(pmd, addr) :
Expand Down

0 comments on commit 9490991

Please sign in to comment.