drivers: lkdtm: fix clang -Wformat warning
Subsystems (2)
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
@@ -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
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_SIZEtounsigned longto match format specifier%lu.Reported-by Nathan Chancellor <[email protected]>Suggested-by Nathan Chancellor <[email protected]>Signed-off-by Justin Stitt <[email protected]>
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@@ -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
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_SIZEtounsigned longto match format specifier%lu.Reported-by Nathan Chancellor <[email protected]>Suggested-by Nathan Chancellor <[email protected]>Signed-off-by Justin Stitt <[email protected]>---
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
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
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
@@ -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
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_SIZEtounsigned longto match format specifier%luas 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
Suggested-by Nick Desaulniers <[email protected]>Signed-off-by Justin Stitt <[email protected]>
Quoted 28 lines
---
Reported by Nathan here:
https://lore.kernel.org/all/[email protected]/changes from v1 -> v2:
* Use implicit division conversion with/ nULinstead of verbose(unsigned long)~ Thanks Nickdrivers/misc/lkdtm/bugs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)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 (THREAD_SIZE / 8UL)#endif #define REC_NUM_DEFAULT ((THREAD_SIZE / REC_STACK_SIZE) * 2)Signature · 1 line
2.37.1.359.gd136c6c3e2-goog
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_SIZEtounsigned longto match format specifier%luas well as maintain symmetry with#define REC_STACK_SIZE (_AC(CONFIG_FRAME_WARN, UL) / 2).
Quoted 5 lines
Reported-by Nathan Chancellor <[email protected]>Suggested-by Nathan Chancellor <[email protected]>Suggested-by Nick Desaulniers <[email protected]>Signed-off-by Justin Stitt <[email protected]>
Thanks!
Signature · 1 line
Kees Cook