Another issue with <linux/export.h> 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 <linux/export.h> but do not use EXPORT_SYMBOL() when the kernel is built with W=1.
Unified · Split
| @@ -51,5 +51,17 @@ check_missing_include_linux_export_h () { · 50 unmodified lines | |||
| 51 | xargs -r printf "%s: warning: EXPORT_SYMBOL() is used, but #include <linux/export.h> is missing\n" >&2 | 51 | xargs -r printf "%s: warning: EXPORT_SYMBOL() is used, but #include <linux/export.h> is missing\n" >&2 |
| 52 | } | 52 | } |
| 53 | 53 | ||
| 54 | # If you do not use EXPORT_SYMBOL(), please do not include <linux/export.h>. | ||
| 55 | # Currently, this is checked for *.c files, but not for *.h files, because some | ||
| 56 | # *.c files rely on <linux/export.h> being included indirectly. | ||
| 57 | check_unnecessary_include_linux_export_h () { | ||
| 58 | |||
| 59 | git -C "${srctree:-.}" grep --files-with-matches '#include[[:space:]]*<linux/export\.h>' \ | ||
| 60 | -- '*.[c]' :^tools/ | | ||
| 61 | xargs -r git -C "${srctree:-.}" grep --files-without-match -E 'EXPORT_SYMBOL((_NS)?(_GPL)?|_GPL_FOR_MODULES)\(.*\)' | | ||
| 62 | xargs -r printf "%s: warning: EXPORT_SYMBOL() is not used, but #include <linux/export.h> is present\n" >&2 | ||
| 63 | } | ||
| 64 | |||
| 54 | check_tracked_ignored_files | 65 | check_tracked_ignored_files |
| 55 | check_missing_include_linux_export_h | 66 | check_missing_include_linux_export_h |
| 67 | check_unnecessary_include_linux_export_h | ||