* [PATCH] mfd: madera: work around false-positive -Wininitialized warning
@ 2025-08-07 7:19 Arnd Bergmann
2025-08-07 13:15 ` Richard Fitzgerald
2025-09-02 8:15 ` (subset) " Lee Jones
0 siblings, 2 replies; 3+ messages in thread
From: Arnd Bergmann @ 2025-08-07 7:19 UTC (permalink / raw)
To: Charles Keepax, Richard Fitzgerald, Lee Jones, Nathan Chancellor
Cc: Arnd Bergmann, Nick Desaulniers, Bill Wendling, Justin Stitt,
linux-sound, patches, linux-kernel, llvm
From: Arnd Bergmann <arnd@arndb.de>
clang-21 warns about one uninitialized variable getting dereferenced
in madera_dev_init:
drivers/mfd/madera-core.c:739:10: error: variable 'mfd_devs' is uninitialized when used here [-Werror,-Wuninitialized]
739 | mfd_devs, n_devs,
| ^~~~~~~~
drivers/mfd/madera-core.c:459:33: note: initialize the variable 'mfd_devs' to silence this warning
459 | const struct mfd_cell *mfd_devs;
| ^
| = NULL
The code is actually correct here because n_devs is only nonzero
when mfd_devs is a valid pointer, but this is impossible for the
compiler to see reliably.
Change the logic to check for the pointer as well, to make this easier
for the compiler to follow.
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
drivers/mfd/madera-core.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/mfd/madera-core.c b/drivers/mfd/madera-core.c
index bdbd5bfc9714..2f74a8c644a3 100644
--- a/drivers/mfd/madera-core.c
+++ b/drivers/mfd/madera-core.c
@@ -456,7 +456,7 @@ int madera_dev_init(struct madera *madera)
struct device *dev = madera->dev;
unsigned int hwid;
int (*patch_fn)(struct madera *) = NULL;
- const struct mfd_cell *mfd_devs;
+ const struct mfd_cell *mfd_devs = NULL;
int n_devs = 0;
int i, ret;
@@ -670,7 +670,7 @@ int madera_dev_init(struct madera *madera)
goto err_reset;
}
- if (!n_devs) {
+ if (!n_devs || !mfd_devs) {
dev_err(madera->dev, "Device ID 0x%x not a %s\n", hwid,
madera->type_name);
ret = -ENODEV;
--
2.39.5
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] mfd: madera: work around false-positive -Wininitialized warning
2025-08-07 7:19 [PATCH] mfd: madera: work around false-positive -Wininitialized warning Arnd Bergmann
@ 2025-08-07 13:15 ` Richard Fitzgerald
2025-09-02 8:15 ` (subset) " Lee Jones
1 sibling, 0 replies; 3+ messages in thread
From: Richard Fitzgerald @ 2025-08-07 13:15 UTC (permalink / raw)
To: Arnd Bergmann, Charles Keepax, Lee Jones, Nathan Chancellor
Cc: Arnd Bergmann, Nick Desaulniers, Bill Wendling, Justin Stitt,
linux-sound, patches, linux-kernel, llvm
On 07/08/2025 8:19 am, Arnd Bergmann wrote:
> From: Arnd Bergmann <arnd@arndb.de>
>
> clang-21 warns about one uninitialized variable getting dereferenced
> in madera_dev_init:
>
> drivers/mfd/madera-core.c:739:10: error: variable 'mfd_devs' is uninitialized when used here [-Werror,-Wuninitialized]
> 739 | mfd_devs, n_devs,
> | ^~~~~~~~
> drivers/mfd/madera-core.c:459:33: note: initialize the variable 'mfd_devs' to silence this warning
> 459 | const struct mfd_cell *mfd_devs;
> | ^
> | = NULL
>
> The code is actually correct here because n_devs is only nonzero
> when mfd_devs is a valid pointer, but this is impossible for the
> compiler to see reliably.
>
> Change the logic to check for the pointer as well, to make this easier
> for the compiler to follow.
>
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
> ---
> drivers/mfd/madera-core.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/mfd/madera-core.c b/drivers/mfd/madera-core.c
> index bdbd5bfc9714..2f74a8c644a3 100644
> --- a/drivers/mfd/madera-core.c
> +++ b/drivers/mfd/madera-core.c
> @@ -456,7 +456,7 @@ int madera_dev_init(struct madera *madera)
> struct device *dev = madera->dev;
> unsigned int hwid;
> int (*patch_fn)(struct madera *) = NULL;
> - const struct mfd_cell *mfd_devs;
> + const struct mfd_cell *mfd_devs = NULL;
> int n_devs = 0;
> int i, ret;
>
> @@ -670,7 +670,7 @@ int madera_dev_init(struct madera *madera)
> goto err_reset;
> }
>
> - if (!n_devs) {
> + if (!n_devs || !mfd_devs) {
> dev_err(madera->dev, "Device ID 0x%x not a %s\n", hwid,
> madera->type_name);
> ret = -ENODEV;
Reviewed-by: Richard Fitzgerald <rf@opensource.cirrus.com>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: (subset) [PATCH] mfd: madera: work around false-positive -Wininitialized warning
2025-08-07 7:19 [PATCH] mfd: madera: work around false-positive -Wininitialized warning Arnd Bergmann
2025-08-07 13:15 ` Richard Fitzgerald
@ 2025-09-02 8:15 ` Lee Jones
1 sibling, 0 replies; 3+ messages in thread
From: Lee Jones @ 2025-09-02 8:15 UTC (permalink / raw)
To: Charles Keepax, Richard Fitzgerald, Lee Jones, Nathan Chancellor,
Arnd Bergmann
Cc: Arnd Bergmann, Nick Desaulniers, Bill Wendling, Justin Stitt,
linux-sound, patches, linux-kernel, llvm
On Thu, 07 Aug 2025 09:19:28 +0200, Arnd Bergmann wrote:
> clang-21 warns about one uninitialized variable getting dereferenced
> in madera_dev_init:
>
> drivers/mfd/madera-core.c:739:10: error: variable 'mfd_devs' is uninitialized when used here [-Werror,-Wuninitialized]
> 739 | mfd_devs, n_devs,
> | ^~~~~~~~
> drivers/mfd/madera-core.c:459:33: note: initialize the variable 'mfd_devs' to silence this warning
> 459 | const struct mfd_cell *mfd_devs;
> | ^
> | = NULL
>
> [...]
Applied, thanks!
[1/1] mfd: madera: work around false-positive -Wininitialized warning
commit: 3105933c2cf5e2e1908d31500fff72e28e0d94bf
--
Lee Jones [李琼斯]
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-09-02 8:15 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-07 7:19 [PATCH] mfd: madera: work around false-positive -Wininitialized warning Arnd Bergmann
2025-08-07 13:15 ` Richard Fitzgerald
2025-09-02 8:15 ` (subset) " Lee Jones
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).