public inbox for linux-acpi@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] acpi: watchdog: properly initialize resources
@ 2017-09-15 19:55 Arnd Bergmann
  2017-09-15 22:39 ` Guenter Roeck
  2017-09-16  6:56 ` Mika Westerberg
  0 siblings, 2 replies; 4+ messages in thread
From: Arnd Bergmann @ 2017-09-15 19:55 UTC (permalink / raw)
  To: Rafael J. Wysocki, Len Brown
  Cc: Arnd Bergmann, Mika Westerberg, Ryan Kennedy, Guenter Roeck,
	linux-acpi, linux-kernel

We copy a local resource structure into a list, but only
initialize some of its members, as pointed out by gcc-4.4:

drivers/acpi/acpi_watchdog.c: In function 'acpi_watchdog_init':
drivers/acpi/acpi_watchdog.c:105: error: 'res.child' may be used uninitialized in this function
drivers/acpi/acpi_watchdog.c:105: error: 'res.sibling' may be used uninitialized in this function
drivers/acpi/acpi_watchdog.c:105: error: 'res.parent' may be used uninitialized in this function
drivers/acpi/acpi_watchdog.c:105: error: 'res.desc' may be used uninitialized in this function
drivers/acpi/acpi_watchdog.c:105: error: 'res.name' may be used uninitialized in this function

Newer compilers can presumably optimize the uninitialized access
away entirely and don't warn at all, but rely on the kzalloc()
to zero the structure first. This adds an explicit initialization
to force consistent behavior.

Fixes: 058dfc767008 ("ACPI / watchdog: Add support for WDAT hardware watchdog")
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
 drivers/acpi/acpi_watchdog.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/acpi/acpi_watchdog.c b/drivers/acpi/acpi_watchdog.c
