Skip to contentSkip to conversation

drivers: lkdtm: fix clang -Wformat warning

PATCH Superseded Justin Stitt 4 participants 6 messages Jul 21, 2022 – Jul 23, 2022

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drivers: lkdtm: fix clang -Wformat warning

When building with Clang we encounter the following warning (ARCH=hexagon + CONFIG_FRAME_WARN=0):

| ../drivers/misc/lkdtm/bugs.c:107:3: error: format specifies type
| 'unsigned long' but the argument has type 'int' [-Werror,-Wformat]
|                 REC_STACK_SIZE, recur_count);
|                 ^~~~~~~~~~~~~~

Cast REC_STACK_SIZE to unsigned long to match format specifier %lu.

---
Reported by Nathan here:
https://lore.kernel.org/all/[email protected]/

 drivers/misc/lkdtm/bugs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/misc/lkdtm/bugs.c +1 -1
index 009239ad1d8a..6381255aaecc 100644
@@ -29,7 +29,7 @@ struct lkdtm_list {
 #if defined(CONFIG_FRAME_WARN) && (CONFIG_FRAME_WARN > 0)
 #define REC_STACK_SIZE (_AC(CONFIG_FRAME_WARN, UL) / 2)
 #else
-#define REC_STACK_SIZE (THREAD_SIZE / 8)
+#define REC_STACK_SIZE ((unsigned long)(THREAD_SIZE / 8))
 #endif
 #define REC_NUM_DEFAULT ((THREAD_SIZE / REC_STACK_SIZE) * 2)
 
Signature · 1 line
2.37.1.359.gd136c6c3e2-goog
Reviewed-by on v1 1/1
#1 lore raw
Quoted 7 lines · Justin Stitt

When building with Clang we encounter the following warning (ARCH=hexagon + CONFIG_FRAME_WARN=0):

| ../drivers/misc/lkdtm/bugs.c:107:3: error: format specifies type
| 'unsigned long' but the argument has type 'int' [-Werror,-Wformat]
|                 REC_STACK_SIZE, recur_count);
|                 ^~~~~~~~~~~~~~
Quoted 6 lines

Cast REC_STACK_SIZE to unsigned long to match format specifier %lu.

I think this is the right fix, as REC_STACK_SIZE will be 'unsigned long' when CONFIG_FRAME_WARN is greater than 0 due to the _AC(..., UL) macro, so the other one should match too. THREAD_SIZE might not be an unsigned long; I see at least hexagon, microblaze, m68k, powerpc, and sh that define it as either a regular integer literal with no suffix or '1 << THREAD_SHIFT', which will both be of type 'int'.

Quoted 23 lines

---
Reported by Nathan here:
https://lore.kernel.org/all/[email protected]/

 drivers/misc/lkdtm/bugs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/misc/lkdtm/bugs.c +1 -1
index 009239ad1d8a..6381255aaecc 100644
@@ -29,7 +29,7 @@ struct lkdtm_list {
 #if defined(CONFIG_FRAME_WARN) && (CONFIG_FRAME_WARN > 0)
 #define REC_STACK_SIZE (_AC(CONFIG_FRAME_WARN, UL) / 2)
 #else
-#define REC_STACK_SIZE (THREAD_SIZE / 8)
+#define REC_STACK_SIZE ((unsigned long)(THREAD_SIZE / 8))
 #endif
 #define REC_NUM_DEFAULT ((THREAD_SIZE / REC_STACK_SIZE) * 2)
 
Signature · 1 line
2.37.1.359.gd136c6c3e2-goog
#2 lore raw
In reply to Justin Stitt
Quoted 26 lines · Justin Stitt

When building with Clang we encounter the following warning (ARCH=hexagon + CONFIG_FRAME_WARN=0):

| ../drivers/misc/lkdtm/bugs.c:107:3: error: format specifies type
| 'unsigned long' but the argument has type 'int' [-Werror,-Wformat]
|                 REC_STACK_SIZE, recur_count);
|                 ^~~~~~~~~~~~~~

Cast REC_STACK_SIZE to unsigned long to match format specifier %lu.

---
Reported by Nathan here:
https://lore.kernel.org/all/[email protected]/

 drivers/misc/lkdtm/bugs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/misc/lkdtm/bugs.c +0 -0
index 009239ad1d8a..6381255aaecc 100644

