Skip to contentSkip to conversation

checkpatch: recognize FIXTURE_DATA() and FIXTURE_VARIANT() as types

PATCH In review HONG Yifan 2 participants 3 messages Nov 17 – Nov 18 Checkpatch

lore
Share & tools
lore

HONG Yifan

author
#0 lore raw

PATCH 1/1 checkpatch: recognize FIXTURE_DATA() and FIXTURE_VARIANT() as types

tools/testing/selftests/kselftest_harness.h defines FIXTURE_DATA() and FIXTURE_VARIANT() to expand to struct type specifiers ("struct _test_data_##datatype_name" and
"struct _fixture_variant_##fixture_name").

Because checkpatch.pl does not recognize these function-like macros in $NonptrType or $NonptrTypeWithAttr, annotate_values() parses them as function calls and tags a following '*' as a binary multiplication operator instead of a pointer declarator. This triggers false-positive errors across kselftests whenever helper functions take pointers to fixture data or variants (over 150 sites in tools/testing/selftests/), for example on commit d2b82fa39fda ("selftests/mm: add a GUP selftest"):

ERROR:SPACING: need consistent spacing around '*' (ctx:WxV) #319: FILE: tools/testing/selftests/mm/gup.c:191:
+ FIXTURE_DATA(gup_test) *self,

Add FIXTURE_DATA(...) and FIXTURE_VARIANT(...) to $NonptrType and $NonptrTypeWithAttr in build_types(), alongside typeof() and __typeof__(). Valid pointer declarations and casts no longer emit false SPACING errors, while malformed pointer placement (such as "FIXTURE_DATA(foo)* p" or "(FIXTURE_DATA(foo)*)p") is flagged by POINTER_LOCATION.

---
 scripts/checkpatch.pl | 2 ++
 1 file changed, 2 insertions(+)
scripts/checkpatch.pl +2 -0
index b8b64f720191..f1695f20a7d2 100755
@@ -1067,6 +1067,7 @@ sub build_types {
 			(?:$Modifier\s+|const\s+)*
 			(?:
 				(?:typeof|__typeof__)\s*\([^\)]*\)|
+				(?:FIXTURE_DATA|FIXTURE_VARIANT)\s*\([^\)]*\)|
 				(?:$typeTypedefs\b)|
 				(?:${all}\b)
 			)
@@ -1083,6 +1084,7 @@ sub build_types {
 			(?:$Modifier\s+|const\s+)*
 			(?:
 				(?:typeof|__typeof__)\s*\([^\)]*\)|
+				(?:FIXTURE_DATA|FIXTURE_VARIANT)\s*\([^\)]*\)|
 				(?:$typeTypedefs\b)|
 				(?:${allWithAttr}\b)
 			)
Signature · 1 line
2.56.1.703.gf848ed807c-goog
maintainer
#1 lore raw
Quoted 4 lines · HONG Yifan

tools/testing/selftests/kselftest_harness.h defines FIXTURE_DATA() and FIXTURE_VARIANT() to expand to struct type specifiers ("struct _test_data_##datatype_name" and
"struct _fixture_variant_##fixture_name").

NAK. This sort of stuff needs to be externalized.

#2 lore raw
Quoted 8 lines · Joe Perches
Quoted 4 lines · HONG Yifan

tools/testing/selftests/kselftest_harness.h defines FIXTURE_DATA() and FIXTURE_VARIANT() to expand to struct type specifiers ("struct _test_data_##datatype_name" and
"struct _fixture_variant_##fixture_name").

NAK. This sort of stuff needs to be externalized.

Thanks for the review. By "externalize", I assume you mean the pattern in
https://lore.kernel.org/all/e5a8da43e7c11525bafbda1ca69a8323614dd942.1472664220.git.joe@perches.com/
commit bf1fa1dae68e ("checkpatch: externalize the structs that should be const") so that I should put an autoloaded file listing function-like macros that expand to types. Is that what you mean?

Assuming that's the case, I'll prepare a v2 of the patch.