kbuild: enforce -Werror=unused-result
PATCH v2 1/1 kbuild: enforce -Werror=unused-result
It is a hard error if a return value is ignored.
In case the return value has no meaning, remove the attribute.
---
v2:
resend
Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Makefile +1 -1
@@ -495,7 +495,7 @@ KBUILD_AFLAGS := -D__ASSEMBLY__ -fno-PIE KBUILD_CFLAGS := -Wall -Wundef -Werror=strict-prototypes -Wno-trigraphs \ -fno-strict-aliasing -fno-common -fshort-wchar -fno-PIE \ -Werror=implicit-function-declaration -Werror=implicit-int \ - -Werror=return-type -Wno-format-security \ + -Werror=return-type -Werror=unused-result -Wno-format-security \ -std=gnu89 KBUILD_CPPFLAGS := -D__KERNEL__ KBUILD_AFLAGS_KERNEL :=
kernel test robot
build botThank you for the patch! Yet something to improve:
Hi Olaf,
Thank you for the patch! Yet something to improve:
[auto build test ERROR on kbuild/for-next]
[also build test ERROR on linux/master linus/master v5.12-rc3 next-20210319] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/0day-ci/linux/commits/Olaf-Hering/kbuild-enforce-Werror-unused-result/20210319-223913 base: https://git.kernel.org/pub/scm/linux/kernel/git/masahiroy/linux-kbuild.git for-next config: alpha-allyesconfig (attached as .config) compiler: alpha-linux-gcc (GCC) 9.3.0
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# https://github.com/0day-ci/linux/commit/635ecb94f0f38a005c528c2cddb9fc6f9cfab1dc
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Olaf-Hering/kbuild-enforce-Werror-unused-result/20210319-223913 git checkout 635ecb94f0f38a005c528c2cddb9fc6f9cfab1dc
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross ARCH=alpha
If you fix the issue, kindly add following tag as appropriate
All errors (new ones prefixed by >>):
fs/binfmt_em86.c: In function 'load_em86':
>> fs/binfmt_em86.c:66:2: error: ignoring return value of 'remove_arg_zero', declared with attribute warn_unused_result [-Werror=unused-result]
66 | remove_arg_zero(bprm);
| ^~~~~~~~~~~~~~~~~~~~~cc1: some warnings being treated as errors
vim +/remove_arg_zero +66 fs/binfmt_em86.c
^1da177e4c3f41 Linus Torvalds 2005-04-16 25
71613c3b871c5a Al Viro 2012-10-20 26 static int load_em86(struct linux_binprm *bprm)
^1da177e4c3f41 Linus Torvalds 2005-04-16 27 {
a310dcb7a43f97 Daniel Wagner 2016-08-02 28 const char *i_name, *i_arg;
a310dcb7a43f97 Daniel Wagner 2016-08-02 29 char *interp;
^1da177e4c3f41 Linus Torvalds 2005-04-16 30 struct file * file;
^1da177e4c3f41 Linus Torvalds 2005-04-16 31 int retval;
^1da177e4c3f41 Linus Torvalds 2005-04-16 32 struct elfhdr elf_ex;
^1da177e4c3f41 Linus Torvalds 2005-04-16 33
^1da177e4c3f41 Linus Torvalds 2005-04-16 34 /* Make sure this is a Linux/Intel ELF executable... */
^1da177e4c3f41 Linus Torvalds 2005-04-16 35 elf_ex = *((struct elfhdr *)bprm->buf);
^1da177e4c3f41 Linus Torvalds 2005-04-16 36
^1da177e4c3f41 Linus Torvalds 2005-04-16 37 if (memcmp(elf_ex.e_ident, ELFMAG, SELFMAG) != 0)
^1da177e4c3f41 Linus Torvalds 2005-04-16 38 return -ENOEXEC;
^1da177e4c3f41 Linus Torvalds 2005-04-16 39
^1da177e4c3f41 Linus Torvalds 2005-04-16 40 /* First of all, some simple consistency checks */
^1da177e4c3f41 Linus Torvalds 2005-04-16 41 if ((elf_ex.e_type != ET_EXEC && elf_ex.e_type != ET_DYN) ||
^1da177e4c3f41 Linus Torvalds 2005-04-16 42 (!((elf_ex.e_machine == EM_386) || (elf_ex.e_machine == EM_486))) ||
72c2d531920048 Al Viro 2013-09-22 43 !bprm->file->f_op->mmap) {
^1da177e4c3f41 Linus Torvalds 2005-04-16 44 return -ENOEXEC;
^1da177e4c3f41 Linus Torvalds 2005-04-16 45 }
^1da177e4c3f41 Linus Torvalds 2005-04-16 46
51f39a1f0cea1c David Drysdale 2014-12-12 47 /* Need to be able to load the file after exec */
51f39a1f0cea1c David Drysdale 2014-12-12 48 if (bprm->interp_flags & BINPRM_FLAGS_PATH_INACCESSIBLE)
51f39a1f0cea1c David Drysdale 2014-12-12 49 return -ENOENT;
51f39a1f0cea1c David Drysdale 2014-12-12 50
^1da177e4c3f41 Linus Torvalds 2005-04-16 51 /* Unlike in the script case, we don't have to do any hairy
^1da177e4c3f41 Linus Torvalds 2005-04-16 52 * parsing to find our interpreter... it's hardcoded!
^1da177e4c3f41 Linus Torvalds 2005-04-16 53 */
^1da177e4c3f41 Linus Torvalds 2005-04-16 54 interp = EM86_INTERP;
^1da177e4c3f41 Linus Torvalds 2005-04-16 55 i_name = EM86_I_NAME;
^1da177e4c3f41 Linus Torvalds 2005-04-16 56 i_arg = NULL; /* We reserve the right to add an arg later */
^1da177e4c3f41 Linus Torvalds 2005-04-16 57
^1da177e4c3f41 Linus Torvalds 2005-04-16 58 /*
^1da177e4c3f41 Linus Torvalds 2005-04-16 59 * Splice in (1) the interpreter's name for argv[0]
^1da177e4c3f41 Linus Torvalds 2005-04-16 60 * (2) (optional) argument to interpreter
^1da177e4c3f41 Linus Torvalds 2005-04-16 61 * (3) filename of emulated file (replace argv[0])
^1da177e4c3f41 Linus Torvalds 2005-04-16 62 *
^1da177e4c3f41 Linus Torvalds 2005-04-16 63 * This is done in reverse order, because of how the
^1da177e4c3f41 Linus Torvalds 2005-04-16 64 * user environment and arguments are stored.
^1da177e4c3f41 Linus Torvalds 2005-04-16 65 */
^1da177e4c3f41 Linus Torvalds 2005-04-16 @66 remove_arg_zero(bprm);
986db2d14a6dca Christoph Hellwig 2020-06-04 67 retval = copy_string_kernel(bprm->filename, bprm);
^1da177e4c3f41 Linus Torvalds 2005-04-16 68 if (retval < 0) return retval;
^1da177e4c3f41 Linus Torvalds 2005-04-16 69 bprm->argc++;
^1da177e4c3f41 Linus Torvalds 2005-04-16 70 if (i_arg) {
986db2d14a6dca Christoph Hellwig 2020-06-04 71 retval = copy_string_kernel(i_arg, bprm);
^1da177e4c3f41 Linus Torvalds 2005-04-16 72 if (retval < 0) return retval;
^1da177e4c3f41 Linus Torvalds 2005-04-16 73 bprm->argc++;
^1da177e4c3f41 Linus Torvalds 2005-04-16 74 }
986db2d14a6dca Christoph Hellwig 2020-06-04 75 retval = copy_string_kernel(i_name, bprm);
^1da177e4c3f41 Linus Torvalds 2005-04-16 76 if (retval < 0) return retval;
^1da177e4c3f41 Linus Torvalds 2005-04-16 77 bprm->argc++;
^1da177e4c3f41 Linus Torvalds 2005-04-16 78
^1da177e4c3f41 Linus Torvalds 2005-04-16 79 /*
^1da177e4c3f41 Linus Torvalds 2005-04-16 80 * OK, now restart the process with the interpreter's inode.
^1da177e4c3f41 Linus Torvalds 2005-04-16 81 * Note that we use open_exec() as the name is now in kernel
^1da177e4c3f41 Linus Torvalds 2005-04-16 82 * space, and we don't need to copy it.
^1da177e4c3f41 Linus Torvalds 2005-04-16 83 */
^1da177e4c3f41 Linus Torvalds 2005-04-16 84 file = open_exec(interp);
^1da177e4c3f41 Linus Torvalds 2005-04-16 85 if (IS_ERR(file))
^1da177e4c3f41 Linus Torvalds 2005-04-16 86 return PTR_ERR(file);
^1da177e4c3f41 Linus Torvalds 2005-04-16 87
bc2bf338d54b7a Eric W. Biederman 2020-05-18 88 bprm->interpreter = file;
bc2bf338d54b7a Eric W. Biederman 2020-05-18 89 return 0;
^1da177e4c3f41 Linus Torvalds 2005-04-16 90 }
^1da177e4c3f41 Linus Torvalds 2005-04-16 91 ---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
Am Fri, 19 Mar 2021 15:32:31 +0100
schrieb Olaf Hering <[email protected]>:
Quoted 1 line
It is a hard error if a return value is ignored.
The automated builds found only a single error, in load_em86().
Let me know if there are other reasons why the patch was rejected.
Olaf
Quoted 7 lines · Olaf Hering
Am Fri, 19 Mar 2021 15:32:31 +0100
schrieb Olaf Hering <[email protected]>:Quoted 1 line
It is a hard error if a return value is ignored.
The automated builds found only a single error, in
load_em86().
What about drivers/net/ethernet/lantiq_etop.c ?
Quoted 3 lines
Let me know if there are other reasons why the patch was rejected.
Olaf
I got a lot of complaints in the last trial.
It is easy to send a patch like this, but difficult to make sure that I will not break any CI tests.
Over time, I started to believe keeping this as a warning is OK.
The same problem happens when you add a new __must_check annotation. You end up with fixing all the call-sites in advance.
Signature · 2 lines
Best Regards Masahiro Yamada
Am Fri, 26 Mar 2021 01:55:41 +0900
schrieb Masahiro Yamada <[email protected]>:
Quoted 1 line
What about
drivers/net/ethernet/lantiq_etop.c?
Nothing complained about it. I guess there is a build-bot for alpha, but none for mips.
Quoted 1 line
I got a lot of complaints in the last trial.
Why did you get complains, instead of me?
What is the "must" in "__must_check" worth if it is not enforced...
Olaf
Quoted 8 lines · Olaf Hering
Am Fri, 26 Mar 2021 01:55:41 +0900
schrieb Masahiro Yamada <[email protected]>:Quoted 1 line
What about
drivers/net/ethernet/lantiq_etop.c?Nothing complained about it. I guess there is a build-bot for alpha, but none for mips.
Quoted 8 lines
Quoted 1 line
I got a lot of complaints in the last trial.
Why did you get complains, instead of me?
What is the "must" in "
__must_check" worth if it is not enforced...Olaf
In hindsight, __must_check may not be a perfect name.
Miguel suggested __nodiscard to get along with:
https://en.cppreference.com/w/c/language/attributes/nodiscard
It is not enforcing. Just a compiler warning.
Signature · 2 lines
Best Regards Masahiro Yamada