linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mfd: arizona: fix undefined behavior
@ 2019-03-22 14:33 Arnd Bergmann
  2019-03-22 15:57 ` Nathan Chancellor
  2019-03-22 17:03 ` Charles Keepax
  0 siblings, 2 replies; 3+ messages in thread
From: Arnd Bergmann @ 2019-03-22 14:33 UTC (permalink / raw)
  To: Lee Jones
  Cc: clang-built-linux, Nick Desaulniers, Nathan Chancellor,
	Arnd Bergmann, Charles Keepax, Linus Walleij, Sapthagiri Baratam,
	Colin Ian King, patches, linux-kernel

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>
---
 drivers/mfd/arizona-core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/mfd/arizona-core.c b/drivers/mfd/arizona-core.c
index 27b61639cdc7..0ca0fc9a67fd 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);
-- 
2.20.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] mfd: arizona: fix undefined behavior
  2019-03-22 14:33 [PATCH] mfd: arizona: fix undefined behavior Arnd Bergmann
@ 2019-03-22 15:57 ` Nathan Chancellor
  2019-03-22 17:03 ` Charles Keepax
  1 sibling, 0 replies; 3+ messages in thread
From: Nathan Chancellor @ 2019-03-22 15:57 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: Lee Jones, clang-built-linux, Nick Desaulniers, Charles Keepax,
	Linus Walleij, Sapthagiri Baratam, Colin Ian King, patches,
	linux-kernel

On Fri, Mar 22, 2019 at 03:33:37PM +0100, Arnd Bergmann wrote:
> 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>

Took me a bit to follow the flow of this function. I agree that without
restructuring it, zero initializing this variable to shut up the warning
is the path of least resistance (clang must evaluate variables in
isolation like I did until I fully read the commit message *facepalm*).

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

> ---
>  drivers/mfd/arizona-core.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/mfd/arizona-core.c b/drivers/mfd/arizona-core.c
> index 27b61639cdc7..0ca0fc9a67fd 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);
> -- 
> 2.20.0
> 

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] mfd: arizona: fix undefined behavior
  2019-03-22 14:33 [PATCH] mfd: arizona: fix undefined behavior Arnd Bergmann
  2019-03-22 15:57 ` Nathan Chancellor
@ 2019-03-22 17:03 ` Charles Keepax
  1 sibling, 0 replies; 3+ messages in thread
From: Charles Keepax @ 2019-03-22 17:03 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: Lee Jones, clang-built-linux, Nick Desaulniers,
	Nathan Chancellor, Linus Walleij, Sapthagiri Baratam,
	Colin Ian King, patches, linux-kernel

On Fri, Mar 22, 2019 at 03:33:37PM +0100, Arnd Bergmann wrote:
> 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>
> ---

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

Thanks,
Charles

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2019-03-22 17:03 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-03-22 14:33 [PATCH] mfd: arizona: fix undefined behavior Arnd Bergmann
2019-03-22 15:57 ` Nathan Chancellor
2019-03-22 17:03 ` Charles Keepax

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