Skip to content

Commit 52ea850

Browse files
JoePerchestorvalds
authored andcommitted
checkpatch: add test for #defines of ARCH_HAS_<foo>
Add a test for these #defines Additionally, moved string_find_replace sub as it screws up subsequent formatting when placed inside another sub. Signed-off-by: Joe Perches <joe@perches.com> Suggested-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 11ea516 commit 52ea850

1 file changed

Lines changed: 14 additions & 8 deletions

File tree

‎scripts/checkpatch.pl‎

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1514,6 +1514,14 @@ sub rtrim {
15141514
return $string;
15151515
}
15161516

1517+
sub string_find_replace {
1518+
my ($string, $find, $replace) = @_;
1519+
1520+
$string =~ s/$find/$replace/g;
1521+
1522+
return $string;
1523+
}
1524+
15171525
sub tabify {
15181526
my ($leading) = @_;
15191527

@@ -3733,14 +3741,6 @@ sub process {
37333741
}
37343742
}
37353743

3736-
sub string_find_replace {
3737-
my ($string, $find, $replace) = @_;
3738-
3739-
$string =~ s/$find/$replace/g;
3740-
3741-
return $string;
3742-
}
3743-
37443744
# check for bad placement of section $InitAttribute (e.g.: __initdata)
37453745
if ($line =~ /(\b$InitAttribute\b)/) {
37463746
my $attr = $1;
@@ -4198,6 +4198,12 @@ sub string_find_replace {
41984198
"usage of NR_CPUS is often wrong - consider using cpu_possible(), num_possible_cpus(), for_each_possible_cpu(), etc\n" . $herecurr);
41994199
}
42004200

4201+
# Use of __ARCH_HAS_<FOO> or ARCH_HAVE_<BAR> is wrong.
4202+
if ($line =~ /\+\s*#\s*define\s+((?:__)?ARCH_(?:HAS|HAVE)\w*)\b/) {
4203+
ERROR("DEFINE_ARCH_HAS",
4204+
"#define of '$1' is wrong - use Kconfig variables or standard guards instead\n" . $herecurr);
4205+
}
4206+
42014207
# check for %L{u,d,i} in strings
42024208
my $string;
42034209
while ($line =~ /(?:^|")([X\t]*)(?:"|$)/g) {

0 commit comments

Comments
 (0)