Skip to content

Silence some instances of -Wtautological-compare and enable globally

Nathan Chancellor linux-arch linux-kbuild linux-mm lkml 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest6 patches 11 repliesIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/6asm/sections: Add COMPARE_SECTIONS macroinclude/asm-generic/sections.h+7 -00 replies
2/6kernel/extable: Wrap section comparison in sort_main_extable with COMPARE_SECTIONSkernel/extable.c+2 -10 replies
3/6tracing: Wrap section comparison in tracer_alloc_buffers with COMPARE_SECTIONSkernel/trace/trace.c+1 -19 replies
4/6dynamic_debug: Wrap section comparison in dynamic_debug_init with COMPARE_SECTIONSlib/dynamic_debug.c+1 -10 replies
5/6mm: kmemleak: Wrap section comparison in kmemleak_init with COMPARE_SECTIONSmm/kmemleak.c+2 -10 replies
6/6kbuild: Enable -Wtautological-compareMakefile+1 -20 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.

Read the v1 thread

Cover letter [PATCH 0/6] Silence some instances of -Wtautological-compare and enable globally

Hi everyone,

This patch series aims to silence some instances of clang's -Wtautological-compare that are not problematic and enable it globally for the kernel because it has a bunch of subwarnings that can find real bugs in the kernel such as
https://lore.kernel.org/lkml/[email protected]/
and https://bugs.llvm.org/show_bug.cgi?id=42666, which was specifically requested by Dmitry.

The first patch adds a macro that casts the section variables to unsigned long (uintptr_t), which silences the warning and adds documentation.

Patches two through four silence the warning in the places I have noticed it across all of my builds with -Werror, including arm, arm64, and x86_64 defconfig/allmodconfig/allyesconfig. There might still be more lurking but those will have to be teased out over time.

Patch six finally enables the warning, while leaving one of the subwarnings disabled because it is rather noisy and somewhat pointless for the kernel, where core kernel code is expected to build and run with many different configurations where variable types can be different sizes.

A slight meta comment: This is the first treewide patchset that I have sent. I pray I did everything right but please let me know if I did not. I assume someone like Andrew will pick this up with acks from everyone but let me know if there is someone better.

Cheers,
Nathan

Nathan Chancellor (6):
asm/sections: Add COMPARE_SECTIONS macro kernel/extable: Wrap section comparison in sort_main_extable with
COMPARE_SECTIONS
tracing: Wrap section comparison in tracer_alloc_buffers with
COMPARE_SECTIONS
dynamic_debug: Wrap section comparison in dynamic_debug_init with
COMPARE_SECTIONS
mm: kmemleak: Wrap section comparison in kmemleak_init with
COMPARE_SECTIONS
kbuild: Enable -Wtautological-compare

 Makefile                       | 3 +--
 include/asm-generic/sections.h | 7 +++++++
 kernel/extable.c               | 3 ++-
 kernel/trace/trace.c           | 2 +-
 lib/dynamic_debug.c            | 2 +-
 mm/kmemleak.c                  | 3 ++-
 6 files changed, 14 insertions(+), 6 deletions(-)

base-commit: 02815e777db630e3c183718cab73752b48a5053e

Signature · 1 line
2.25.1