diff mbox series

[1/4,RESEND] mfd: arizona: fix undefined behavior

Message ID 20190520090628.29061-1-ckeepax@opensource.cirrus.com
State New
Headers show
Series [1/4,RESEND] mfd: arizona: fix undefined behavior | expand

Commit Message

Charles Keepax May 20, 2019, 9:06 a.m. UTC
From: Arnd Bergmann <arnd@arndb.de>


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.

Signed-off-by: Arnd Bergmann <arnd@arndb.de>

Reviewed-by: Nathan Chancellor <natechancellor@gmail.com>

Signed-off-by: Charles Keepax <ckeepax@opensource.cirrus.com>

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

-- 
2.11.0

Comments

Mauro Carvalho Chehab May 27, 2019, 1:52 p.m. UTC | #1
Em Mon, 20 May 2019 10:06:26 +0100
Charles Keepax <ckeepax@opensource.cirrus.com> escreveu:

> From: Otto Sabart <ottosabart@seberm.com>

> 

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

> Signed-off-by: Otto Sabart <ottosabart@seberm.com>

> Signed-off-by: Charles Keepax <ckeepax@opensource.cirrus.com>


Reviewed-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>


> ---

>  include/linux/mfd/madera/pdata.h | 3 ++-

>  1 file changed, 2 insertions(+), 1 deletion(-)

> 

> diff --git a/include/linux/mfd/madera/pdata.h b/include/linux/mfd/madera/pdata.h

> index 8dc852402dbb1..dd00ab824e5be 100644

> --- a/include/linux/mfd/madera/pdata.h

> +++ b/include/linux/mfd/madera/pdata.h

> @@ -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
Lee Jones June 12, 2019, 8:31 a.m. UTC | #2
On Mon, 20 May 2019, Charles Keepax wrote:

> From: Arnd Bergmann <arnd@arndb.de>

> 

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

> 

> Signed-off-by: Arnd Bergmann <arnd@arndb.de>

> Reviewed-by: Nathan Chancellor <natechancellor@gmail.com>

> Signed-off-by: Charles Keepax <ckeepax@opensource.cirrus.com>

> ---

>  drivers/mfd/arizona-core.c | 2 +-

>  1 file changed, 1 insertion(+), 1 deletion(-)


Applied, thanks.

-- 
Lee Jones [李琼斯]
Linaro Services Technical Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog
Lee Jones June 12, 2019, 8:31 a.m. UTC | #3
On Mon, 20 May 2019, Charles Keepax wrote:

> From: Otto Sabart <ottosabart@seberm.com>

> 

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

> Signed-off-by: Otto Sabart <ottosabart@seberm.com>

> Signed-off-by: Charles Keepax <ckeepax@opensource.cirrus.com>

> ---

>  include/linux/mfd/madera/pdata.h | 3 ++-

>  1 file changed, 2 insertions(+), 1 deletion(-)


Applied, thanks.

-- 
Lee Jones [李琼斯]
Linaro Services Technical Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog
Lee Jones June 12, 2019, 8:31 a.m. UTC | #4
On Mon, 20 May 2019, Charles Keepax wrote:

> From: Stuart Henderson <stuarth@opensource.cirrus.com>

> 

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

> 

> Signed-off-by: Stuart Henderson <stuarth@opensource.cirrus.com>

> Signed-off-by: Charles Keepax <ckeepax@opensource.cirrus.com>

> ---

>  drivers/mfd/madera-core.c | 2 +-

>  1 file changed, 1 insertion(+), 1 deletion(-)


Applied, thanks.

-- 
Lee Jones [李琼斯]
Linaro Services Technical Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog
Lee Jones June 12, 2019, 8:32 a.m. UTC | #5
On Mon, 20 May 2019, Charles Keepax wrote:

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

> 

> Signed-off-by: Charles Keepax <ckeepax@opensource.cirrus.com>

> ---

>  drivers/mfd/madera-core.c | 18 +++++++++++++++---

>  1 file changed, 15 insertions(+), 3 deletions(-)


Applied, thanks.

-- 
Lee Jones [李琼斯]
Linaro Services Technical Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog
diff mbox series

Patch

diff --git a/drivers/mfd/arizona-core.c b/drivers/mfd/arizona-core.c
index 27b61639cdc7e..0ca0fc9a67fd9 100644
--- a/drivers/mfd/arizona-core.c
+++ b/drivers/mfd/arizona-core.c
@@ -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);