linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mfd: db8500: avoid uninitialized variable reference
@ 2016-01-25 16:02 Arnd Bergmann
  2016-01-28 10:37 ` Linus Walleij
  2016-01-28 11:15 ` Lee Jones
  0 siblings, 2 replies; 3+ messages in thread
From: Arnd Bergmann @ 2016-01-25 16:02 UTC (permalink / raw)
  To: linux-arm-kernel

The prcmu_config_clkout() function ensures that the 'clkout' argument
can only be '0' or '1' using an appropriate BUG_ON(), so the compiler
should know that the div_mask, mask, and bits variables are always
initialized later on. However, it doesn't understand this in gcc-5.2
and produces a false positive warning instead:

drivers/mfd/db8500-prcmu.c: In function 'prcmu_config_clkout':
drivers/mfd/db8500-prcmu.c:762:10: error: 'div_mask' may be used uninitialized in this function [-Werror=maybe-uninitialized]
  if (val & div_mask) {
          ^
drivers/mfd/db8500-prcmu.c:769:13: error: 'mask' may be used uninitialized in this function [-Werror=maybe-uninitialized]
    if ((val & mask & ~div_mask) != bits) {
             ^
drivers/mfd/db8500-prcmu.c:757:7: error: 'bits' may be used uninitialized in this function [-Werror=maybe-uninitialized]

Replacing the switch() statement with an equivalent if() lets
gcc figure this out reliably and avoids the warnings.

Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
 drivers/mfd/db8500-prcmu.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/drivers/mfd/db8500-prcmu.c b/drivers/mfd/db8500-prcmu.c
index 12099b09a9a7..c0a86aeb1733 100644
--- a/drivers/mfd/db8500-prcmu.c
+++ b/drivers/mfd/db8500-prcmu.c
@@ -739,20 +739,17 @@ int prcmu_config_clkout(u8 clkout, u8 source, u8 div)
 	if (!div && !requests[clkout])
 		return -EINVAL;
 
-	switch (clkout) {
-	case 0:
+	if (clkout == 0) {
 		div_mask = PRCM_CLKOCR_CLKODIV0_MASK;
 		mask = (PRCM_CLKOCR_CLKODIV0_MASK | PRCM_CLKOCR_CLKOSEL0_MASK);
 		bits = ((source << PRCM_CLKOCR_CLKOSEL0_SHIFT) |
 			(div << PRCM_CLKOCR_CLKODIV0_SHIFT));
-		break;
-	case 1:
+	} else {
 		div_mask = PRCM_CLKOCR_CLKODIV1_MASK;
 		mask = (PRCM_CLKOCR_CLKODIV1_MASK | PRCM_CLKOCR_CLKOSEL1_MASK |
 			PRCM_CLKOCR_CLK1TYPE);
 		bits = ((source << PRCM_CLKOCR_CLKOSEL1_SHIFT) |
 			(div << PRCM_CLKOCR_CLKODIV1_SHIFT));
-		break;
 	}
 	bits &= mask;
 
-- 
2.7.0

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

* [PATCH] mfd: db8500: avoid uninitialized variable reference
  2016-01-25 16:02 [PATCH] mfd: db8500: avoid uninitialized variable reference Arnd Bergmann
@ 2016-01-28 10:37 ` Linus Walleij
  2016-01-28 11:15 ` Lee Jones
  1 sibling, 0 replies; 3+ messages in thread
From: Linus Walleij @ 2016-01-28 10:37 UTC (permalink / raw)
  To: linux-arm-kernel

On Mon, Jan 25, 2016 at 5:02 PM, Arnd Bergmann <arnd@arndb.de> wrote:

> The prcmu_config_clkout() function ensures that the 'clkout' argument
> can only be '0' or '1' using an appropriate BUG_ON(), so the compiler
> should know that the div_mask, mask, and bits variables are always
> initialized later on. However, it doesn't understand this in gcc-5.2
> and produces a false positive warning instead:
>
> drivers/mfd/db8500-prcmu.c: In function 'prcmu_config_clkout':
> drivers/mfd/db8500-prcmu.c:762:10: error: 'div_mask' may be used uninitialized in this function [-Werror=maybe-uninitialized]
>   if (val & div_mask) {
>           ^
> drivers/mfd/db8500-prcmu.c:769:13: error: 'mask' may be used uninitialized in this function [-Werror=maybe-uninitialized]
>     if ((val & mask & ~div_mask) != bits) {
>              ^
> drivers/mfd/db8500-prcmu.c:757:7: error: 'bits' may be used uninitialized in this function [-Werror=maybe-uninitialized]
>
> Replacing the switch() statement with an equivalent if() lets
> gcc figure this out reliably and avoids the warnings.
>
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>

OK then..
Acked-by: Linus Walleij <linus.walleij@linaro.org>

Yours,
Linus Walleij

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

* [PATCH] mfd: db8500: avoid uninitialized variable reference
  2016-01-25 16:02 [PATCH] mfd: db8500: avoid uninitialized variable reference Arnd Bergmann
  2016-01-28 10:37 ` Linus Walleij
@ 2016-01-28 11:15 ` Lee Jones
  1 sibling, 0 replies; 3+ messages in thread
From: Lee Jones @ 2016-01-28 11:15 UTC (permalink / raw)
  To: linux-arm-kernel

On Mon, 25 Jan 2016, Arnd Bergmann wrote:

> The prcmu_config_clkout() function ensures that the 'clkout' argument
> can only be '0' or '1' using an appropriate BUG_ON(), so the compiler
> should know that the div_mask, mask, and bits variables are always
> initialized later on. However, it doesn't understand this in gcc-5.2
> and produces a false positive warning instead:
> 
> drivers/mfd/db8500-prcmu.c: In function 'prcmu_config_clkout':
> drivers/mfd/db8500-prcmu.c:762:10: error: 'div_mask' may be used uninitialized in this function [-Werror=maybe-uninitialized]
>   if (val & div_mask) {
>           ^
> drivers/mfd/db8500-prcmu.c:769:13: error: 'mask' may be used uninitialized in this function [-Werror=maybe-uninitialized]
>     if ((val & mask & ~div_mask) != bits) {
>              ^
> drivers/mfd/db8500-prcmu.c:757:7: error: 'bits' may be used uninitialized in this function [-Werror=maybe-uninitialized]
> 
> Replacing the switch() statement with an equivalent if() lets
> gcc figure this out reliably and avoids the warnings.
> 
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
> ---
>  drivers/mfd/db8500-prcmu.c | 7 ++-----
>  1 file changed, 2 insertions(+), 5 deletions(-)

Applied, thanks.

> diff --git a/drivers/mfd/db8500-prcmu.c b/drivers/mfd/db8500-prcmu.c
> index 12099b09a9a7..c0a86aeb1733 100644
> --- a/drivers/mfd/db8500-prcmu.c
> +++ b/drivers/mfd/db8500-prcmu.c
> @@ -739,20 +739,17 @@ int prcmu_config_clkout(u8 clkout, u8 source, u8 div)
>  	if (!div && !requests[clkout])
>  		return -EINVAL;
>  
> -	switch (clkout) {
> -	case 0:
> +	if (clkout == 0) {
>  		div_mask = PRCM_CLKOCR_CLKODIV0_MASK;
>  		mask = (PRCM_CLKOCR_CLKODIV0_MASK | PRCM_CLKOCR_CLKOSEL0_MASK);
>  		bits = ((source << PRCM_CLKOCR_CLKOSEL0_SHIFT) |
>  			(div << PRCM_CLKOCR_CLKODIV0_SHIFT));
> -		break;
> -	case 1:
> +	} else {
>  		div_mask = PRCM_CLKOCR_CLKODIV1_MASK;
>  		mask = (PRCM_CLKOCR_CLKODIV1_MASK | PRCM_CLKOCR_CLKOSEL1_MASK |
>  			PRCM_CLKOCR_CLK1TYPE);
>  		bits = ((source << PRCM_CLKOCR_CLKOSEL1_SHIFT) |
>  			(div << PRCM_CLKOCR_CLKODIV1_SHIFT));
> -		break;
>  	}
>  	bits &= mask;
>  

-- 
Lee Jones
Linaro STMicroelectronics Landing Team Lead
Linaro.org ? Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog

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

end of thread, other threads:[~2016-01-28 11:15 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-01-25 16:02 [PATCH] mfd: db8500: avoid uninitialized variable reference Arnd Bergmann
2016-01-28 10:37 ` Linus Walleij
2016-01-28 11:15 ` 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).