* [PATCH] of: declare string literals const
@ 2022-10-12 17:46 Christian Göttsche
2022-10-13 20:56 ` Nick Desaulniers
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Christian Göttsche @ 2022-10-12 17:46 UTC (permalink / raw)
Cc: Rob Herring, Frank Rowand, Nathan Chancellor, Nick Desaulniers,
Tom Rix, devicetree, linux-kernel, llvm
of_overlay_action_name() returns a string literal from a function local
array. Modifying string literals is undefined behavior which usage of
const pointer can avoid. of_overlay_action_name() is currently only
used once in overlay_notify() to print the returned value.
While on it declare the data array const as well.
Reported by Clang:
In file included from arch/x86/kernel/asm-offsets.c:22:
In file included from arch/x86/kernel/../kvm/vmx/vmx.h:5:
In file included from ./include/linux/kvm_host.h:19:
In file included from ./include/linux/msi.h:23:
In file included from ./arch/x86/include/asm/msi.h:5:
In file included from ./arch/x86/include/asm/irqdomain.h:5:
In file included from ./include/linux/irqdomain.h:35:
./include/linux/of.h:1555:3: error: initializing 'char *' with an expression of type 'const char[5]' discards qualifiers [-Werror,-Wincompatible-pointer-types-discards-qualifiers]
"init",
^~~~~~
./include/linux/of.h:1556:3: error: initializing 'char *' with an expression of type 'const char[10]' discards qualifiers [-Werror,-Wincompatible-pointer-types-discards-qualifiers]
"pre-apply",
^~~~~~~~~~~
./include/linux/of.h:1557:3: error: initializing 'char *' with an expression of type 'const char[11]' discards qualifiers [-Werror,-Wincompatible-pointer-types-discards-qualifiers]
"post-apply",
^~~~~~~~~~~~
./include/linux/of.h:1558:3: error: initializing 'char *' with an expression of type 'const char[11]' discards qualifiers [-Werror,-Wincompatible-pointer-types-discards-qualifiers]
"pre-remove",
^~~~~~~~~~~~
./include/linux/of.h:1559:3: error: initializing 'char *' with an expression of type 'const char[12]' discards qualifiers [-Werror,-Wincompatible-pointer-types-discards-qualifiers]
"post-remove",
^~~~~~~~~~~~~
Signed-off-by: Christian Göttsche <cgzones@googlemail.com>
---
include/linux/of.h | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/include/linux/of.h b/include/linux/of.h
index 6b79ef9a6541..8b9f94386dc3 100644
--- a/include/linux/of.h
+++ b/include/linux/of.h
@@ -1549,9 +1549,9 @@ enum of_overlay_notify_action {
OF_OVERLAY_POST_REMOVE,
};
-static inline char *of_overlay_action_name(enum of_overlay_notify_action action)
+static inline const char *of_overlay_action_name(enum of_overlay_notify_action action)
{
- static char *of_overlay_action_name[] = {
+ static const char *const of_overlay_action_name[] = {
"init",
"pre-apply",
"post-apply",
--
2.37.2
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] of: declare string literals const
2022-10-12 17:46 [PATCH] of: declare string literals const Christian Göttsche
@ 2022-10-13 20:56 ` Nick Desaulniers
2022-10-14 18:42 ` Frank Rowand
2022-10-14 21:11 ` Rob Herring
2 siblings, 0 replies; 4+ messages in thread
From: Nick Desaulniers @ 2022-10-13 20:56 UTC (permalink / raw)
To: Christian Göttsche
Cc: Rob Herring, Frank Rowand, Nathan Chancellor, Tom Rix,
devicetree, linux-kernel, llvm
On Wed, Oct 12, 2022 at 10:46 AM Christian Göttsche
<cgzones@googlemail.com> wrote:
>
> of_overlay_action_name() returns a string literal from a function local
> array. Modifying string literals is undefined behavior which usage of
> const pointer can avoid. of_overlay_action_name() is currently only
> used once in overlay_notify() to print the returned value.
>
> While on it declare the data array const as well.
>
> Reported by Clang:
>
> In file included from arch/x86/kernel/asm-offsets.c:22:
> In file included from arch/x86/kernel/../kvm/vmx/vmx.h:5:
> In file included from ./include/linux/kvm_host.h:19:
> In file included from ./include/linux/msi.h:23:
> In file included from ./arch/x86/include/asm/msi.h:5:
> In file included from ./arch/x86/include/asm/irqdomain.h:5:
> In file included from ./include/linux/irqdomain.h:35:
> ./include/linux/of.h:1555:3: error: initializing 'char *' with an expression of type 'const char[5]' discards qualifiers [-Werror,-Wincompatible-pointer-types-discards-qualifiers]
> "init",
> ^~~~~~
> ./include/linux/of.h:1556:3: error: initializing 'char *' with an expression of type 'const char[10]' discards qualifiers [-Werror,-Wincompatible-pointer-types-discards-qualifiers]
> "pre-apply",
> ^~~~~~~~~~~
> ./include/linux/of.h:1557:3: error: initializing 'char *' with an expression of type 'const char[11]' discards qualifiers [-Werror,-Wincompatible-pointer-types-discards-qualifiers]
> "post-apply",
> ^~~~~~~~~~~~
> ./include/linux/of.h:1558:3: error: initializing 'char *' with an expression of type 'const char[11]' discards qualifiers [-Werror,-Wincompatible-pointer-types-discards-qualifiers]
> "pre-remove",
> ^~~~~~~~~~~~
> ./include/linux/of.h:1559:3: error: initializing 'char *' with an expression of type 'const char[12]' discards qualifiers [-Werror,-Wincompatible-pointer-types-discards-qualifiers]
> "post-remove",
> ^~~~~~~~~~~~~
>
> Signed-off-by: Christian Göttsche <cgzones@googlemail.com>
Thanks for the patch!
Reviewed-by: Nick Desaulniers <ndesaulniers@google.com>
> ---
> include/linux/of.h | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/include/linux/of.h b/include/linux/of.h
> index 6b79ef9a6541..8b9f94386dc3 100644
> --- a/include/linux/of.h
> +++ b/include/linux/of.h
> @@ -1549,9 +1549,9 @@ enum of_overlay_notify_action {
> OF_OVERLAY_POST_REMOVE,
> };
>
> -static inline char *of_overlay_action_name(enum of_overlay_notify_action action)
> +static inline const char *of_overlay_action_name(enum of_overlay_notify_action action)
> {
> - static char *of_overlay_action_name[] = {
> + static const char *const of_overlay_action_name[] = {
> "init",
> "pre-apply",
> "post-apply",
> --
> 2.37.2
>
--
Thanks,
~Nick Desaulniers
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] of: declare string literals const
2022-10-12 17:46 [PATCH] of: declare string literals const Christian Göttsche
2022-10-13 20:56 ` Nick Desaulniers
@ 2022-10-14 18:42 ` Frank Rowand
2022-10-14 21:11 ` Rob Herring
2 siblings, 0 replies; 4+ messages in thread
From: Frank Rowand @ 2022-10-14 18:42 UTC (permalink / raw)
To: Christian Göttsche
Cc: Rob Herring, Nathan Chancellor, Nick Desaulniers, Tom Rix,
devicetree, linux-kernel, llvm
On 10/12/22 12:46, Christian Göttsche wrote:
> of_overlay_action_name() returns a string literal from a function local
> array. Modifying string literals is undefined behavior which usage of
> const pointer can avoid. of_overlay_action_name() is currently only
> used once in overlay_notify() to print the returned value.
>
> While on it declare the data array const as well.
>
> Reported by Clang:
>
> In file included from arch/x86/kernel/asm-offsets.c:22:
> In file included from arch/x86/kernel/../kvm/vmx/vmx.h:5:
> In file included from ./include/linux/kvm_host.h:19:
> In file included from ./include/linux/msi.h:23:
> In file included from ./arch/x86/include/asm/msi.h:5:
> In file included from ./arch/x86/include/asm/irqdomain.h:5:
> In file included from ./include/linux/irqdomain.h:35:
> ./include/linux/of.h:1555:3: error: initializing 'char *' with an expression of type 'const char[5]' discards qualifiers [-Werror,-Wincompatible-pointer-types-discards-qualifiers]
> "init",
> ^~~~~~
> ./include/linux/of.h:1556:3: error: initializing 'char *' with an expression of type 'const char[10]' discards qualifiers [-Werror,-Wincompatible-pointer-types-discards-qualifiers]
> "pre-apply",
> ^~~~~~~~~~~
> ./include/linux/of.h:1557:3: error: initializing 'char *' with an expression of type 'const char[11]' discards qualifiers [-Werror,-Wincompatible-pointer-types-discards-qualifiers]
> "post-apply",
> ^~~~~~~~~~~~
> ./include/linux/of.h:1558:3: error: initializing 'char *' with an expression of type 'const char[11]' discards qualifiers [-Werror,-Wincompatible-pointer-types-discards-qualifiers]
> "pre-remove",
> ^~~~~~~~~~~~
> ./include/linux/of.h:1559:3: error: initializing 'char *' with an expression of type 'const char[12]' discards qualifiers [-Werror,-Wincompatible-pointer-types-discards-qualifiers]
> "post-remove",
> ^~~~~~~~~~~~~
>
> Signed-off-by: Christian Göttsche <cgzones@googlemail.com>
> ---
> include/linux/of.h | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/include/linux/of.h b/include/linux/of.h
> index 6b79ef9a6541..8b9f94386dc3 100644
> --- a/include/linux/of.h
> +++ b/include/linux/of.h
> @@ -1549,9 +1549,9 @@ enum of_overlay_notify_action {
> OF_OVERLAY_POST_REMOVE,
> };
>
> -static inline char *of_overlay_action_name(enum of_overlay_notify_action action)
> +static inline const char *of_overlay_action_name(enum of_overlay_notify_action action)
> {
> - static char *of_overlay_action_name[] = {
> + static const char *const of_overlay_action_name[] = {
> "init",
> "pre-apply",
> "post-apply",
Reviewed-by: Frank Rowand <frowand.list@gmail.com>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] of: declare string literals const
2022-10-12 17:46 [PATCH] of: declare string literals const Christian Göttsche
2022-10-13 20:56 ` Nick Desaulniers
2022-10-14 18:42 ` Frank Rowand
@ 2022-10-14 21:11 ` Rob Herring
2 siblings, 0 replies; 4+ messages in thread
From: Rob Herring @ 2022-10-14 21:11 UTC (permalink / raw)
To: Christian Göttsche
Cc: linux-kernel, Tom Rix, Nick Desaulniers, Nathan Chancellor,
Frank Rowand, llvm, devicetree, Rob Herring
On Wed, 12 Oct 2022 19:46:22 +0200, Christian Göttsche wrote:
> of_overlay_action_name() returns a string literal from a function local
> array. Modifying string literals is undefined behavior which usage of
> const pointer can avoid. of_overlay_action_name() is currently only
> used once in overlay_notify() to print the returned value.
>
> While on it declare the data array const as well.
>
> Reported by Clang:
>
> In file included from arch/x86/kernel/asm-offsets.c:22:
> In file included from arch/x86/kernel/../kvm/vmx/vmx.h:5:
> In file included from ./include/linux/kvm_host.h:19:
> In file included from ./include/linux/msi.h:23:
> In file included from ./arch/x86/include/asm/msi.h:5:
> In file included from ./arch/x86/include/asm/irqdomain.h:5:
> In file included from ./include/linux/irqdomain.h:35:
> ./include/linux/of.h:1555:3: error: initializing 'char *' with an expression of type 'const char[5]' discards qualifiers [-Werror,-Wincompatible-pointer-types-discards-qualifiers]
> "init",
> ^~~~~~
> ./include/linux/of.h:1556:3: error: initializing 'char *' with an expression of type 'const char[10]' discards qualifiers [-Werror,-Wincompatible-pointer-types-discards-qualifiers]
> "pre-apply",
> ^~~~~~~~~~~
> ./include/linux/of.h:1557:3: error: initializing 'char *' with an expression of type 'const char[11]' discards qualifiers [-Werror,-Wincompatible-pointer-types-discards-qualifiers]
> "post-apply",
> ^~~~~~~~~~~~
> ./include/linux/of.h:1558:3: error: initializing 'char *' with an expression of type 'const char[11]' discards qualifiers [-Werror,-Wincompatible-pointer-types-discards-qualifiers]
> "pre-remove",
> ^~~~~~~~~~~~
> ./include/linux/of.h:1559:3: error: initializing 'char *' with an expression of type 'const char[12]' discards qualifiers [-Werror,-Wincompatible-pointer-types-discards-qualifiers]
> "post-remove",
> ^~~~~~~~~~~~~
>
> Signed-off-by: Christian Göttsche <cgzones@googlemail.com>
> ---
> include/linux/of.h | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
Applied, thanks!
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2022-10-14 21:11 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-12 17:46 [PATCH] of: declare string literals const Christian Göttsche
2022-10-13 20:56 ` Nick Desaulniers
2022-10-14 18:42 ` Frank Rowand
2022-10-14 21:11 ` Rob Herring
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).