[PATCH] devtools: check uAPI headers inclusions
David Marchand
david.marchand at redhat.com
Tue Nov 3 08:59:33 CET 2026
Imported Linux kernel uAPI headers must be included before any other
header to avoid a system-installed header being read instead.
Add a check that runs after every operation to catch files where
Linux uapi includes are preceded by other includes.
Signed-off-by: David Marchand <david.marchand at redhat.com>
---
devtools/linux-uapi.sh | 25 +++++++++++++++++++++++++
1 file changed, 25 insertions(+)
diff --git a/devtools/linux-uapi.sh b/devtools/linux-uapi.sh
index 3f804685aa..d03b43a0aa 100755
--- a/devtools/linux-uapi.sh
+++ b/devtools/linux-uapi.sh
@@ -138,6 +138,29 @@ check_header()
return 0
}
+check_include_order()
+{
+ local errors=0
+
+ $quiet || echo "Checking uapi/linux inclusion order"
+ for filename in $(git grep -l '#include <uapi/linux/' ':!devtools/linux-uapi.sh' \
+ ':!doc/guides/contributing/linux_uapi.rst' ':!kernel/linux/uapi/'); do
+ last_uapi=$(grep -n '#include <uapi/linux/' "$filename" | tail -1 | cut -d: -f1)
+ first_other=$(grep -n '^#include' "$filename" | grep -v 'uapi/linux/' |
+ head -1 | cut -d: -f1)
+ if [ -z "$first_other" ] || [ "$first_other" -gt "$last_uapi" ]; then
+ continue;
+ fi
+ $quiet || echo "$filename: uapi headers must be included before other headers"
+ errors=$((errors + 1))
+ done
+ if [ $errors -ne 0 ] || ! $quiet; then
+ echo "$errors error(s) found in uapi inclusion order"
+ fi
+
+ return $errors
+}
+
check_all()
{
local errors=0
@@ -192,3 +215,5 @@ if $check_headers; then
else
update_all
fi
+
+check_include_order
--
2.56.0
More information about the dev
mailing list