Skip to contentSkip to conversation

mfd: arizona: fix undefined behavior

PATCH RESEND Applied Charles Keepax 3 participants 9 messages May 20, 2019 – Jun 12, 2019

Subsystems (3)
lore
Share & tools
lore

Charles Keepax

author maintainer
#0 lore raw

PATCH RESEND 1/4 mfd: arizona: fix undefined behavior

From: Arnd Bergmann <[email protected]>

When the driver is used with a subdevice that is disabled in the kernel configuration, clang gets a little confused about the control flow and fails to notice that n_subdevs is only uninitialized when subdevs is NULL, and we check for that, leading to a false-positive warning:

drivers/mfd/arizona-core.c:1423:19: error: variable 'n_subdevs' is uninitialized when used here

      [-Werror,-Wuninitialized]
                              subdevs, n_subdevs, NULL, 0, NULL);
                                       ^~~~~~~~~
drivers/mfd/arizona-core.c:999:15: note: initialize the variable 'n_subdevs' to silence this warning
        int n_subdevs, ret, i;
                     ^
                      = 0

Ideally, we would rearrange the code to avoid all those early initializations and have an explicit exit in each disabled case, but it's much easier to chicken out and add one more initialization here to shut up the warning.

---
 drivers/mfd/arizona-core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/mfd/arizona-core.c +1 -1
index 27b61639cdc7e..0ca0fc9a67fd9 100644
@@ -996,7 +996,7 @@ int arizona_dev_init(struct arizona *arizona)
 	unsigned int reg, val;
 	int (*apply_patch)(struct arizona *) = NULL;
 	const struct mfd_cell *subdevs = NULL;
-	int n_subdevs, ret, i;
+	int n_subdevs = 0, ret, i;
 
 	dev_set_drvdata(arizona->dev, arizona);
 	mutex_init(&arizona->clk_lock);
Signature · 1 line
2.11.0
author maintainer
#1 lore raw

PATCH RESEND 2/4 mfd: madera: Fix bad reference to pinctrl.txt file

From: Otto Sabart <[email protected]>

The pinctrl.txt file was converted into reStructuredText and moved into driver-api folder. This patch updates the broken reference.

Fixes 5a9b73832e9e ("pinctrl.txt: move it to the driver-api book")
---
 include/linux/mfd/madera/pdata.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
include/linux/mfd/madera/pdata.h +2 -1
index 8dc852402dbb1..dd00ab824e5be 100644
@@ -34,7 +34,8 @@ struct madera_codec_pdata;
  * @micvdd:	    Substruct of pdata for the MICVDD regulator
  * @irq_flags:	    Mode for primary IRQ (defaults to active low)
  * @gpio_base:	    Base GPIO number
