On Wed, Feb 04, 2026 at 08:59:17AM -0800, Stephen Hemminger wrote:
> Alternative to the checkpatches.sh shell script that wraps the Linux kernel's
> checkpatch.pl with a standalone Python implementation. The new
> dpdk-checkpatch.py script provides equivalent functionality without
> requiring the kernel source tree or Perl.
> 
> Performance is significantly improved: checking a recent flow parser
> patch series dropped from 2m23s to 0.43s (approximately 300x faster).
> 
> Supports checking individual patch files, mbox bundles containing
> multiple patches, git commit ranges (-r), last N commits (-n), or
> reading from stdin. Exit code is 0 if all patches are clean,
> 1 if any have issues.
> 
> Kernel checkpatch.pl compatible checks:
>   - AVOID_EXTERNS, UNNECESSARY_BREAK, COMPLEX_MACRO
>   - STRNCPY/STRCPY, RETURN_PARENTHESES, POINTER_LOCATION
>   - INITIALISED_STATIC, GLOBAL_INITIALISERS
>   - TRAILING_STATEMENTS, LINE_CONTINUATIONS, ONE_SEMICOLON
>   - REPEATED_WORD, CONSTANT_COMPARISON, SELF_ASSIGNMENT
>   - INLINE_LOCATION, STORAGE_CLASS, FUNCTION_WITHOUT_ARGS
>   - MACRO_WITH_FLOW_CONTROL, MULTISTATEMENT_MACRO_USE_DO_WHILE
>   - PREFER_DEFINED_ATTRIBUTE_MACRO (using DPDK __rte_* macros)
>   - TYPO_SPELLING via codespell dictionary
> 
> DPDK-specific forbidden token checks:
>   - RTE_LOG usage (prefer RTE_LOG_LINE)
>   - printf/fprintf to stdout/stderr in libs/drivers
>   - rte_panic/rte_exit, direct __attribute__ usage
>   - Deprecated atomics (rte_atomicNN_xxx, rte_smp_[rw]mb)
>   - Compiler builtins (__sync_xxx, __atomic_xxx, __builtin_xxx)
>   - pthread functions (prefer rte_thread)
>   - Reserved keywords, pragma, variadic macros
> 
> DPDK tag validation:
>   - __rte_experimental and __rte_internal placement
>   - __rte_packed_begin/end pairing
>   - __rte_aligned attribute checking
> 
> Expected differences from the shell/Perl version:
> 
> The following checks from checkpatch.pl are intentionally not
> implemented because they produced false positives on valid DPDK code:
> 
>   - DEEP_INDENTATION: tab counting without full brace-nesting
>     tracking flags legitimate patterns in switch/case blocks and
>     driver transmit paths.
>   - CAMELCASE: flags standard C macros like PRIx64 and DPDK
>     naming conventions.
>   - SPACING after cast: flags RTE_ATOMIC() macro as a cast and
>     flags unary minus in (type)-1 expressions.
>   - CONCATENATED_STRING: flags valid C format string macros
>     like "%"PRIx64.
> 
> The following checks have improved behavior:
> 
>   - AVOID_EXTERNS only flags function declarations, not data.
>     Using extern on data declarations is sometimes necessary
>     and does not need a warning.
>   - COMPLEX_MACRO does not flag C99 compound literal macros
>     like (const type[]){ ... } which are commonly used in DPDK.
>   - RETURN_PARENTHESES does not flag return with casts such
>     as return (uint16_t)(expr).
>   - TYPO_SPELLING excludes common networking abbreviations
>     (ND, NS, etc.) and Doxygen tags, and handles contractions
>     (don't, couldn't) without false positives.
>   - LINE_CONTINUATIONS properly tracks macro context across
>     patch context lines.
> 
> Known limitations:
>   - BRACES check not implemented (requires multi-line analysis)
>   - COMMIT_LOG_LONG_LINE not implemented
> 
> This script was developed with assistance from the Claude AI assistant.
> 
> Signed-off-by: Stephen Hemminger <[email protected]>
> ---
>  devtools/dpdk-checkpatch.py | 1381 +++++++++++++++++++++++++++++++++++
>  1 file changed, 1381 insertions(+)
>  create mode 100755 devtools/dpdk-checkpatch.py
> 
Acked-by: Bruce Richardson <[email protected]>

A minor nit, but this could do with running black on it to reformat it
according to standard rules, and to limit line lengths to 100 chars.
(Running the script on its own commit throws up long line errors as well as
a bunch of false positives)

Reply via email to