Skip to contentSkip to conversation

checkpatch: Add check for array allocator family argument order

PATCH Superseded Liao Chang 2 participants 2 messages Nov 4, 2022 Checkpatch

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Liao Chang

author
#0 lore raw

PATCH 1/1 checkpatch: Add check for array allocator family argument order

These array allocator family are sometimes misused with the first and second arguments switchted.

Same issue with calloc, kvcalloc, kvmalloc_array etc.

Bleat if sizeof is the first argument.

---
 scripts/checkpatch.pl | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/checkpatch.pl +1 -1
index 1e5e66ae5a52..a9a9dc277cff 100755
@@ -7128,7 +7128,7 @@ sub process {
 		}
 
 # check for alloc argument mismatch
-		if ($line =~ /\b((?:devm_)?(?:kcalloc|kmalloc_array))\s*\(\s*sizeof\b/) {
+		if ($line =~ /\b((?:devm_)?((?:k|kv)?(calloc|malloc_array)(?:_node)?))\s*\(\s*sizeof\b/) {
 			WARN("ALLOC_ARRAY_ARGS",
 			     "$1 uses number as first arg, sizeof is generally wrong\n" . $herecurr);
 		}
Signature · 1 line
2.17.1
maintainer Acked-by on v1 1/1
#1 lore raw
Quoted 8 lines · Liao Chang

These array allocator family are sometimes misused with the first and second arguments switchted.

Same issue with calloc, kvcalloc, kvmalloc_array etc.

Bleat if sizeof is the first argument.

You might use the -next version of checkpatch on this and find out it's generally better to use lore links like:

https://lore.kernel.org/lkml/[email protected]/

Quoted 1 line

cheers, Joe

Quoted 17 lines
---
 scripts/checkpatch.pl | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/checkpatch.pl +1 -1
index 1e5e66ae5a52..a9a9dc277cff 100755
@@ -7128,7 +7128,7 @@ sub process {
 		}
 
 # check for alloc argument mismatch
-		if ($line =~ /\b((?:devm_)?(?:kcalloc|kmalloc_array))\s*\(\s*sizeof\b/) {
+		if ($line =~ /\b((?:devm_)?((?:k|kv)?(calloc|malloc_array)(?:_node)?))\s*\(\s*sizeof\b/) {
 			WARN("ALLOC_ARRAY_ARGS",
 			     "$1 uses number as first arg, sizeof is generally wrong\n" . $herecurr);
 		}