mfd: db8500: Avoid uninitialized variable reference
authorArnd Bergmann <arnd@arndb.de>
Mon, 25 Jan 2016 16:02:24 +0000 (17:02 +0100)
committerLee Jones <lee.jones@linaro.org>
Wed, 16 Mar 2016 08:50:16 +0000 (08:50 +0000)
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>
Acked-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Lee Jones <lee.jones@linaro.org>
drivers/mfd/db8500-prcmu.c

index e6e4bacb09ee5d2636576c3363c97a1a5c5f72c8..2f4a1279b0940565bdacdbe8057c6386f9bd1805 100644 (file)
@@ -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;