This project includes comprehensive static analysis and code formatting tools to ensure high code quality and compliance with Linux kernel coding standards.
All tools and hooks are automatically installed and configured in the dev container. No manual setup required!
make format # Format all source files
make format-check # Check if code is properly formatted (CI-friendly)
make check # Run all static analysis checks
make checkpatch # Kernel coding style
make sparse # Kernel static analysis
make cppcheck # General C/C++ analysis
CPPCHECK_JOBS=8 make cppcheck # Optional: control cppcheck parallelismPurpose: Automatic code formatting
Standard: Linux kernel coding style
Configuration: .clang-format
Features:
- 8-space tabs (kernel standard)
- 100-column line limit (relaxed kernel baseline used by this project)
- Linux brace style
- Consistent spacing and alignment
Purpose: Kernel coding style compliance
Source: Official Linux kernel scripts
Note:
- checkpatch.pl requires kernel headers for the running kernel.
- The dev container post-create script installs
linux-headers-$(uname -r)to avoid version mismatches.
Checks:
- Indentation and spacing rules
- Line length limits (warns above 80 columns; project uses a 100-column limit)
- Function declaration style
- Comment formatting (/* */ style)
- Macro usage patterns
- Variable naming conventions
Project usage:
make checkpatchrunscheckpatch.pl --no-tree --strict --fileon allsrc/*.candsrc/*.h- The pre-commit hook runs checkpatch on staged
*.cand*.hfiles
Purpose: Semantic analysis for C code
Specialty: Kernel-specific checks
Detects:
- Type confusion errors
- Endianness issues (
__be32,__le32) - Lock context imbalances
- Address space mismatches (
__user,__kernel) - Null pointer dereferences
Purpose: General C/C++ static analysis
Configuration: .cppcheck-suppressions
Detects:
- Memory leaks
- Buffer overflows
- Uninitialized variables
- Dead code
- Logic errors
.clang-format- Code formatting rules (Linux kernel style).cppcheck-suppressions- Suppression list for false positives.editorconfig- Editor configuration for consistent coding style
Pre-commit hooks are automatically installed on container startup.
The pre-commit hook runs:
- Code formatting checks
- Cppcheck static analysis
- Checkpatch validation for staged C/header files
Hook location: .github/pre-commit.sh
To bypass hooks (use sparingly):
git commit --no-verify -m "message"Follow Linux Kernel Coding Style:
- Use tabs (8 spaces), not spaces for indentation
- 100 column limit for code (project baseline; checkpatch warns above 80)
- Opening brace on same line (except functions)
- Space after keywords:
if (,while (,for ( - No space after function names:
function(arg) - Use C89-style comments:
/* comment */
Example:
int example_function(int param)
{
if (param > 0) {
/* Comment style: C89 */
return param * 2;
}
return 0;
}# Everything is ready - just start coding!
# Format code before committing
make format
# Run all checks
make check
# Optional stricter local gate before opening PR
make format-check && make checkpatch && make sparse && make cppcheck
# Commit (hooks run automatically)
git commit -m "Your message"make checkis a convenience aggregator for static analysis output.- Some tool invocations in the Makefile are best-effort (
|| true) to keep developer flow smooth. - For release/PR readiness, treat any checkpatch/sparse/cppcheck findings as actionable and resolve them.