Skip to contentSkip to conversation

checkpatch: Ignore <inttypes.h> format macros

PATCH Superseded Petr Vorel 3 participants 7 messages May 11 – May 12 Checkpatch

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Petr Vorel

author
#0 lore raw

PATCH 1/1 checkpatch: Ignore <inttypes.h> format macros

Constants from <inttypes.h> are used only in userspace tools, they are from ISO C99, let's don't report it:

arch/mips/boot/tools/relocs.c:572: CHECK: Avoid CamelCase: <PRIx32> arch/s390/tools/relocs.c:52: CHECK: Avoid CamelCase: <PRIu64> tools/testing/selftests/mm/vm_util.c:244: CHECK: Avoid CamelCase: <SCNu64>

---
 scripts/checkpatch.pl | 2 ++
 1 file changed, 2 insertions(+)
scripts/checkpatch.pl +2 -0
index 3727156e4ccad..4c7a952a418c0 100755
@@ -5940,6 +5940,8 @@ sub process {
 #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_]+)?$/ &&
+#Ignore <inttypes.h> format macros (e.g. PRIu64, SCNu64)
+			    $var !~ /^(?:PRI|SCN)[dioux][A-Z0-9]+$/ &&
 #Ignore some three character SI units explicitly, like MiB and KHz
 			    $var !~ /^(?:[a-z_]*?)_?(?:[KMGT]iB|[KMGT]?Hz)(?:_[a-z_]+)?$/) {
 				while ($var =~ m{\b($Ident)}g) {
Signature · 1 line
2.53.0
Reviewed-by on v1 1/1
#1 lore raw

Hi Petr,

Quoted 27 lines · Petr Vorel

Constants from <inttypes.h> are used only in userspace tools, they are from ISO C99, let's don't report it:

arch/mips/boot/tools/relocs.c:572: CHECK: Avoid CamelCase: <PRIx32> arch/s390/tools/relocs.c:52: CHECK: Avoid CamelCase: <PRIu64> tools/testing/selftests/mm/vm_util.c:244: CHECK: Avoid CamelCase: <SCNu64>

---
 scripts/checkpatch.pl | 2 ++
 1 file changed, 2 insertions(+)
scripts/checkpatch.pl +2 -1
index 3727156e4ccad..4c7a952a418c0 100755
@@ -5940,6 +5940,8 @@ sub process {
 #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_]+)?$/ &&
+#Ignore <inttypes.h> format macros (e.g. PRIu64, SCNu64)
+                           $var !~ /^(?:PRI|SCN)[dioux][A-Z0-9]+$/ &&
 #Ignore some three character SI units explicitly, like MiB and KHz
                            $var !~ /^(?:[a-z_]*?)_?(?:[KMGT]iB|[KMGT]?Hz)(?:_[a-z_]+)?$/) {
                                while ($var =~ m{\b($Ident)}g) {
--
Quoted 2 lines

2.53.0

How about adding X as well, since <inttypes.h> also defines uppercase-hex variants like PRIX8

Regards,
Simon

author
#2 lore raw
Quoted 26 lines

Hi Petr,

Quoted 22 lines · Petr Vorel

Constants from <inttypes.h> are used only in userspace tools, they are from ISO C99, let's don't report it:

arch/mips/boot/tools/relocs.c:572: CHECK: Avoid CamelCase: <PRIx32> arch/s390/tools/relocs.c:52: CHECK: Avoid CamelCase: <PRIu64> tools/testing/selftests/mm/vm_util.c:244: CHECK: Avoid CamelCase: <SCNu64>

---
 scripts/checkpatch.pl | 2 ++
 1 file changed, 2 insertions(+)
scripts/checkpatch.pl +2 -0
index 3727156e4ccad..4c7a952a418c0 100755
@@ -5940,6 +5940,8 @@ sub process {
 #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_]+)?$/ &&
+#Ignore <inttypes.h> format macros (e.g. PRIu64, SCNu64)
+                           $var !~ /^(?:PRI|SCN)[dioux][A-Z0-9]+$/ &&
Quoted 8 lines
Quoted 5 lines
scripts/checkpatch.pl +0 -1
 #Ignore some three character SI units explicitly, like MiB and KHz
                            $var !~ /^(?:[a-z_]*?)_?(?:[KMGT]iB|[KMGT]?Hz)(?:_[a-z_]+)?$/) {
                                while ($var =~ m{\b($Ident)}g) {
--

2.53.0

Thanks for your review!

Quoted 2 lines

How about adding X as well, since <inttypes.h> also defines uppercase-hex variants like PRIX8

Yes, but that would not be cought as CamelCase (no lower case character).

Kind regards,
Petr

Quoted 2 lines

Regards,
Simon

maintainer
#3 lore raw
In reply to Petr Vorel
Quoted 9 lines · Petr Vorel

```
Constants from <inttypes.h> are used only in userspace tools, they are from ISO C99, let's don't report it:

arch/mips/boot/tools/relocs.c:572: CHECK: Avoid CamelCase: <PRIx32> arch/s390/tools/relocs.c:52: CHECK: Avoid CamelCase: <PRIu64> tools/testing/selftests/mm/vm_util.c:244: CHECK: Avoid CamelCase: <SCNu64>

Nack. This is userspace only and should be tested as such.

Quoted 19 lines
---
 scripts/checkpatch.pl | 2 ++
 1 file changed, 2 insertions(+)
scripts/checkpatch.pl +2 -0
index 3727156e4ccad..4c7a952a418c0 100755
@@ -5940,6 +5940,8 @@ sub process {
 #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_]+)?$/ &&
+#Ignore <inttypes.h> format macros (e.g. PRIu64, SCNu64)
+			    $var !~ /^(?:PRI|SCN)[dioux][A-Z0-9]+$/ &&
 #Ignore some three character SI units explicitly, like MiB and KHz
 			    $var !~ /^(?:[a-z_]*?)_?(?:[KMGT]iB|[KMGT]?Hz)(?:_[a-z_]+)?$/) {
 				while ($var =~ m{\b($Ident)}g) {

```

author
#4 lore raw
Quoted 5 lines · Petr Vorel
Quoted 3 lines

```
Constants from <inttypes.h> are used only in userspace tools, they are from ISO C99, let's don't report it:

Quoted 7 lines
Quoted 5 lines

arch/mips/boot/tools/relocs.c:572: CHECK: Avoid CamelCase: <PRIx32> arch/s390/tools/relocs.c:52: CHECK: Avoid CamelCase: <PRIu64> tools/testing/selftests/mm/vm_util.c:244: CHECK: Avoid CamelCase: <SCNu64>

Nack. This is userspace only and should be tested as such.

Thanks for info.

Yes, warning is correct for kernel space code. Do I understand correctly that false positives are ok for user space code in the Linux kernel tree?

Or is it just because checkpatch.pl has no idea which sources are for user space?

Kind regards,
Petr
...

maintainer
#5 lore raw
Quoted 9 lines · Petr Vorel
Quoted 6 lines · Petr Vorel
Quoted 5 lines

Constants from <inttypes.h> are used only in userspace tools, they are from ISO C99, let's don't report it:
arch/mips/boot/tools/relocs.c:572: CHECK: Avoid CamelCase: <PRIx32> arch/s390/tools/relocs.c:52: CHECK: Avoid CamelCase: <PRIu64> tools/testing/selftests/mm/vm_util.c:244: CHECK: Avoid CamelCase: <SCNu64>

Nack. This is userspace only and should be tested as such.

Quoted 7 lines

Thanks for info.

Yes, warning is correct for kernel space code. Do I understand correctly that false positives are ok for user space code in the Linux kernel tree?

Or is it just because checkpatch.pl has no idea which sources are for user space?

Hello Petr.

I suppose another check could be added.
There is function 'is_userspace' available.

I don't know if userspace cares at all about camelcase anyway.

author
#6 lore raw

Hi Joe, all,

Quoted 15 lines · Petr Vorel
Quoted 13 lines · Petr Vorel
Quoted 6 lines
Quoted 5 lines

Constants from <inttypes.h> are used only in userspace tools, they are from ISO C99, let's don't report it:
arch/mips/boot/tools/relocs.c:572: CHECK: Avoid CamelCase: <PRIx32> arch/s390/tools/relocs.c:52: CHECK: Avoid CamelCase: <PRIu64> tools/testing/selftests/mm/vm_util.c:244: CHECK: Avoid CamelCase: <SCNu64>

Nack. This is userspace only and should be tested as such.

Thanks for info.

Yes, warning is correct for kernel space code. Do I understand correctly that false positives are ok for user space code in the Linux kernel tree?

Quoted 7 lines
Quoted 2 lines

Or is it just because checkpatch.pl has no idea which sources are for user space?

Hello Petr.

I suppose another check could be added.
There is function 'is_userspace' available.

Thanks for pointing out is_userspace() (quite new, from v6.18-rc1, not even in u-boot vendored checkpatch.pl).

Quoted 1 line

I don't know if userspace cares at all about camelcase anyway.

I'd say while there are some differences in kernel and user space code, code style should be mostly the same => userspace should care. Doc [1] does not mention anything specific about userspace either. Therefore I'd prefer to send v2 with this change (to v1):

- $var !~ /^(?:PRI|SCN)[dioux][A-Z0-9]+$/ &&
+ (is_userspace($realfile) && $var !~ /^(?:PRI|SCN)[dioux][A-Z0-9]+$/) &&

Other thing, because we vendored checkpatch.pl in LTP which has only userspace code, I'll have to modify is_userspace() to return always 1. It'd be great if you acked patch to allow always return 1 based on certain variable (e.g. CHECKPATCH_FORCE_USERSPACE=1) or even getopt switch (e.g. --userspace). But I understand if you don't ack it (minimise number of patches on vendored checkpatch.pl makes updating it easier and there are other user space projects which suggest to use checkpatch.pl e.g. btrfs-progs, but there is a boundary what is meaningful to upstream).

Kind regards,
Petr

[1] https://www.kernel.org/doc/html/latest/process/coding-style.html#naming