mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] checkpatch: Make SI unit tolerance more lenient with 3-character units
@ 2014-11-08  0:18 Julius Werner
  2014-11-08  0:38 ` Joe Perches
  0 siblings, 1 reply; 4+ messages in thread
From: Julius Werner @ 2014-11-08  0:18 UTC (permalink / raw)
  To: Joe Perches; +Cc: Andy Whitcroft, Andrew Morton, linux-kernel, Julius Werner

Checkpatch flags CamelCase identifiers in strict mode, but it has a
feature to ignore parts with only two characters to allow for SI units
like mV or uA. Unfortunately, not all SI units fit in two characters,
and not all are lower case followed by upper case.

This patch changes the check from [a-z][A-Z] to [a-zA-Z]{1,3} (any
combination of up to three lower and upper case characters), so that it
will also allow units like MHz, As or KiB.

Signed-off-by: Julius Werner <jwerner@chromium.org>
---
 scripts/checkpatch.pl | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 374abf4..0bbd25a 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -4055,8 +4055,8 @@ sub process {
 			    $var =~ /[A-Z][a-z]|[a-z][A-Z]/ &&
 #Ignore Page<foo> variants
 			    $var !~ /^(?:Clear|Set|TestClear|TestSet|)Page[A-Z]/ &&
-#Ignore SI style variants like nS, mV and dB (ie: max_uV, regulator_min_uA_show)
-			    $var !~ /^(?:[a-z_]*?)_?[a-z][A-Z](?:_[a-z_]+)?$/) {
+#Ignore SI style variants like nS, mV, MHz and dB (ie: max_uV, regulator_min_uA_show)
+			    $var !~ /^(?:[a-z_]*?)_?[a-zA-Z]{1,3}(?:_[a-z_]+)?$/) {
 				while ($var =~ m{($Ident)}g) {
 					my $word = $1;
 					next if ($word !~ /[A-Z][a-z]|[a-z][A-Z]/);
-- 
1.8.3.2


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] checkpatch: Make SI unit tolerance more lenient with 3-character units
  2014-11-08  0:18 [PATCH] checkpatch: Make SI unit tolerance more lenient with 3-character units Julius Werner
@ 2014-11-08  0:38 ` Joe Perches
  2014-11-10 19:39   ` [PATCHv2] checkpatch: Allow certain SI units with three characters Julius Werner
  0 siblings, 1 reply; 4+ messages in thread
From: Joe Perches @ 2014-11-08  0:38 UTC (permalink / raw)
  To: Julius Werner; +Cc: Andy Whitcroft, Andrew Morton, linux-kernel

On Fri, 2014-11-07 at 16:18 -0800, Julius Werner wrote:
> Checkpatch flags CamelCase identifiers in strict mode, but it has a
> feature to ignore parts with only two characters to allow for SI units
> like mV or uA. Unfortunately, not all SI units fit in two characters,
> and not all are lower case followed by upper case.
> 
> This patch changes the check from [a-z][A-Z] to [a-zA-Z]{1,3} (any
> combination of up to three lower and upper case characters), so that it
> will also allow units like MHz, As or KiB.
[]
> diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
[]
> @@ -4055,8 +4055,8 @@ sub process {
>  			    $var =~ /[A-Z][a-z]|[a-z][A-Z]/ &&
>  #Ignore Page<foo> variants
>  			    $var !~ /^(?:Clear|Set|TestClear|TestSet|)Page[A-Z]/ &&
> -#Ignore SI style variants like nS, mV and dB (ie: max_uV, regulator_min_uA_show)
> -			    $var !~ /^(?:[a-z_]*?)_?[a-z][A-Z](?:_[a-z_]+)?$/) {
> +#Ignore SI style variants like nS, mV, MHz and dB (ie: max_uV, regulator_min_uA_show)
> +			    $var !~ /^(?:[a-z_]*?)_?[a-zA-Z]{1,3}(?:_[a-z_]+)?$/) {
>  				while ($var =~ m{($Ident)}g) {
>  					my $word = $1;
>  					next if ($word !~ /[A-Z][a-z]|[a-z][A-Z]/);

I think this may miss too many uses like pDB and
other variables used for hungarian notations.

It may be better to enumerate the specific character
sequences to exempt.


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCHv2] checkpatch: Allow certain SI units with three characters
  2014-11-08  0:38 ` Joe Perches
@ 2014-11-10 19:39   ` Julius Werner
  2014-11-10 19:50     ` Joe Perches
  0 siblings, 1 reply; 4+ messages in thread