index bf22c29d2517..11b113f8e367 100644
--- a/drivers/acpi/acpi_watchdog.c
+++ b/drivers/acpi/acpi_watchdog.c
@@ -66,7 +66,7 @@ void __init acpi_watchdog_init(void)
 	for (i = 0; i < wdat->entries; i++) {
 		const struct acpi_generic_address *gas;
 		struct resource_entry *rentry;
-		struct resource res;
+		struct resource res = {};
 		bool found;
 
 		gas = &entries[i].register_region;
-- 
2.9.0


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

* Re: [PATCH] acpi: watchdog: properly initialize resources
  2017-09-15 19:55 [PATCH] acpi: watchdog: properly initialize resources Arnd Bergmann
@ 2017-09-15 22:39 ` Guenter Roeck
  2017-09-16  6:56 ` Mika Westerberg
  1 sibling, 0 replies; 4+ messages in thread
From: Guenter Roeck @ 2017-09-15 22:39 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: Rafael J. Wysocki, Len Brown, Mika Westerberg, Ryan Kennedy,
	linux-acpi, linux-kernel

On Fri, Sep 15, 2017 at 09:55:18PM +0200, Arnd Bergmann wrote:
> We copy a local resource structure into a list, but only
> initialize some of its members, as pointed out by gcc-4.4:
> 
> drivers/acpi/acpi_watchdog.c: In function 'acpi_watchdog_init':
> drivers/acpi/acpi_watchdog.c:105: error: 'res.child' may be used uninitialized in this function
> drivers/acpi/acpi_watchdog.c:105: error: 'res.sibling' may be used uninitialized in this function
> drivers/acpi/acpi_watchdog.c:105: error: 'res.parent' may be used uninitialized in this function
> drivers/acpi/acpi_watchdog.c:105: error: 'res.desc' may be used uninitialized in this function
> drivers/acpi/acpi_watchdog.c:105: error: 'res.name' may be used uninitialized in this function
> 
> Newer compilers can presumably optimize the uninitialized access
> away entirely and don't warn at all, but rely on the kzalloc()
> to zero the structure first. This adds an explicit initialization
> to force consistent behavior.
> 
> Fixes: 058dfc767008 ("ACPI / watchdog: Add support for WDAT hardware watchdog")
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>

Acked-by: Guenter Roeck <linux@roeck-us.net>

> ---
>  drivers/acpi/acpi_watchdog.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/acpi/acpi_watchdog.c b/drivers/acpi/acpi_watchdog.c
> index bf22c29d2517..11b113f8e367 100644
> --- a/drivers/acpi/acpi_watchdog.c
> +++ b/drivers/acpi/acpi_watchdog.c
> @@ -66,7 +66,7 @@ void __init acpi_watchdog_init(void)
>  	for (i = 0; i < wdat->entries; i++) {
>  		const struct acpi_generic_address *gas;
>  		struct resource_entry *rentry;
> -		struct resource res;
> +		struct resource res = {};
>  		bool found;
>  
>  		gas = &entries[i].register_region;
> -- 
> 2.9.0
> 

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

* Re: [PATCH] acpi: watchdog: properly initialize resources
  2017-09-15 19:55 [PATCH] acpi: watchdog: properly initialize resources Arnd Bergmann
  2017-09-15 22:39 ` Guenter Roeck
@ 2017-09-16  6:56 ` Mika Westerberg
  2017-09-18 23:41   ` Rafael J. Wysocki
  1 sibling, 1 reply; 4+ messages in thread
From: Mika Westerberg @ 2017-09-16  6:56 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: Rafael J. Wysocki, Len Brown, Ryan Kennedy, Guenter Roeck,
	linux-acpi, linux-kernel

On Fri, Sep 15, 2017 at 09:55:18PM +0200, Arnd Bergmann wrote:
> We copy a local resource structure into a list, but only
> initialize some of its members, as pointed out by gcc-4.4:
> 
> drivers/acpi/acpi_watchdog.c: In function 'acpi_watchdog_init':
> drivers/acpi/acpi_watchdog.c:105: error: 'res.child' may be used uninitialized in this function
> drivers/acpi/acpi_watchdog.c:105: error: 'res.sibling' may be used uninitialized in this function
> drivers/acpi/acpi_watchdog.c:105: error: 'res.parent' may be used uninitialized in this function
> drivers/acpi/acpi_watchdog.c:105: error: 'res.desc' may be used uninitialized in this function
> drivers/acpi/acpi_watchdog.c:105: error: 'res.name' may be used uninitialized in this function
> 
> Newer compilers can presumably optimize the uninitialized access
> away entirely and don't warn at all, but rely on the kzalloc()
> to zero the structure first. This adds an explicit initialization
> to force consistent behavior.
> 
> Fixes: 058dfc767008 ("ACPI / watchdog: Add support for WDAT hardware watchdog")
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>

Acked-by: Mika Westerberg <mika.westerberg@linux.intel.com>

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

* Re: [PATCH] acpi: watchdog: properly initialize resources
  2017-09-16  6:56 ` Mika Westerberg
@ 2017-09-18 23:41   ` Rafael J. Wysocki
  0 siblings, 0 replies; 4+ messages in thread
From: Rafael J. Wysocki @ 2017-09-18 23:41 UTC (permalink / raw)
  To: Mika Westerberg, Arnd Bergmann
  Cc: Len Brown, Ryan Kennedy, Guenter Roeck, linux-acpi, linux-kernel

On Saturday, September 16, 2017 8:56:49 AM CEST Mika Westerberg wrote:
> On Fri, Sep 15, 2017 at 09:55:18PM +0200, Arnd Bergmann wrote:
> > We copy a local resource structure into a list, but only
> > initialize some of its members, as pointed out by gcc-4.4:
> > 
> > drivers/acpi/acpi_watchdog.c: In function 'acpi_watchdog_init':
> > drivers/acpi/acpi_watchdog.c:105: error: 'res.child' may be used uninitialized in this function
> > drivers/acpi/acpi_watchdog.c:105: error: 'res.sibling' may be used uninitialized in this function
> > drivers/acpi/acpi_watchdog.c:105: error: 'res.parent' may be used uninitialized in this function
> > drivers/acpi/acpi_watchdog.c:105: error: 'res.desc' may be used uninitialized in this function
> > drivers/acpi/acpi_watchdog.c:105: error: 'res.name' may be used uninitialized in this function
> > 
> > Newer compilers can presumably optimize the uninitialized access
> > away entirely and don't warn at all, but rely on the kzalloc()
> > to zero the structure first. This adds an explicit initialization
> > to force consistent behavior.
> > 
> > Fixes: 058dfc767008 ("ACPI / watchdog: Add support for WDAT hardware watchdog")
> > Signed-off-by: Arnd Bergmann <arnd@arndb.de>
> 
> Acked-by: Mika Westerberg <mika.westerberg@linux.intel.com>

Applied, thanks!


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

end of thread, other threads:[~2017-09-18 23:50 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-09-15 19:55 [PATCH] acpi: watchdog: properly initialize resources Arnd Bergmann
2017-09-15 22:39 ` Guenter Roeck
2017-09-16  6:56 ` Mika Westerberg
2017-09-18 23:41   ` Rafael J. Wysocki

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox