[PATCH] checkpatch: recognize standard SI unit prefixes and symbols

Ariel Yu posted 1 patch 1 month, 2 weeks ago
There is a newer version of this series
scripts/checkpatch.pl | 18 ++++++++++++++----
1 file changed, 14 insertions(+), 4 deletions(-)
[PATCH] checkpatch: recognize standard SI unit prefixes and symbols
Posted by Ariel Yu 1 month, 2 weeks ago
The CAMELCASE check currently uses a broad [a-z][A-Z] pattern to
skip SI-unit-style identifiers, which matches any lowercase-then-
uppercase pair rather than actual SI units.

Replace it with an explicit list of standard SI prefixes
(u, n, m, k, K, M, G, T) and units (V, A, Hz, Ohm, C, K, s, W),
while retaining the binary byte units (KiB, MiB, GiB) and dB.

Link: https://lore.kernel.org/linux-iio/F9A182CC-62C0-445C-BAF0-9CDB7FFB3868@gmail.com/
Assisted-by: opencode:deepseek-v4-pro
Signed-off-by: Ariel Yu <ariel@ariels.xyz>
---
 scripts/checkpatch.pl | 18 ++++++++++++++----
 1 file changed, 14 insertions(+), 4 deletions(-)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 2b7a42bbdd..ba76beafc3 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -5935,11 +5935,21 @@ sub process {
 			    $var !~ /^(?:Clear|Set|TestClear|TestSet|)Page[A-Z]/ &&
 #Ignore ETHTOOL_LINK_MODE_<foo> variants
 			    $var !~ /^ETHTOOL_LINK_MODE_/ &&
-#Ignore SI style variants like nS, mV and dB
+#Ignore SI style variants like mV, uA, kHz, dB, MiB etc.
 #(ie: max_uV, regulator_min_uA_show, RANGE_mA_VALUE)
-			    $var !~ /^(?:[a-z0-9_]*|[A-Z0-9_]*)?_?[a-z][A-Z](?:_[a-z0-9_]+|_[A-Z0-9_]+)?$/ &&
-#Ignore some three character SI units explicitly, like MiB and KHz
-			    $var !~ /^(?:[a-z_]*?)_?(?:[KMGT]iB|[KMGT]?Hz)(?:_[a-z_]+)?$/) {
+#
+#Recognized standard SI unit prefixes (case sensitive):
+#	u - micro (10^-6)	n - nano (10^-9)	m - milli (10^-3)
+#	k - kilo (10^3)		K - kilo (10^3)		M - mega (10^6)
+#	G - giga (10^9)		T - tera (10^12)
+#
+#Recognized units (optionally prefixed by the above):
+#	V - volt		A - ampere		Hz - hertz
+#	Ohm - ohm		C - coulomb		K - kelvin
+#	s - second		W - watt
+#Binary byte units: KiB, MiB, GiB (TiB)
+#Decibel: dB
+			    $var !~ /^(?:[a-z0-9_]*|[A-Z0-9_]*)?_?(?:[unmkKMGT]?(?:V|A|Hz|Ohm|C|K|s|W)|[KMG]iB|dB)(?:_[a-z0-9_]+|_[A-Z0-9_]+)?$/) {
 				while ($var =~ m{\b($Ident)}g) {
 					my $word = $1;
 					next if ($word !~ /[A-Z][a-z]|[a-z][A-Z]/);

---
base-commit: d58772d8520c7ef247c4b95c9bd76d3a25da9ff5
change-id: 20260814-ktodo-si-cad1bd45ca07

Best regards,
--  
Ariel Yu <ariel@ariels.xyz>
Re: [PATCH] checkpatch: recognize standard SI unit prefixes and symbols
Posted by Joe Perches 1 month, 2 weeks ago
On Fri, 2026-08-14 at 15:51 +0000, Ariel Yu wrote:
> ```
> The CAMELCASE check currently uses a broad [a-z][A-Z] pattern to
> skip SI-unit-style identifiers, which matches any lowercase-then-
> uppercase pair rather than actual SI units.
> 
> Replace it with an explicit list of standard SI prefixes
> (u, n, m, k, K, M, G, T) and units (V, A, Hz, Ohm, C, K, s, W),
> while retaining the binary byte units (KiB, MiB, GiB) and dB.

Why?  What does this complication do better?


> 
> Link: [https://lore.kernel.org/linux-iio/F9A182CC-62C0-445C-BAF0-9CDB7FFB3868@gmail.com/](https://lore.kernel.org/linux-iio/F9A182CC-62C0-445C-BAF0-9CDB7FFB3868@gmail.com/)
> Assisted-by: opencode:deepseek-v4-pro
> Signed-off-by: Ariel Yu <[ariel@ariels.xyz](mailto:ariel@ariels.xyz)>
> ---
>  scripts/checkpatch.pl | 18 ++++++++++++++----
>  1 file changed, 14 insertions(+), 4 deletions(-)
> 
> diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
> index 2b7a42bbdd..ba76beafc3 100755
> --- a/scripts/checkpatch.pl
> +++ b/scripts/checkpatch.pl
> @@ -5935,11 +5935,21 @@ sub process {
>  			    $var !~ /^(?:Clear|Set|TestClear|TestSet|)Page[A-Z]/ &&
>  #Ignore ETHTOOL_LINK_MODE_<foo> variants
>  			    $var !~ /^ETHTOOL_LINK_MODE_/ &&
> -#Ignore SI style variants like nS, mV and dB
> +#Ignore SI style variants like mV, uA, kHz, dB, MiB etc.
>  #(ie: max_uV, regulator_min_uA_show, RANGE_mA_VALUE)
> -			    $var !~ /^(?:[a-z0-9_]*|[A-Z0-9_]*)?_?[a-z][A-Z](?:_[a-z0-9_]+|_[A-Z0-9_]+)?$/ &&
> -#Ignore some three character SI units explicitly, like MiB and KHz
> -			    $var !~ /^(?:[a-z_]*?)_?(?:[KMGT]iB|[KMGT]?Hz)(?:_[a-z_]+)?$/) {
> +#
> +#Recognized standard SI unit prefixes (case sensitive):
> +#	u - micro (10^-6)	n - nano (10^-9)	m - milli (10^-3)
> +#	k - kilo (10^3)		K - kilo (10^3)		M - mega (10^6)
> +#	G - giga (10^9)		T - tera (10^12)
> +#
> +#Recognized units (optionally prefixed by the above):
> +#	V - volt		A - ampere		Hz - hertz
> +#	Ohm - ohm		C - coulomb		K - kelvin
> +#	s - second		W - watt
> +#Binary byte units: KiB, MiB, GiB (TiB)
> +#Decibel: dB
> +			    $var !~ /^(?:[a-z0-9_]*|[A-Z0-9_]*)?_?(?:[unmkKMGT]?(?:V|A|Hz|Ohm|C|K|s|W)|[KMG]iB|dB)(?:_[a-z0-9_]+|_[A-Z0-9_]+)?$/) {
>  				while ($var =~ m{\b($Ident)}g) {
>  					my $word = $1;
>  					next if ($word !~ /[A-Z][a-z]|[a-z][A-Z]/);
> 
> ---
> base-commit: d58772d8520c7ef247c4b95c9bd76d3a25da9ff5
> change-id: 20260814-ktodo-si-cad1bd45ca07
> 
> Best regards,
> --  
> Ariel Yu <[ariel@ariels.xyz](mailto:ariel@ariels.xyz)>
> 
> 
> ```