Skip to content

Commit

Permalink
pwm: meson: Handle unknown ID values
Browse files Browse the repository at this point in the history
When building with -Wmaybe-uninitialized, we get a couple of harmless
warnings about three functions in this new driver that don't look
safe to the compiler:

drivers/pwm/pwm-meson.c: In function 'meson_pwm_get_state':
drivers/pwm/pwm-meson.c:355:26: error: 'mask' may be used uninitialized in this function [-Werror=maybe-uninitialized]
drivers/pwm/pwm-meson.c: In function 'meson_pwm_disable':
drivers/pwm/pwm-meson.c:263:13: error: 'enable' may be used uninitialized in this function [-Werror=maybe-uninitialized]
drivers/pwm/pwm-meson.c: In function 'meson_pwm_apply':
drivers/pwm/pwm-meson.c:231:13: error: 'clk_shift' may be used uninitialized in this function [-Werror=maybe-uninitialized]
drivers/pwm/pwm-meson.c:231:36: error: 'enable' may be used uninitialized in this function [-Werror=maybe-uninitialized]
drivers/pwm/pwm-meson.c:231:24: error: 'clk_enable' may be used uninitialized in this function [-Werror=maybe-uninitialized]

Specifically, if we have a device with an ID other than 0 or 1,
this would result in undefined behavior. This is currently not
possible, but the compiler cannot be expected to know this.

This patch adds a 'default' clause to let the compiler know
what to do instead, which shuts up the warning and makes the
code slightly more resiliant in case it gets extended to other
identifiers.

Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Acked-by: Neil Armstrong <narmstrong@baylibre.com>
Signed-off-by: Thierry Reding <thierry.reding@gmail.com>
  • Loading branch information
Arnd Bergmann authored and Thierry Reding committed Sep 8, 2016
1 parent 7d8a600 commit 2fbc487
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions drivers/pwm/pwm-meson.c
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,9 @@ static void meson_pwm_enable(struct meson_pwm *meson,
enable = MISC_B_EN;
offset = REG_PWM_B;
break;

default:
return;
}

value = readl(meson->base + REG_MISC_AB);
Expand Down Expand Up @@ -273,6 +276,9 @@ static void meson_pwm_disable(struct meson_pwm *meson, unsigned int id)
case 1:
enable = MISC_B_EN;
break;

default:
return;
}

value = readl(meson->base + REG_MISC_AB);
Expand Down Expand Up @@ -352,6 +358,9 @@ static void meson_pwm_get_state(struct pwm_chip *chip, struct pwm_device *pwm,
case 1:
mask = MISC_B_EN;
break;

default:
return;
}

value = readl(meson->base + REG_MISC_AB);
Expand Down

0 comments on commit 2fbc487

Please sign in to comment.