* [PATCH] checkpatch: recognize standard SI unit prefixes and symbols
@ 2026-08-14 15:51 Ariel Yu
2026-08-14 22:21 ` Joe Perches
2026-08-15 18:04 ` [PATCH v2] " Ariel Yu
0 siblings, 2 replies; 4+ messages in thread
From: Ariel Yu @ 2026-08-14 15:51 UTC (permalink / raw)
To: apw, joe; +Cc: linux-kernel
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>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] checkpatch: recognize standard SI unit prefixes and symbols
2026-08-14 15:51 [PATCH] checkpatch: recognize standard SI unit prefixes and symbols Ariel Yu
@ 2026-08-14 22:21 ` Joe Perches
2026-08-15 18:04 ` [PATCH v2] " Ariel Yu
1 sibling, 0 replies; 4+ messages in thread
From: Joe Perches @ 2026-08-14 22:21 UTC (permalink / raw)
To: Ariel Yu, apw; +Cc: linux-kernel
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)>
>
>
> ```
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH v2] checkpatch: recognize standard SI unit prefixes and symbols
2026-08-14 15:51 [PATCH] checkpatch: recognize standard SI unit prefixes and symbols Ariel Yu
2026-08-14 22:21 ` Joe Perches
@ 2026-08-15 18:04 ` Ariel Yu
2026-08-17 8:33 ` Andy Shevchenko
1 sibling, 1 reply; 4+ messages in thread
From: Ariel Yu @ 2026-08-15 18:04 UTC (permalink / raw)
To: apw, joe; +Cc: linux-kernel, andriy.shevchenko
checkpatch flags identifiers containing valid SI units as CamelCase.
Expand the SI unit ignore patterns to recognize standard Système
International d'unités prefixes (u, m, k, M, G) and unit symbols
(V, A, Hz, Ohm, C, K, s, W, etc.):
- Allow mixed-case suffixes after the [a-z][A-Z] SI unit core, so
derived units like _uV_per_C or _mV_per_K are no longer flagged.
- Allow mixed-case prefixes in both the two-char and three-char SI
patterns, so identifiers like clock_FREQ_kHz are recognized.
- Add Ohm (with all standard prefixes: uOhm, mOhm, kOhm, MOhm, GOhm)
to the three-char SI unit list.
- Allow mixed-case suffixes after three-char SI units as well.
Suggested-by: Andy Shevchenko <andriy.shevchenko@intel.com>
Closes: 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>
---
Fixed false positives in check reports with SI units, like
<AD7173_TEMP_SENSIIVITY_uV_per_C>, <SENSOR_uV_per_C>, <clock_FREQ_kHz>,
<impedance_kOhm>. Now these naming conventions will now be considered PASS.
---
Changes in v2:
- Rewrite all regex.
- Link to v1: https://patch.msgid.link/010601a000f8aa59-fa0e91fe-a069-4aaf-baa2-79737d25251a-000000@ap-northeast-1.amazonses.com
---
scripts/checkpatch.pl | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 2b7a42bbdd..a55d7085c5 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -5937,9 +5937,9 @@ sub process {
$var !~ /^ETHTOOL_LINK_MODE_/ &&
#Ignore SI style variants like nS, mV and dB
#(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_]+)?$/ &&
+ $var !~ /^(?:[a-zA-Z0-9_]*)?_?[a-z][A-Z](?:_[a-zA-Z0-9_]+)?$/ &&
#Ignore some three character SI units explicitly, like MiB and KHz
- $var !~ /^(?:[a-z_]*?)_?(?:[KMGT]iB|[KMGT]?Hz)(?:_[a-z_]+)?$/) {
+ $var !~ /^(?:[a-zA-Z_]*?)_?(?:[KMGT]iB|[KMGT]?Hz|[umkMG]?Ohm)(?:_[a-zA-Z_]+)?$/) {
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: 20260816-commit2v-63337b4ffa2a
Best regards,
--
Ariel Yu <ariel@ariels.xyz>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2] checkpatch: recognize standard SI unit prefixes and symbols
2026-08-15 18:04 ` [PATCH v2] " Ariel Yu
@ 2026-08-17 8:33 ` Andy Shevchenko
0 siblings, 0 replies; 4+ messages in thread
From: Andy Shevchenko @ 2026-08-17 8:33 UTC (permalink / raw)
To: Ariel Yu; +Cc: apw, joe, linux-kernel
On Sat, Aug 15, 2026 at 06:04:49PM +0000, Ariel Yu wrote:
> checkpatch flags identifiers containing valid SI units as CamelCase.
>
> Expand the SI unit ignore patterns to recognize standard Système
> International d'unités prefixes (u, m, k, M, G) and unit symbols
> (V, A, Hz, Ohm, C, K, s, W, etc.):
>
> - Allow mixed-case suffixes after the [a-z][A-Z] SI unit core, so
> derived units like _uV_per_C or _mV_per_K are no longer flagged.
> - Allow mixed-case prefixes in both the two-char and three-char SI
> patterns, so identifiers like clock_FREQ_kHz are recognized.
> - Add Ohm (with all standard prefixes: uOhm, mOhm, kOhm, MOhm, GOhm)
> to the three-char SI unit list.
> - Allow mixed-case suffixes after three-char SI units as well.
Maybe this way, or maybe some leveled one (first check the multiplier, then
validate the SI unit). Whatever, I am okay with this approach.
Acked-by: Andy Shevchenko <andriy.shevchenko@intel.com>
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-08-17 8:33 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-08-14 15:51 [PATCH] checkpatch: recognize standard SI unit prefixes and symbols Ariel Yu
2026-08-14 22:21 ` Joe Perches
2026-08-15 18:04 ` [PATCH v2] " Ariel Yu
2026-08-17 8:33 ` Andy Shevchenko
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®