From: Masahiro Yamada Date: Sun, 1 Jun 2025 13:31:30 +0000 (+0900) Subject: scripts/misc-check: check unnecessary #include when W=1 X-Git-Tag: v6.16-rc1~10^2~5 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=7d95680d64ac8e836c35fd56efe77eac4e9cc26b;p=thirdparty%2Flinux.git scripts/misc-check: check unnecessary #include when W=1 Another issue with is that it is sometimes included even when EXPORT_SYMBOL() is not used at all. Some headers (e.g. include/linux/linkage.h>) cannot be fixed for now for the reason described in the previous commit. This commit adds a warning for *.c files that include but do not use EXPORT_SYMBOL() when the kernel is built with W=1. Signed-off-by: Masahiro Yamada --- diff --git a/scripts/misc-check b/scripts/misc-check index 7cb61841a125..a74450e799d1 100755 --- a/scripts/misc-check +++ b/scripts/misc-check @@ -51,5 +51,17 @@ check_missing_include_linux_export_h () { xargs -r printf "%s: warning: EXPORT_SYMBOL() is used, but #include is missing\n" >&2 } +# If you do not use EXPORT_SYMBOL(), please do not include . +# Currently, this is checked for *.c files, but not for *.h files, because some +# *.c files rely on being included indirectly. +check_unnecessary_include_linux_export_h () { + + git -C "${srctree:-.}" grep --files-with-matches '#include[[:space:]]*' \ + -- '*.[c]' :^tools/ | + xargs -r git -C "${srctree:-.}" grep --files-without-match -E 'EXPORT_SYMBOL((_NS)?(_GPL)?|_GPL_FOR_MODULES)\(.*\)' | + xargs -r printf "%s: warning: EXPORT_SYMBOL() is not used, but #include is present\n" >&2 +} + check_tracked_ignored_files check_missing_include_linux_export_h +check_unnecessary_include_linux_export_h