drivers/misc/lkdtm/bugs.c struct lkdtm_list { · line 32

Quoted 5 lines
drivers/misc/lkdtm/bugs.c +1 -1
@@ -29,7 +29,7 @@ struct lkdtm_list {
 #if defined(CONFIG_FRAME_WARN) && (CONFIG_FRAME_WARN > 0)
 #define REC_STACK_SIZE (_AC(CONFIG_FRAME_WARN, UL) / 2)
 #else
-#define REC_STACK_SIZE (THREAD_SIZE / 8)
+#define REC_STACK_SIZE ((unsigned long)(THREAD_SIZE / 8))

THREAD_SIZE / 8UL might be more concise.

Quoted 6 lines
drivers/misc/lkdtm/bugs.c +0 -1
 #endif
 #define REC_NUM_DEFAULT ((THREAD_SIZE / REC_STACK_SIZE) * 2)
 
--

2.37.1.359.gd136c6c3e2-goog

Signature · 2 lines
Thanks,
~Nick Desaulniers
#3 lore raw

PATCH v2 1/1 drivers: lkdtm: fix clang -Wformat warning

When building with Clang we encounter the following warning (ARCH=hexagon + CONFIG_FRAME_WARN=0):

| ../drivers/misc/lkdtm/bugs.c:107:3: error: format specifies type
| 'unsigned long' but the argument has type 'int' [-Werror,-Wformat]
|                 REC_STACK_SIZE, recur_count);
|                 ^~~~~~~~~~~~~~

Cast REC_STACK_SIZE to unsigned long to match format specifier %lu as well as maintain symmetry with #define REC_STACK_SIZE (_AC(CONFIG_FRAME_WARN, UL) / 2).

---
Reported by Nathan here:
https://lore.kernel.org/all/[email protected]/

changes from v1 -> v2:
* Use implicit division conversion with / nUL instead of verbose (unsigned long) ~ Thanks Nick

 drivers/misc/lkdtm/bugs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/misc/lkdtm/bugs.c +1 -1
index 009239ad1d8a..48821f4c2b21 100644
@@ -29,7 +29,7 @@ struct lkdtm_list {
 #if defined(CONFIG_FRAME_WARN) && (CONFIG_FRAME_WARN > 0)
 #define REC_STACK_SIZE (_AC(CONFIG_FRAME_WARN, UL) / 2)
 #else
-#define REC_STACK_SIZE (THREAD_SIZE / 8)
+#define REC_STACK_SIZE (THREAD_SIZE / 8UL)
 #endif
 #define REC_NUM_DEFAULT ((THREAD_SIZE / REC_STACK_SIZE) * 2)
 
Signature · 1 line
2.37.1.359.gd136c6c3e2-goog
Reviewed-by Tested-by on v2 1/1
#4 lore raw
Quoted 7 lines · Justin Stitt

When building with Clang we encounter the following warning (ARCH=hexagon + CONFIG_FRAME_WARN=0):

| ../drivers/misc/lkdtm/bugs.c:107:3: error: format specifies type
| 'unsigned long' but the argument has type 'int' [-Werror,-Wformat]
|                 REC_STACK_SIZE, recur_count);
|                 ^~~~~~~~~~~~~~
Quoted 7 lines

Cast REC_STACK_SIZE to unsigned long to match format specifier %lu as well as maintain symmetry with #define REC_STACK_SIZE (_AC(CONFIG_FRAME_WARN, UL) / 2).

Personally, I would drop this; my suggestion was the cast, which we are not going with anymore. Not worth a v3 unless there are other changes requested.

Quoted 2 lines
Quoted 28 lines

---
Reported by Nathan here:
https://lore.kernel.org/all/[email protected]/

changes from v1 -> v2:
* Use implicit division conversion with / nUL instead of verbose (unsigned long) ~ Thanks Nick

 drivers/misc/lkdtm/bugs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/misc/lkdtm/bugs.c +1 -1
index 009239ad1d8a..48821f4c2b21 100644
@@ -29,7 +29,7 @@ struct lkdtm_list {
 #if defined(CONFIG_FRAME_WARN) && (CONFIG_FRAME_WARN > 0)
 #define REC_STACK_SIZE (_AC(CONFIG_FRAME_WARN, UL) / 2)
 #else
-#define REC_STACK_SIZE (THREAD_SIZE / 8)
+#define REC_STACK_SIZE (THREAD_SIZE / 8UL)
 #endif
 #define REC_NUM_DEFAULT ((THREAD_SIZE / REC_STACK_SIZE) * 2)
 
Signature · 1 line
2.37.1.359.gd136c6c3e2-goog
Acked-by on v2 1/1
#5 lore raw
In reply to Justin Stitt
Quoted 11 lines · Justin Stitt

When building with Clang we encounter the following warning (ARCH=hexagon + CONFIG_FRAME_WARN=0):

| ../drivers/misc/lkdtm/bugs.c:107:3: error: format specifies type
| 'unsigned long' but the argument has type 'int' [-Werror,-Wformat]
|                 REC_STACK_SIZE, recur_count);
|                 ^~~~~~~~~~~~~~

Cast REC_STACK_SIZE to unsigned long to match format specifier %lu as well as maintain symmetry with #define REC_STACK_SIZE (_AC(CONFIG_FRAME_WARN, UL) / 2).

Quoted 5 lines

Thanks!

Fixes 24cccab42c419 ("lkdtm/bugs: Adjust recursion test to avoid elision")
Signature · 1 line
Kees Cook