Commit 73f1d07e authored by Gustavo A. R. Silva's avatar Gustavo A. R. Silva
Browse files

checkpatch: add new alloc functions to alloc with multiplies check

kvmalloc() and kvzalloc() functions have now 2-factor multiplication
argument forms kvmalloc_array() and kvcalloc(), correspondingly.

Add alloc-with-multiplies checks for these new functions.

Link: https://github.com/KSPP/linux/issues/187


Signed-off-by: default avatarGustavo A. R. Silva <gustavoars@kernel.org>
parent ce522ba9
Loading
Loading
Loading
Loading
+5 −3
Original line number Original line Diff line number Diff line
@@ -7033,14 +7033,16 @@ sub process {
			    "Prefer $3(sizeof(*$1)...) over $3($4...)\n" . $herecurr);
			    "Prefer $3(sizeof(*$1)...) over $3($4...)\n" . $herecurr);
		}
		}


# check for k[mz]alloc with multiplies that could be kmalloc_array/kcalloc
# check for (kv|k)[mz]alloc with multiplies that could be kmalloc_array/kvmalloc_array/kvcalloc/kcalloc
		if ($perl_version_ok &&
		if ($perl_version_ok &&
		    defined $stat &&
		    defined $stat &&
		    $stat =~ /^\+\s*($Lval)\s*\=\s*(?:$balanced_parens)?\s*(k[mz]alloc)\s*\(\s*($FuncArg)\s*\*\s*($FuncArg)\s*,/) {
		    $stat =~ /^\+\s*($Lval)\s*\=\s*(?:$balanced_parens)?\s*((?:kv|k)[mz]alloc)\s*\(\s*($FuncArg)\s*\*\s*($FuncArg)\s*,/) {
			my $oldfunc = $3;
			my $oldfunc = $3;
			my $a1 = $4;
			my $a1 = $4;
			my $a2 = $10;
			my $a2 = $10;
			my $newfunc = "kmalloc_array";
			my $newfunc = "kmalloc_array";
			$newfunc = "kvmalloc_array" if ($oldfunc eq "kvmalloc");
			$newfunc = "kvcalloc" if ($oldfunc eq "kvzalloc");
			$newfunc = "kcalloc" if ($oldfunc eq "kzalloc");
			$newfunc = "kcalloc" if ($oldfunc eq "kzalloc");
			my $r1 = $a1;
			my $r1 = $a1;
			my $r2 = $a2;
			my $r2 = $a2;
@@ -7057,7 +7059,7 @@ sub process {
					 "Prefer $newfunc over $oldfunc with multiply\n" . $herectx) &&
					 "Prefer $newfunc over $oldfunc with multiply\n" . $herectx) &&
				    $cnt == 1 &&
				    $cnt == 1 &&
				    $fix) {
				    $fix) {
					$fixed[$fixlinenr] =~ s/\b($Lval)\s*\=\s*(?:$balanced_parens)?\s*(k[mz]alloc)\s*\(\s*($FuncArg)\s*\*\s*($FuncArg)/$1 . ' = ' . "$newfunc(" . trim($r1) . ', ' . trim($r2)/e;
					$fixed[$fixlinenr] =~ s/\b($Lval)\s*\=\s*(?:$balanced_parens)?\s*((?:kv|k)[mz]alloc)\s*\(\s*($FuncArg)\s*\*\s*($FuncArg)/$1 . ' = ' . "$newfunc(" . trim($r1) . ', ' . trim($r2)/e;
				}
				}
			}
			}
		}
		}