checkpatch: Add context-analysis attributes
PATCH v2 1/1 checkpatch: Add context-analysis attributes
Checkpatch doesn't know about the context-analysis attributes and misparses annotated declarations (e.g. mistaking __guarded_by() fields for extern prototypes). Add them to the known attributes list with support for a single nested set of parentheses.
Handle context-analysis attributes with parentheses like __attribute__ in annotate_values() so unary '&' in their arguments is not mistaken for binary bitwise AND.
--- scripts/checkpatch.pl | 37 ++++++++++++++++++++++++++++++++----- 1 file changed, 32 insertions(+), 5 deletions(-)
scripts/checkpatch.pl +32 -5
@@ -527,6 +527,32 @@ our $InitAttributeConst = qr{$InitAttributePrefix(?:initconst\b)}; our $InitAttributeInit = qr{$InitAttributePrefix(?:init\b)}; our $InitAttribute = qr{$InitAttributeData|$InitAttributeConst|$InitAttributeInit}; +# Match (...) attribute arguments, allowing one level of nested parens +# (e.g. __guarded_by(__bitlock(3, &bits))). +our $AttrParens = qr{\s*\((?:[^()]++|\([^()]*+\))*+\)}; +our $ContextAnalysisWithArgs = qr{ + __guarded_by| + __pt_guarded_by| + __must_hold| + __must_hold_shared| + __must_not_hold| + __acquires| + __acquires_shared| + __cond_acquires| + __cond_acquires_shared| + __releases| + __releases_shared| + __cond_releases| + __context_unsafe + }x; +our $ContextAnalysis = qr{ + (?:$ContextAnalysisWithArgs)$AttrParens| + __rcu_guarded\b| + __no_context_analysis\b| + __acquires_ret\b| + __acquires_shared_ret\b + }x; + # Notes to $Attribute: # We need \b after 'init' otherwise 'initconst' will cause a false positive in a check our $Attribute = qr{
@@ -551,6 +577,7 @@ our $Attribute = qr{ __ro_after_init| __kprobes| $InitAttribute| + $ContextAnalysis| __aligned\s*\(.*\)| ____cacheline_aligned| ____cacheline_aligned_in_smp|
@@ -2141,6 +2168,11 @@ sub annotate_values { push(@av_paren_type, $type); $type = 'c'; + } elsif ($cur =~ /^(__attribute__|$ContextAnalysisWithArgs)\b\s*\(?/o) { + print "ATTR($1)\n" if ($dbg_values > 1); + $av_pending = $type; + $type = 'N'; + } elsif ($cur =~ /^($Type)\s*(?:$Ident|,|\)|\(|\s*$)/) { print "DECLARE($1)\n" if ($dbg_values > 1); $type = 'T';
@@ -2193,11 +2225,6 @@ sub annotate_values { } elsif ($cur =~ /^(\\\n)/o) { print "PRECONT($1)\n" if ($dbg_values > 1); - } elsif ($cur =~ /^(__attribute__)\s*\(?/o) { - print "ATTR($1)\n" if ($dbg_values > 1); - $av_pending = $type; - $type = 'N'; - } elsif ($cur =~ /^(sizeof)\s*(\()?/o) { print "SIZEOF($1)\n" if ($dbg_values > 1); if (defined $2) {
base-commit: 6628e7d4c6b25c8d18f1345e3a20d21829aae7e4
Signature · 1 line
2.56.1.703.gf848ed807c-goog
Quoted 6 lines · Vincent Donnefort
Checkpatch doesn't know about the context-analysis attributes and misparses annotated declarations (e.g. mistaking
__guarded_by()fields for extern prototypes). Add them to the known attributes list with support for a single nested set of parentheses.
Quoted 6 lines
Handle context-analysis attributes with parentheses like
__attribute__inannotate_values()so unary '&' in their arguments is not mistaken for binary bitwise AND.Cc Marco Elver <[email protected]>Signed-off-by Vincent Donnefort <[email protected]>
Quoted 78 lines
--- scripts/checkpatch.pl | 37 ++++++++++++++++++++++++++++++++----- 1 file changed, 32 insertions(+), 5 deletions(-)scripts/checkpatch.pl +32
-5@@ -527,6 +527,32 @@ our $InitAttributeConst = qr{$InitAttributePrefix(?:initconst\b)}; our $InitAttributeInit = qr{$InitAttributePrefix(?:init\b)}; our $InitAttribute = qr{$InitAttributeData|$InitAttributeConst|$InitAttributeInit}; +# Match (...) attribute arguments, allowing one level of nested parens +# (e.g. __guarded_by(__bitlock(3, &bits))). +our $AttrParens = qr{\s*\((?:[^()]++|\([^()]*+\))*+\)}; +our $ContextAnalysisWithArgs = qr{ + __guarded_by| + __pt_guarded_by| + __must_hold| + __must_hold_shared| + __must_not_hold| + __acquires| + __acquires_shared| + __cond_acquires| + __cond_acquires_shared| + __releases| + __releases_shared| + __cond_releases| + __context_unsafe + }x; +our $ContextAnalysis = qr{ + (?:$ContextAnalysisWithArgs)$AttrParens| + __rcu_guarded\b| + __no_context_analysis\b| + __acquires_ret\b| + __acquires_shared_ret\b + }x; + # Notes to $Attribute: # We need \b after 'init' otherwise 'initconst' will cause a false positive in a check our $Attribute = qr{@@ -551,6 +577,7 @@ our $Attribute = qr{ __ro_after_init| __kprobes| $InitAttribute| + $ContextAnalysis| __aligned\s*\(.*\)| ____cacheline_aligned| ____cacheline_aligned_in_smp|@@ -2141,6 +2168,11 @@ sub annotate_values { push(@av_paren_type, $type); $type = 'c'; + } elsif ($cur =~ /^(__attribute__|$ContextAnalysisWithArgs)\b\s*\(?/o) { + print "ATTR($1)\n" if ($dbg_values > 1); + $av_pending = $type; + $type = 'N'; + } elsif ($cur =~ /^($Type)\s*(?:$Ident|,|\)|\(|\s*$)/) { print "DECLARE($1)\n" if ($dbg_values > 1); $type = 'T';@@ -2193,11 +2225,6 @@ sub annotate_values { } elsif ($cur =~ /^(\\\n)/o) { print "PRECONT($1)\n" if ($dbg_values > 1); - } elsif ($cur =~ /^(__attribute__)\s*\(?/o) { - print "ATTR($1)\n" if ($dbg_values > 1); - $av_pending = $type; - $type = 'N'; - } elsif ($cur =~ /^(sizeof)\s*(\()?/o) { print "SIZEOF($1)\n" if ($dbg_values > 1); if (defined $2) {base-commit:
6628e7d4c6b25c8d18f1345e3a20d21829aae7e4--
2.56.1.703.gf848ed807c-goog
Quoted 11 lines · Vincent Donnefort
Checkpatch doesn't know about the context-analysis attributes and misparses annotated declarations (e.g. mistaking
__guarded_by()fields for extern prototypes). Add them to the known attributes list with support for a single nested set of parentheses.Handle context-analysis attributes with parentheses like
__attribute__inannotate_values()so unary '&' in their arguments is not mistaken for binary bitwise AND.Cc Marco Elver <[email protected]>Signed-off-by Vincent Donnefort <[email protected]>
regards,
Marc
Signature · 4 lines
Pengutronix e.K. | Marc Kleine-Budde | Embedded Linux | https://www.pengutronix.de | Vertretung Nürnberg | Phone: +49-5121-206917-129 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-9 |