lkml.org 
[lkml]   [2021]   [May]   [21]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH v2 7/7] checkpatch: suggest _BITULL() and _BITUL() for UAPI headers
Date
From: Joe Richey <joerichey@google.com>

Instead of just ignoring UAPI headers, reccomend the UAPI compatible
macros if a user adds something that looks like (1 << n). Normal kernel
code will continue to get BIT_ULL() and BIT() reccomended.

This change also modifies the $realfile regex to match headers that have
"include/uapi" anywhere in their path so paths like:
tools/include/uapi/linux/kvm.h
arch/x86/include/uapi/asm/hwcap2.h
get recognized as UAPI headers.

Signed-off-by: Joe Richey <joerichey@google.com>
---
scripts/checkpatch.pl | 16 +++++++++-------
1 file changed, 9 insertions(+), 7 deletions(-)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index d65334588eb4..47edc61b74c2 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -7020,15 +7020,17 @@ sub process {
}
}

-# check for #defines like: 1 << <digit> that could be BIT(digit), it is not exported to uapi
- if ($realfile !~ m@^include/uapi/@ &&
- $line =~ /#\s*define\s+\w+\s+\(?\s*1\s*([ulUL]*)\s*\<\<\s*(?:\d+|$Ident)\s*\)?/) {
- my $ull = "";
- $ull = "_ULL" if (defined($1) && $1 =~ /ll/i);
+# check for #defines like: 1 << <digit> that could be BIT(digit) or similar
+ if ($line =~ /#\s*define\s+\w+\s+\(?\s*1\s*([ulUL]*)\s*\<\<\s*(?:\d+|$Ident)\s*\)?/) {
+ my $ull = (defined($1) && $1 =~ /ll/i);
+ my $macroname = $ull ? "BIT_ULL" : "BIT";
+ if ($realfile =~ m@include/uapi/@) {
+ $macroname = $ull ? "_BITULL" : "_BITUL";
+ }
if (CHK("BIT_MACRO",
- "Prefer using the BIT$ull macro\n" . $herecurr) &&
+ "Prefer using the $macroname macro\n" . $herecurr) &&
$fix) {
- $fixed[$fixlinenr] =~ s/\(?\s*1\s*[ulUL]*\s*<<\s*(\d+|$Ident)\s*\)?/BIT${ull}($1)/;
+ $fixed[$fixlinenr] =~ s/\(?\s*1\s*[ulUL]*\s*<<\s*(\d+|$Ident)\s*\)?/${macroname}($1)/;
}
}

--
2.31.1
\
 
 \ /
  Last update: 2021-05-21 11:01    [W:0.168 / U:0.740 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site