Skip to contentSkip to conversation

mfd: madera: work around false-positive -Wininitialized warning

PATCH Applied Arnd Bergmann 3 participants 3 messages Aug 7, 2025 – Sep 2, 2025

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

PATCH 1/1 mfd: madera: work around false-positive -Wininitialized warning

From: Arnd Bergmann <[email protected]>

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.

---
 drivers/mfd/madera-core.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/mfd/madera-core.c +2 -2
index bdbd5bfc9714..2f74a8c644a3 100644
@@ -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;
Signature · 1 line
2.39.5
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 39 lines · Arnd Bergmann

From: Arnd Bergmann <[email protected]>

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.

---
  drivers/mfd/madera-core.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
drivers/mfd/madera-core.c +1 -1
index bdbd5bfc9714..2f74a8c644a3 100644
@@ -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;
 

drivers/mfd/madera-core.c int madera_dev_init(struct madera *madera) · line 676

Quoted 8 lines
drivers/mfd/madera-core.c +1 -1
@@ -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;
maintainer Applied
#2 lore raw

Re: (subset) [PATCH] mfd: madera: work around false-positive -Wininitialized warning

In reply to Arnd Bergmann
Quoted 4 lines · Arnd Bergmann

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]

Quoted 8 lines
  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 [李琼斯]