From: Julius Werner @ 2014-11-10 19:39 UTC (permalink / raw)
  To: Joe Perches; +Cc: Andy Whitcroft, Andrew Morton, linux-kernel, Julius Werner

Checkpatch flags CamelCase identifiers in strict mode, but it has a
feature to ignore parts with only two characters to allow for SI units
like mV or uA. Unfortunately, not all SI units fit in two characters,
and not all are lower case followed by upper case.

This patch adds hardcoded detection for frequency and 1024-based size
units (Hz/KHz/MHz/GHz/THz and KiB/MiB/GiB/TiB), since allowing any three
character combinations might be too lenient. The list can later be
expanded as needed.

Signed-off-by: Julius Werner <jwerner@chromium.org>
---
 scripts/checkpatch.pl | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 374abf4..b947c75 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -4056,7 +4056,9 @@ sub process {
 #Ignore Page<foo> variants
 			    $var !~ /^(?:Clear|Set|TestClear|TestSet|)Page[A-Z]/ &&
 #Ignore SI style variants like nS, mV and dB (ie: max_uV, regulator_min_uA_show)
-			    $var !~ /^(?:[a-z_]*?)_?[a-z][A-Z](?:_[a-z_]+)?$/) {
+			    $var !~ /^(?:[a-z_]*?)_?[a-z][A-Z](?:_[a-z_]+)?$/ &&
+#Ignore some three character SI units explicitly, like MiB and KHz
+			    $var !~ /^(?:[a-z_]*?)_?(?:[KMGT]iB|[KMGT]?Hz)(?:_[a-z_]+)?$/) {
 				while ($var =~ m{($Ident)}g) {
 					my $word = $1;
 					next if ($word !~ /[A-Z][a-z]|[a-z][A-Z]/);
-- 
2.1.2


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCHv2] checkpatch: Allow certain SI units with three characters
  2014-11-10 19:39   ` [PATCHv2] checkpatch: Allow certain SI units with three characters Julius Werner
@ 2014-11-10 19:50     ` Joe Perches
  0 siblings, 0 replies; 4+ messages in thread
From: Joe Perches @ 2014-11-10 19:50 UTC (permalink / raw)
  To: Julius Werner; +Cc: Andy Whitcroft, Andrew Morton, linux-kernel

On Mon, 2014-11-10 at 11:39 -0800, Julius Werner wrote:
> Checkpatch flags CamelCase identifiers in strict mode, but it has a
> feature to ignore parts with only two characters to allow for SI units
> like mV or uA. Unfortunately, not all SI units fit in two characters,
> and not all are lower case followed by upper case.
> 
> This patch adds hardcoded detection for frequency and 1024-based size
> units (Hz/KHz/MHz/GHz/THz and KiB/MiB/GiB/TiB), since allowing any three
> character combinations might be too lenient. The list can later be
> expanded as needed.

Seems sensible enough, thanks.

Acked-by: Joe Perches <joe@perches.com>

> Signed-off-by: Julius Werner <jwerner@chromium.org>
> ---
>  scripts/checkpatch.pl | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
> index 374abf4..b947c75 100755
> --- a/scripts/checkpatch.pl
> +++ b/scripts/checkpatch.pl
> @@ -4056,7 +4056,9 @@ sub process {
>  #Ignore Page<foo> variants
>  			    $var !~ /^(?:Clear|Set|TestClear|TestSet|)Page[A-Z]/ &&
>  #Ignore SI style variants like nS, mV and dB (ie: max_uV, regulator_min_uA_show)
> -			    $var !~ /^(?:[a-z_]*?)_?[a-z][A-Z](?:_[a-z_]+)?$/) {
> +			    $var !~ /^(?:[a-z_]*?)_?[a-z][A-Z](?:_[a-z_]+)?$/ &&
> +#Ignore some three character SI units explicitly, like MiB and KHz
> +			    $var !~ /^(?:[a-z_]*?)_?(?:[KMGT]iB|[KMGT]?Hz)(?:_[a-z_]+)?$/) {
>  				while ($var =~ m{($Ident)}g) {
>  					my $word = $1;
>  					next if ($word !~ /[A-Z][a-z]|[a-z][A-Z]/);




^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2014-11-10 19:50 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-11-08  0:18 [PATCH] checkpatch: Make SI unit tolerance more lenient with 3-character units Julius Werner
2014-11-08  0:38 ` Joe Perches
2014-11-10 19:39   ` [PATCHv2] checkpatch: Allow certain SI units with three characters Julius Werner
2014-11-10 19:50     ` Joe Perches

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome