linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] ELF: add and use SUPRESS_WARN_UNUSED_RESULT
@ 2021-06-25 19:52 Alexey Dobriyan
  2021-06-25 20:34 ` Miguel Ojeda
  2021-06-25 21:13 ` [PATCH v2] ELF: add and use SUPPRESS_WARN_UNUSED_RESULT Alexey Dobriyan
  0 siblings, 2 replies; 13+ messages in thread
From: Alexey Dobriyan @ 2021-06-25 19:52 UTC (permalink / raw)
  To: akpm; +Cc: linux-kernel, Miguel Ojeda

Last write to the "error" variable in load_elf_binary() is dead write.

Add and use SUPRESS_WARN_UNUSED_RESULT macro to express intent better.

Credit goes to Ed Catmur:

	https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66425#c34

Macro doesn't work for WUR functions returning structures and unions,
but it will work once gcc copies clang.

Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com>
---

 fs/binfmt_elf.c                     |    3 ++-
 include/linux/compiler_attributes.h |    4 ++++
 2 files changed, 6 insertions(+), 1 deletion(-)

--- a/fs/binfmt_elf.c
+++ b/fs/binfmt_elf.c
@@ -1290,7 +1290,8 @@ static int load_elf_binary(struct linux_binprm *bprm)
 		   and some applications "depend" upon this behavior.
 		   Since we do not have the power to recompile these, we
 		   emulate the SVr4 behavior. Sigh. */
-		error = vm_mmap(NULL, 0, PAGE_SIZE, PROT_READ | PROT_EXEC,
+		SUPRESS_WARN_UNUSED_RESULT
+		vm_mmap(NULL, 0, PAGE_SIZE, PROT_READ | PROT_EXEC,
 				MAP_FIXED | MAP_PRIVATE, 0);
 	}
 
--- a/include/linux/compiler_attributes.h
+++ b/include/linux/compiler_attributes.h
@@ -284,6 +284,10 @@
  * clang: https://clang.llvm.org/docs/AttributeReference.html#nodiscard-warn-unused-result
  */
 #define __must_check                    __attribute__((__warn_unused_result__))
+/*
+ * "(void)" is enough for clang but not for gcc.
+ */
+#define SUPRESS_WARN_UNUSED_RESULT	(void)!
 
 /*
  *   gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-weak-function-attribute

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2021-06-26 14:30 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-25 19:52 [PATCH] ELF: add and use SUPRESS_WARN_UNUSED_RESULT Alexey Dobriyan
2021-06-25 20:34 ` Miguel Ojeda
2021-06-25 21:10   ` Alexey Dobriyan
2021-06-25 21:11     ` Randy Dunlap
2021-06-25 21:57     ` Miguel Ojeda
2021-06-26  6:44       ` [PATCH] ELF: add and use SUPRESS_WARN_UNUSED_RESULT\ Alexey Dobriyan
2021-06-26 14:29         ` Miguel Ojeda
2021-06-25 21:13 ` [PATCH v2] ELF: add and use SUPPRESS_WARN_UNUSED_RESULT Alexey Dobriyan
2021-06-25 23:30   ` Andrew Morton
2021-06-26  2:05     ` Linus Torvalds
2021-06-26  2:37       ` Al Viro
2021-06-26  3:13         ` Linus Torvalds
2021-06-26  6:40     ` Alexey Dobriyan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).