005-v5.17-01-Kbuild-use-Wdeclaration-after-statement.patch 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. From 2fd7e7f9317d3048a14026816d081b08ba98ea8e Mon Sep 17 00:00:00 2001
  2. From: Mark Rutland <[email protected]>
  3. Date: Tue, 8 Mar 2022 22:56:13 +0100
  4. Subject: [PATCH 1/3] Kbuild: use -Wdeclaration-after-statement
  5. The kernel is moving from using `-std=gnu89` to `-std=gnu11`, permitting
  6. the use of additional C11 features such as for-loop initial declarations.
  7. One contentious aspect of C99 is that it permits mixed declarations and
  8. code, and for now at least, it seems preferable to enforce that
  9. declarations must come first.
  10. These warnings were already enabled in the kernel itself, but not
  11. for KBUILD_USERCFLAGS or the compat VDSO on arch/arm64, which uses
  12. a separate set of CFLAGS.
  13. This patch fixes an existing violation in modpost.c, which is not
  14. reported because of the missing flag in KBUILD_USERCFLAGS:
  15. | scripts/mod/modpost.c: In function ‘match’:
  16. | scripts/mod/modpost.c:837:3: warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement]
  17. | 837 | const char *endp = p + strlen(p) - 1;
  18. | | ^~~~~
  19. Signed-off-by: Mark Rutland <[email protected]>
  20. [arnd: don't add a duplicate flag to the default set, update changelog]
  21. Signed-off-by: Arnd Bergmann <[email protected]>
  22. Reviewed-by: Nathan Chancellor <[email protected]>
  23. Reviewed-by: Nick Desaulniers <[email protected]>
  24. Tested-by: Sedat Dilek <[email protected]> # LLVM/Clang v13.0.0 (x86-64)
  25. Signed-off-by: Masahiro Yamada <[email protected]>
  26. ---
  27. Makefile | 3 ++-
  28. arch/arm64/kernel/vdso32/Makefile | 1 +
  29. scripts/mod/modpost.c | 4 +++-
  30. 3 files changed, 6 insertions(+), 2 deletions(-)
  31. --- a/Makefile
  32. +++ b/Makefile
  33. @@ -440,7 +440,8 @@ endif
  34. HOSTPKG_CONFIG = pkg-config
  35. export KBUILD_USERCFLAGS := -Wall -Wmissing-prototypes -Wstrict-prototypes \
  36. - -O2 -fomit-frame-pointer -std=gnu89
  37. + -O2 -fomit-frame-pointer -std=gnu89 \
  38. + -Wdeclaration-after-statement
  39. export KBUILD_USERLDFLAGS :=
  40. KBUILD_HOSTCFLAGS := $(KBUILD_USERCFLAGS) $(HOST_LFS_CFLAGS) $(HOSTCFLAGS)
  41. --- a/arch/arm64/kernel/vdso32/Makefile
  42. +++ b/arch/arm64/kernel/vdso32/Makefile
  43. @@ -76,6 +76,7 @@ VDSO_CFLAGS += -Wall -Wundef -Wstrict-pr
  44. -fno-strict-aliasing -fno-common \
  45. -Werror-implicit-function-declaration \
  46. -Wno-format-security \
  47. + -Wdeclaration-after-statement \
  48. -std=gnu89
  49. VDSO_CFLAGS += -O2
  50. # Some useful compiler-dependent flags from top-level Makefile
  51. --- a/scripts/mod/modpost.c
  52. +++ b/scripts/mod/modpost.c
  53. @@ -833,8 +833,10 @@ static int match(const char *sym, const
  54. {
  55. const char *p;
  56. while (*pat) {
  57. + const char *endp;
  58. +
  59. p = *pat++;
  60. - const char *endp = p + strlen(p) - 1;
  61. + endp = p + strlen(p) - 1;
  62. /* "*foo*" */
  63. if (*p == '*' && *endp == '*') {