Skip to contentSkip to conversation

lockdep: address clang -Wformat warning printing for %hd

PATCH Applied Arnd Bergmann 3 participants 3 messages Mar 22, 2021 – Mar 29, 2021 Locking primitives

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 lockdep: address clang -Wformat warning printing for %hd

From: Arnd Bergmann <[email protected]>

Clang doesn't like format strings that truncate a 32-bit value to something shorter:

kernel/locking/lockdep.c:709:4: error: format specifies type 'short' but the argument has type 'int' [-Werror,-Wformat]

In this case, the warning is a slightly questionable, as it could realize that both class->wait_type_outer and class->wait_type_inner are in fact 8-bit struct members, even though the result of the ?: operator becomes an 'int'.

However, there is really no point in printing the number as a 16-bit 'short' rather than either an 8-bit or 32-bit number, so just change it to a normal %d.

Fixes de8f5e4f2dc1 ("lockdep: Introduce wait-type checks")
---
 kernel/locking/lockdep.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/locking/lockdep.c +1 -1
index 70bf3e48eae3..bb3b0bc6ee17 100644
@@ -705,7 +705,7 @@ static void print_lock_name(struct lock_class *class)
 
 	printk(KERN_CONT " (");
 	__print_lock_name(class);
-	printk(KERN_CONT "){%s}-{%hd:%hd}", usage,
+	printk(KERN_CONT "){%s}-{%d:%d}", usage,
 			class->wait_type_outer ?: class->wait_type_inner,
 			class->wait_type_inner);
 }
Signature · 1 line
2.29.2
merge bot Applied
#1 lore raw

[tip: perf/urgent] lockdep: Address clang -Wformat warning printing for %hd

The following commit has been merged into the perf/urgent branch of tip:

The following commit has been merged into the perf/urgent branch of tip:

Commit-ID:     6d48b7912cc72275dc7c59ff961c8bac7ef66a92
Gitweb:        https://git.kernel.org/tip/6d48b7912cc72275dc7c59ff961c8bac7ef66a92
Author:        Arnd Bergmann <[email protected]>
AuthorDate:    Mon, 22 Mar 2021 12:55:25 +01:00
Committer:     Ingo Molnar <[email protected]>
CommitterDate: Mon, 22 Mar 2021 22:07:09 +01:00

lockdep: Address clang -Wformat warning printing for %hd

Clang doesn't like format strings that truncate a 32-bit value to something shorter:

kernel/locking/lockdep.c:709:4: error: format specifies type 'short' but the argument has type 'int' [-Werror,-Wformat]

In this case, the warning is a slightly questionable, as it could realize that both class->wait_type_outer and class->wait_type_inner are in fact 8-bit struct members, even though the result of the ?: operator becomes an 'int'.

However, there is really no point in printing the number as a 16-bit 'short' rather than either an 8-bit or 32-bit number, so just change it to a normal %d.

Fixes de8f5e4f2dc1 ("lockdep: Introduce wait-type checks")
---
 kernel/locking/lockdep.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/locking/lockdep.c +1 -1
index c30eb88..f160f1c 100644
@@ -705,7 +705,7 @@ static void print_lock_name(struct lock_class *class)
 
 	printk(KERN_CONT " (");
 	__print_lock_name(class);
-	printk(KERN_CONT "){%s}-{%hd:%hd}", usage,
+	printk(KERN_CONT "){%s}-{%d:%d}", usage,
 			class->wait_type_outer ?: class->wait_type_inner,
 			class->wait_type_inner);
 }
Reviewed-by on v1 1/1
#2 lore raw
In reply to Arnd Bergmann
Quoted 8 lines · Arnd Bergmann

From: Arnd Bergmann <[email protected]>

Clang doesn't like format strings that truncate a 32-bit value to something shorter:

kernel/locking/lockdep.c:709:4: error: format specifies type 'short' but the argument has type 'int' [-Werror,-Wformat]

Quoted 8 lines

In this case, the warning is a slightly questionable, as it could realize that both class->wait_type_outer and class->wait_type_inner are in fact 8-bit struct members, even though the result of the ?: operator becomes an 'int'.

However, there is really no point in printing the number as a 16-bit 'short' rather than either an 8-bit or 32-bit number, so just change it to a normal %d.

Thanks for the patch!

Quoted 23 lines
Fixes de8f5e4f2dc1 ("lockdep: Introduce wait-type checks")
---
 kernel/locking/lockdep.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/locking/lockdep.c +1 -2
index 70bf3e48eae3..bb3b0bc6ee17 100644
@@ -705,7 +705,7 @@ static void print_lock_name(struct lock_class *class)
 
        printk(KERN_CONT " (");
        __print_lock_name(class);
-       printk(KERN_CONT "){%s}-{%hd:%hd}", usage,
+       printk(KERN_CONT "){%s}-{%d:%d}", usage,
                        class->wait_type_outer ?: class->wait_type_inner,
                        class->wait_type_inner);
 }
--

2.29.2

Signature · 2 lines
Thanks,
~Nick Desaulniers