[v3] devtools: check %l format specifier

Message ID 20210521133038.1165002-1-thomas@monjalon.net (mailing list archive)
State Accepted, archived
Headers
Series [v3] devtools: check %l format specifier |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation success Compilation OK
ci/iol-abi-testing success Testing PASS
ci/intel-Testing success Testing PASS
ci/iol-testing success Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-mellanox-Performance fail Performance Testing issues
ci/iol-mellanox-Functional fail Functional Testing issues

Commit Message

Thomas Monjalon May 21, 2021, 1:30 p.m. UTC
  From: Ferruh Yigit <ferruh.yigit@intel.com>

%lx or %llx tend to be wrong for 32-bit platform
if used for fixed size variable like uint64_t.
A checkpatch warning will avoid this common mistake.

Signed-off-by: Ferruh Yigit <ferruh.yigit@intel.com>
Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
---
v3: more explicit message
v2: proposal to reword the message and comment
---
 devtools/checkpatches.sh | 8 ++++++++
 1 file changed, 8 insertions(+)
  

Comments

Ferruh Yigit May 21, 2021, 1:33 p.m. UTC | #1
On 5/21/2021 2:30 PM, Thomas Monjalon wrote:
> From: Ferruh Yigit <ferruh.yigit@intel.com>
> 
> %lx or %llx tend to be wrong for 32-bit platform
> if used for fixed size variable like uint64_t.
> A checkpatch warning will avoid this common mistake.
> 
> Signed-off-by: Ferruh Yigit <ferruh.yigit@intel.com>
> Signed-off-by: Thomas Monjalon <thomas@monjalon.net>

Ack.

Thanks for update.
  
Thomas Monjalon May 21, 2021, 1:36 p.m. UTC | #2
21/05/2021 15:33, Ferruh Yigit:
> On 5/21/2021 2:30 PM, Thomas Monjalon wrote:
> > From: Ferruh Yigit <ferruh.yigit@intel.com>
> > 
> > %lx or %llx tend to be wrong for 32-bit platform
> > if used for fixed size variable like uint64_t.
> > A checkpatch warning will avoid this common mistake.
> > 
> > Signed-off-by: Ferruh Yigit <ferruh.yigit@intel.com>
> > Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
> 
> Ack.
> 
> Thanks for update.

Applied, thanks
  

Patch

diff --git a/devtools/checkpatches.sh b/devtools/checkpatches.sh
index ba43f84e64..c30dadd962 100755
--- a/devtools/checkpatches.sh
+++ b/devtools/checkpatches.sh
@@ -69,6 +69,14 @@  check_forbidden_additions() { # <patch>
 		-f $(dirname $(readlink -f $0))/check-forbidden-tokens.awk \
 		"$1" || res=1
 
+	# check %l or %ll format specifier
+	awk -v FOLDERS='lib drivers app examples' \
+		-v EXPRESSIONS='%ll*[xud]' \
+		-v RET_ON_FAIL=1 \
+		-v MESSAGE='Using %l format, prefer %PRI*64 if type is [u]int64_t' \
+		-f $(dirname $(readlink -f $0))/check-forbidden-tokens.awk \
+		"$1" || res=1
+
 	# forbid variable declaration inside "for" loop
 	awk -v FOLDERS='.' \
 		-v EXPRESSIONS='for[[:space:]]*\\((char|u?int|unsigned|s?size_t)' \