linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] pwm: meson: handle unknown ID values
@ 2016-09-06 12:50 Arnd Bergmann
  2016-09-06 12:55 ` Neil Armstrong
  2016-09-08  9:23 ` Thierry Reding
  0 siblings, 2 replies; 4+ messages in thread
From: Arnd Bergmann @ 2016-09-06 12:50 UTC (permalink / raw)
  To: Thierry Reding
  Cc: Arnd Bergmann, Carlo Caione, Kevin Hilman, Neil Armstrong,
	linux-pwm, linux-arm-kernel, linux-amlogic, linux-kernel

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>
---
 drivers/pwm/pwm-meson.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/drivers/pwm/pwm-meson.c b/drivers/pwm/pwm-meson.c
index 566f5cb81021..25abd95dcc7b 100644
--- a/drivers/pwm/pwm-meson.c
+++ b/drivers/pwm/pwm-meson.c
@@ -242,6 +242,9 @@ static void meson_pwm_enable(struct meson_pwm *meson,
 		clk_enable = MISC_B_CLK_EN;
 		enable = MISC_B_EN;
 		break;
+
+	default:
+		return;
 	}
 
 	value = readl(meson->base + REG_MISC_AB);
@@ -270,6 +273,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);
@@ -349,6 +355,10 @@ static void meson_pwm_get_state(struct pwm_chip *chip, struct pwm_device *pwm,
 	case 1:
 		mask = MISC_B_EN;
 		break;
+
+	default:
+		state->enabled = 0;
+		return;
 	}
 
 	value = readl(meson->base + REG_MISC_AB);
-- 
2.9.0

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

* Re: [PATCH] pwm: meson: handle unknown ID values
  2016-09-06 12:50 [PATCH] pwm: meson: handle unknown ID values Arnd Bergmann
@ 2016-09-06 12:55 ` Neil Armstrong
  2016-09-08  9:23 ` Thierry Reding
  1 sibling, 0 replies; 4+ messages in thread
From: Neil Armstrong @ 2016-09-06 12:55 UTC (permalink / raw)
  To: Arnd Bergmann, Thierry Reding
  Cc: Carlo Caione, Kevin Hilman, linux-pwm, linux-arm-kernel,
	linux-amlogic, linux-kernel

On 09/06/2016 02:50 PM, Arnd Bergmann wrote:
> 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>
> ---
>  drivers/pwm/pwm-meson.c | 10 ++++++++++
>  1 file changed, 10 insertions(+)
> 
> diff --git a/drivers/pwm/pwm-meson.c b/drivers/pwm/pwm-meson.c
> index 566f5cb81021..25abd95dcc7b 100644
> --- a/drivers/pwm/pwm-meson.c
> +++ b/drivers/pwm/pwm-meson.c
> @@ -242,6 +242,9 @@ static void meson_pwm_enable(struct meson_pwm *meson,
>  		clk_enable = MISC_B_CLK_EN;
>  		enable = MISC_B_EN;
>  		break;
> +
> +	default:
> +		return;
>  	}
>  
>  	value = readl(meson->base + REG_MISC_AB);
> @@ -270,6 +273,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);
> @@ -349,6 +355,10 @@ static void meson_pwm_get_state(struct pwm_chip *chip, struct pwm_device *pwm,
>  	case 1:
>  		mask = MISC_B_EN;
>  		break;
> +
> +	default:
> +		state->enabled = 0;
> +		return;
>  	}
>  
>  	value = readl(meson->base + REG_MISC_AB);
> 

Acked-by: Neil Armstrong <narmstrong@baylibre.com>

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

* Re: [PATCH] pwm: meson: handle unknown ID values
  2016-09-06 12:50 [PATCH] pwm: meson: handle unknown ID values Arnd Bergmann
  2016-09-06 12:55 ` Neil Armstrong
@ 2016-09-08  9:23 ` Thierry Reding
  2016-09-08  9:29   ` Arnd Bergmann
  1 sibling, 1 reply; 4+ messages in thread
From: Thierry Reding @ 2016-09-08  9:23 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: Carlo Caione, Kevin Hilman, Neil Armstrong, linux-pwm,
	linux-arm-kernel, linux-amlogic, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 1723 bytes --]

On Tue, Sep 06, 2016 at 02:50:47PM +0200, Arnd Bergmann wrote:
> 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>
> ---
>  drivers/pwm/pwm-meson.c | 10 ++++++++++
>  1 file changed, 10 insertions(+)

Applied, though I left out the dummy assignment of state->enabled = 0
because that's dead code anyway.

Thanks,
Thierry

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 801 bytes --]

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

* Re: [PATCH] pwm: meson: handle unknown ID values
  2016-09-08  9:23 ` Thierry Reding
@ 2016-09-08  9:29   ` Arnd Bergmann
  0 siblings, 0 replies; 4+ messages in thread
From: Arnd Bergmann @ 2016-09-08  9:29 UTC (permalink / raw)
  To: Thierry Reding
  Cc: Carlo Caione, Kevin Hilman, Neil Armstrong, linux-pwm,
	linux-arm-kernel, linux-amlogic, linux-kernel

On Thursday, September 8, 2016 11:23:54 AM CEST Thierry Reding wrote:
> On Tue, Sep 06, 2016 at 02:50:47PM +0200, Arnd Bergmann wrote:
> > 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>
> > ---
> >  drivers/pwm/pwm-meson.c | 10 ++++++++++
> >  1 file changed, 10 insertions(+)
> 
> Applied, though I left out the dummy assignment of state->enabled = 0
> because that's dead code anyway.

Sounds good. My first version had "break" instead of "return" there,
so it required the assignment,  but you are in the current version you
are right that we are better off without it.

	Arnd

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

end of thread, other threads:[~2016-09-08  9:30 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-09-06 12:50 [PATCH] pwm: meson: handle unknown ID values Arnd Bergmann
2016-09-06 12:55 ` Neil Armstrong
2016-09-08  9:23 ` Thierry Reding
2016-09-08  9:29   ` Arnd Bergmann

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