- * @gpio_configs:   Array of GPIO configurations (See Documentation/pinctrl.txt)
+ * @gpio_configs:   Array of GPIO configurations (See
+ *		    Documentation/driver-api/pinctl.rst)
  * @n_gpio_configs: Number of entries in gpio_configs
  * @gpsw:	    General purpose switch mode setting. Depends on the external
  *		    hardware connected to the switch. (See the SW1_MODE field
Signature · 1 line
2.11.0
Reviewed-by on v1 2/4
#2 lore raw

Re: [PATCH 2/4 RESEND] mfd: madera: Fix bad reference to pinctrl.txt file

Em Mon, 20 May 2019 10:06:26 +0100
Charles Keepax <[email protected]> escreveu:

Quoted 8 lines

From: Otto Sabart <[email protected]>

The pinctrl.txt file was converted into reStructuredText and moved into driver-api folder. This patch updates the broken reference.

Fixes 5a9b73832e9e ("pinctrl.txt: move it to the driver-api book")
Quoted 9 lines
---
 include/linux/mfd/madera/pdata.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
include/linux/mfd/madera/pdata.h +0 -0
index 8dc852402dbb1..dd00ab824e5be 100644

include/linux/mfd/madera/pdata.h struct madera_codec_pdata; · line 41

Quoted 9 lines
include/linux/mfd/madera/pdata.h +2 -1
@@ -34,7 +34,8 @@ struct madera_codec_pdata;
  * @micvdd:	    Substruct of pdata for the MICVDD regulator
  * @irq_flags:	    Mode for primary IRQ (defaults to active low)
  * @gpio_base:	    Base GPIO number
- * @gpio_configs:   Array of GPIO configurations (See Documentation/pinctrl.txt)
+ * @gpio_configs:   Array of GPIO configurations (See
+ *		    Documentation/driver-api/pinctl.rst)
  * @n_gpio_configs: Number of entries in gpio_configs
  * @gpsw:	    General purpose switch mode setting. Depends on the external
  *		    hardware connected to the switch. (See the SW1_MODE field

Thanks,
Mauro

Applied
#3 lore raw

Re: [PATCH 2/4 RESEND] mfd: madera: Fix bad reference to pinctrl.txt file

In reply to Charles Keepax
Quoted 11 lines · Charles Keepax

From: Otto Sabart <[email protected]>

The pinctrl.txt file was converted into reStructuredText and moved into driver-api folder. This patch updates the broken reference.

Fixes 5a9b73832e9e ("pinctrl.txt: move it to the driver-api book")
---
 include/linux/mfd/madera/pdata.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Applied, thanks.

Signature · 4 lines
Lee Jones [李琼斯]
Linaro Services Technical Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog
author maintainer
#4 lore raw

PATCH 3/4 mfd: madera: Fix potential uninitialised use of variable

In reply to Charles Keepax

From: Stuart Henderson <[email protected]>

regmap_read won't set val to anything if an ACKed bus fails.

---
 drivers/mfd/madera-core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/mfd/madera-core.c +1 -1
index 2a77988d04625..1b78c5c844a81 100644
@@ -139,7 +139,7 @@ EXPORT_SYMBOL_GPL(madera_name_from_type);
 static int madera_wait_for_boot(struct madera *madera)
 {
 	ktime_t timeout;
-	unsigned int val;
+	unsigned int val = 0;
 	int ret = 0;
 
 	/*
Signature · 1 line
2.11.0
Applied
#5 lore raw

Re: [PATCH 3/4] mfd: madera: Fix potential uninitialised use of variable

Quoted 9 lines · Charles Keepax

From: Stuart Henderson <[email protected]>

regmap_read won't set val to anything if an ACKed bus fails.

---
 drivers/mfd/madera-core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Applied, thanks.

Signature · 4 lines
Lee Jones [李琼斯]
Linaro Services Technical Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog
author maintainer
#6 lore raw

PATCH 4/4 mfd: madera: Add supply mapping for MICVDD

In reply to Charles Keepax

Currently we are relying on the exact match of the regulator name to find MICVDD, we should add an explicit supply mapping to allow this to be found more reliably.

---
 drivers/mfd/madera-core.c | 18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)
drivers/mfd/madera-core.c +15 -3
index 1b78c5c844a81..515283e595aa0 100644
@@ -59,7 +59,11 @@ static const struct mfd_cell cs47l35_devs[] = {
 	{ .name = "madera-irq", },
 	{ .name = "madera-micsupp", },
 	{ .name = "madera-gpio", },
-	{ .name = "madera-extcon", },
+	{
+		.name = "madera-extcon",
+		.parent_supplies = cs47l35_supplies,
+		.num_parent_supplies = 1, /* We only need MICVDD */
+	},
 	{
 		.name = "cs47l35-codec",
 		.parent_supplies = cs47l35_supplies,
@@ -83,7 +87,11 @@ static const struct mfd_cell cs47l85_devs[] = {
 	{ .name = "madera-irq", },
 	{ .name = "madera-micsupp" },
 	{ .name = "madera-gpio", },
-	{ .name = "madera-extcon", },
+	{
+		.name = "madera-extcon",
+		.parent_supplies = cs47l85_supplies,
+		.num_parent_supplies = 1, /* We only need MICVDD */
+	},
 	{
 		.name = "cs47l85-codec",
 		.parent_supplies = cs47l85_supplies,
@@ -105,7 +113,11 @@ static const struct mfd_cell cs47l90_devs[] = {
 	{ .name = "madera-irq", },
 	{ .name = "madera-micsupp", },
 	{ .name = "madera-gpio", },
-	{ .name = "madera-extcon", },
+	{
+		.name = "madera-extcon",
+		.parent_supplies = cs47l90_supplies,
+		.num_parent_supplies = 1, /* We only need MICVDD */
+	},
 	{
 		.name = "cs47l90-codec",
 		.parent_supplies = cs47l90_supplies,
Signature · 1 line
2.11.0
Applied
#7 lore raw

Re: [PATCH 4/4] mfd: madera: Add supply mapping for MICVDD

Quoted 8 lines · Charles Keepax

Currently we are relying on the exact match of the regulator name to find MICVDD, we should add an explicit supply mapping to allow this to be found more reliably.

---
 drivers/mfd/madera-core.c | 18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)

Applied, thanks.

Signature · 4 lines
Lee Jones [李琼斯]
Linaro Services Technical Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog
Applied
#8 lore raw
In reply to Charles Keepax
Quoted 22 lines · Charles Keepax

From: Arnd Bergmann <[email protected]>

When the driver is used with a subdevice that is disabled in the kernel configuration, clang gets a little confused about the control flow and fails to notice that n_subdevs is only uninitialized when subdevs is NULL, and we check for that, leading to a false-positive warning:

drivers/mfd/arizona-core.c:1423:19: error: variable 'n_subdevs' is uninitialized when used here

      [-Werror,-Wuninitialized]
                              subdevs, n_subdevs, NULL, 0, NULL);
                                       ^~~~~~~~~
drivers/mfd/arizona-core.c:999:15: note: initialize the variable 'n_subdevs' to silence this warning
        int n_subdevs, ret, i;
                     ^
                      = 0

Ideally, we would rearrange the code to avoid all those early initializations and have an explicit exit in each disabled case, but it's much easier to chicken out and add one more initialization here to shut up the warning.

Quoted 6 lines
---
 drivers/mfd/arizona-core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Applied, thanks.

Signature · 4 lines
Lee Jones [李琼斯]
Linaro Services Technical Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog