All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] drivers: lkdtm: fix clang -Wformat warning
@ 2022-07-21 21:20 Justin Stitt
  2022-07-21 21:34 ` Nathan Chancellor
  2022-07-21 21:42 ` Nick Desaulniers
  0 siblings, 2 replies; 6+ messages in thread
From: Justin Stitt @ 2022-07-21 21:20 UTC (permalink / raw)
  To: Kees Cook
  Cc: Arnd Bergmann, Greg Kroah-Hartman, Nathan Chancellor,
	Nick Desaulniers, Tom Rix, linux-kernel, llvm, 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`.

Link: https://github.com/ClangBuiltLinux/linux/issues/378
Reported-by: Nathan Chancellor <nathan@kernel.org>
Suggested-by: Nathan Chancellor <nathan@kernel.org>
Signed-off-by: Justin Stitt <justinstitt@google.com>
---
Reported by Nathan here:
https://lore.kernel.org/all/YtmrCJjQrSbv8Aj1@dev-arch.thelio-3990X/

 drivers/misc/lkdtm/bugs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/misc/lkdtm/bugs.c b/drivers/misc/lkdtm/bugs.c
index 009239ad1d8a..6381255aaecc 100644
--- a/drivers/misc/lkdtm/bugs.c
+++ b/drivers/misc/lkdtm/bugs.c
@@ -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)
 
-- 
2.37.1.359.gd136c6c3e2-goog


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] drivers: lkdtm: fix clang -Wformat warning
  2022-07-21 21:20 [PATCH] drivers: lkdtm: fix clang -Wformat warning Justin Stitt
@ 2022-07-21 21:34 ` Nathan Chancellor
  2022-07-21 21:42 ` Nick Desaulniers
  1 sibling, 0 replies; 6+ messages in thread
From: Nathan Chancellor @ 2022-07-21 21:34 UTC (permalink / raw)
  To: Justin Stitt
  Cc: Kees Cook, Arnd Bergmann, Greg Kroah-Hartman, Nick Desaulniers,
	Tom Rix, linux-kernel, llvm

On Thu, Jul 21, 2022 at 02:20:12PM -0700, Justin Stitt wrote:
> 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`.
> 
> Link: https://github.com/ClangBuiltLinux/linux/issues/378
> Reported-by: Nathan Chancellor <nathan@kernel.org>
> Suggested-by: Nathan Chancellor <nathan@kernel.org>
> Signed-off-by: Justin Stitt <justinstitt@google.com>

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'.

Reviewed-by: Nathan Chancellor <nathan@kernel.org>

> ---
> Reported by Nathan here:
> https://lore.kernel.org/all/YtmrCJjQrSbv8Aj1@dev-arch.thelio-3990X/
> 
>  drivers/misc/lkdtm/bugs.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/misc/lkdtm/bugs.c b/drivers/misc/lkdtm/bugs.c
> index 009239ad1d8a..6381255aaecc 100644
> --- a/drivers/misc/lkdtm/bugs.c
> +++ b/drivers/misc/lkdtm/bugs.c
> @@ -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)
>  
> -- 
> 2.37.1.359.gd136c6c3e2-goog
> 

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] drivers: lkdtm: fix clang -Wformat warning
  2022-07-21 21:20 [PATCH] drivers: lkdtm: fix clang -Wformat warning Justin Stitt
  2022-07-21 21:34 ` Nathan Chancellor
@ 2022-07-21 21:42 ` Nick Desaulniers
  2022-07-21 21:57   ` [PATCH v2] " Justin Stitt
  1 sibling, 1 reply; 6+ messages in thread
From: Nick Desaulniers @ 2022-07-21 21:42 UTC (permalink / raw)
  To: Justin Stitt
  Cc: Kees Cook, Arnd Bergmann, Greg Kroah-Hartman, Nathan Chancellor,
	Tom Rix, linux-kernel, llvm

On Thu, Jul 21, 2022 at 2:20 PM Justin Stitt <justinstitt@google.com> wrote:
>
> 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`.
>
> Link: https://github.com/ClangBuiltLinux/linux/issues/378
> Reported-by: Nathan Chancellor <nathan@kernel.org>
> Suggested-by: Nathan Chancellor <nathan@kernel.org>
> Signed-off-by: Justin Stitt <justinstitt@google.com>
> ---
> Reported by Nathan here:
> https://lore.kernel.org/all/YtmrCJjQrSbv8Aj1@dev-arch.thelio-3990X/
>
>  drivers/misc/lkdtm/bugs.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/misc/lkdtm/bugs.c b/drivers/misc/lkdtm/bugs.c
> index 009239ad1d8a..6381255aaecc 100644
> --- a/drivers/misc/lkdtm/bugs.c
> +++ b/drivers/misc/lkdtm/bugs.c
> @@ -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.

>  #endif
>  #define REC_NUM_DEFAULT ((THREAD_SIZE / REC_STACK_SIZE) * 2)
>
> --
> 2.37.1.359.gd136c6c3e2-goog
>


-- 
Thanks,
~Nick Desaulniers

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH v2] drivers: lkdtm: fix clang -Wformat warning
  2022-07-21 21:42 ` Nick Desaulniers
@ 2022-07-21 21:57   ` Justin Stitt
  2022-07-21 22:05     ` Nathan Chancellor
  2022-07-23 13:42     ` Kees Cook
  0 siblings, 2 replies; 6+ messages in thread
From: Justin Stitt @ 2022-07-21 21:57 UTC (permalink / raw)
  To: ndesaulniers
  Cc: arnd, gregkh, justinstitt, keescook, linux-kernel, llvm, nathan, trix

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)`.

Link: https://github.com/ClangBuiltLinux/linux/issues/378
Reported-by: Nathan Chancellor <nathan@kernel.org>
Suggested-by: Nathan Chancellor <nathan@kernel.org>
Suggested-by: Nick Desaulniers <ndesaulniers@google.com>
Signed-off-by: Justin Stitt <justinstitt@google.com>
---
Reported by Nathan here:
https://lore.kernel.org/all/YtmrCJjQrSbv8Aj1@dev-arch.thelio-3990X/

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(-)

diff --git a/drivers/misc/lkdtm/bugs.c b/drivers/misc/lkdtm/bugs.c
index 009239ad1d8a..48821f4c2b21 100644
--- a/drivers/misc/lkdtm/bugs.c
+++ b/drivers/misc/lkdtm/bugs.c
@@ -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)
 
-- 
2.37.1.359.gd136c6c3e2-goog


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH v2] drivers: lkdtm: fix clang -Wformat warning
  2022-07-21 21:57   ` [PATCH v2] " Justin Stitt
@ 2022-07-21 22:05     ` Nathan Chancellor
  2022-07-23 13:42     ` Kees Cook
  1 sibling, 0 replies; 6+ messages in thread
From: Nathan Chancellor @ 2022-07-21 22:05 UTC (permalink / raw)
  To: Justin Stitt
  Cc: ndesaulniers, arnd, gregkh, keescook, linux-kernel, llvm, trix

On Thu, Jul 21, 2022 at 02:57:06PM -0700, Justin Stitt wrote:
> 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)`.
> 
> Link: https://github.com/ClangBuiltLinux/linux/issues/378
> Reported-by: Nathan Chancellor <nathan@kernel.org>
> Suggested-by: Nathan Chancellor <nathan@kernel.org>

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.

> Suggested-by: Nick Desaulniers <ndesaulniers@google.com>
> Signed-off-by: Justin Stitt <justinstitt@google.com>

Reviewed-by: Nathan Chancellor <nathan@kernel.org>
Tested-by: Nathan Chancellor <nathan@kernel.org>

> ---
> Reported by Nathan here:
> https://lore.kernel.org/all/YtmrCJjQrSbv8Aj1@dev-arch.thelio-3990X/
> 
> 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(-)
> 
> diff --git a/drivers/misc/lkdtm/bugs.c b/drivers/misc/lkdtm/bugs.c
> index 009239ad1d8a..48821f4c2b21 100644
> --- a/drivers/misc/lkdtm/bugs.c
> +++ b/drivers/misc/lkdtm/bugs.c
> @@ -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)
>  
> -- 
> 2.37.1.359.gd136c6c3e2-goog
> 
> 

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v2] drivers: lkdtm: fix clang -Wformat warning
  2022-07-21 21:57   ` [PATCH v2] " Justin Stitt
  2022-07-21 22:05     ` Nathan Chancellor
@ 2022-07-23 13:42     ` Kees Cook
  1 sibling, 0 replies; 6+ messages in thread
From: Kees Cook @ 2022-07-23 13:42 UTC (permalink / raw)
  To: Justin Stitt, ndesaulniers
  Cc: arnd, gregkh, justinstitt, linux-kernel, llvm, nathan, trix



On July 21, 2022 2:57:06 PM PDT, Justin Stitt <justinstitt@google.com> wrote:
>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)`.
>
>Link: https://github.com/ClangBuiltLinux/linux/issues/378
>Reported-by: Nathan Chancellor <nathan@kernel.org>
>Suggested-by: Nathan Chancellor <nathan@kernel.org>
>Suggested-by: Nick Desaulniers <ndesaulniers@google.com>
>Signed-off-by: Justin Stitt <justinstitt@google.com>

Thanks!

Acked-by: Kees Cook <keescook@chromium.org>
Fixes: 24cccab42c419 ("lkdtm/bugs: Adjust recursion test to avoid elision")


-- 
Kees Cook

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2022-07-23 13:43 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-21 21:20 [PATCH] drivers: lkdtm: fix clang -Wformat warning Justin Stitt
2022-07-21 21:34 ` Nathan Chancellor
2022-07-21 21:42 ` Nick Desaulniers
2022-07-21 21:57   ` [PATCH v2] " Justin Stitt
2022-07-21 22:05     ` Nathan Chancellor
2022-07-23 13:42     ` Kees Cook

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.