linux-acpi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] acpi: avoid uninialized-variable warning
@ 2020-04-28 21:55 Arnd Bergmann
  2020-04-28 22:08 ` Andy Shevchenko
  0 siblings, 1 reply; 2+ messages in thread
From: Arnd Bergmann @ 2020-04-28 21:55 UTC (permalink / raw)
  To: Rafael J. Wysocki, Len Brown
  Cc: Arnd Bergmann, Andy Shevchenko, Rob Herring, Sakari Ailus,
	Pierre-Louis Bossart, Mika Westerberg, Thomas Gleixner,
	Heikki Krogerus, Geert Uytterhoeven, linux-acpi, linux-kernel

Older compilers like gcc-4.8 produce a bogus warning here

In file included from include/linux/compiler_types.h:68:0,
                 from <command-line>:0:
drivers/acpi/property.c: In function 'acpi_data_prop_read':
include/linux/compiler-gcc.h:75:45: error: 'obj' may be used uninitialized in this function [-Werror=maybe-uninitialized]
 #define __UNIQUE_ID(prefix) __PASTE(__PASTE(__UNIQUE_ID_, prefix), __COUNTER__)
                                             ^
drivers/acpi/property.c:934:27: note: 'obj' was declared here
  const union acpi_object *obj;
                           ^

Ensure the output is always initialized even when returning an error
to avoid the warning.

Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
 drivers/acpi/property.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/acpi/property.c b/drivers/acpi/property.c
index e601c4511a8b..3aa71daeb0b4 100644
--- a/drivers/acpi/property.c
+++ b/drivers/acpi/property.c
@@ -587,8 +587,10 @@ static int acpi_data_get_property_array(const struct acpi_device_data *data,
 	int ret, i;
 
 	ret = acpi_data_get_property(data, name, ACPI_TYPE_PACKAGE, &prop);
-	if (ret)
+	if (ret && obj) {
+		*obj = NULL;
 		return ret;
+	}
 
 	if (type != ACPI_TYPE_ANY) {
 		/* Check that all elements are of correct type. */
-- 
2.26.0


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

* Re: [PATCH] acpi: avoid uninialized-variable warning
  2020-04-28 21:55 [PATCH] acpi: avoid uninialized-variable warning Arnd Bergmann
@ 2020-04-28 22:08 ` Andy Shevchenko
  0 siblings, 0 replies; 2+ messages in thread
From: Andy Shevchenko @ 2020-04-28 22:08 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: Rafael J. Wysocki, Len Brown, Andy Shevchenko, Rob Herring,
	Sakari Ailus, Pierre-Louis Bossart, Mika Westerberg,
	Thomas Gleixner, Heikki Krogerus, Geert Uytterhoeven,
	ACPI Devel Maling List, Linux Kernel Mailing List

On Wed, Apr 29, 2020 at 1:03 AM Arnd Bergmann <arnd@arndb.de> wrote:
>
> Older compilers like gcc-4.8 produce a bogus warning here
>
> In file included from include/linux/compiler_types.h:68:0,
>                  from <command-line>:0:
> drivers/acpi/property.c: In function 'acpi_data_prop_read':
> include/linux/compiler-gcc.h:75:45: error: 'obj' may be used uninitialized in this function [-Werror=maybe-uninitialized]
>  #define __UNIQUE_ID(prefix) __PASTE(__PASTE(__UNIQUE_ID_, prefix), __COUNTER__)
>                                              ^
> drivers/acpi/property.c:934:27: note: 'obj' was declared here
>   const union acpi_object *obj;
>                            ^
>
> Ensure the output is always initialized even when returning an error
> to avoid the warning.
>
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
> ---
>  drivers/acpi/property.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/acpi/property.c b/drivers/acpi/property.c
> index e601c4511a8b..3aa71daeb0b4 100644
> --- a/drivers/acpi/property.c
> +++ b/drivers/acpi/property.c
> @@ -587,8 +587,10 @@ static int acpi_data_get_property_array(const struct acpi_device_data *data,
>         int ret, i;
>
>         ret = acpi_data_get_property(data, name, ACPI_TYPE_PACKAGE, &prop);
> -       if (ret)
> +       if (ret && obj) {

It changes semantics and requires obj to be non-NULL.

Should be
if (ret) {
  if (obj)
    *obj = NULL;
  return ret;
}

> +               *obj = NULL;
>                 return ret;
> +       }
>
>         if (type != ACPI_TYPE_ANY) {
>                 /* Check that all elements are of correct type. */
> --
> 2.26.0
>


-- 
With Best Regards,
Andy Shevchenko

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

end of thread, other threads:[~2020-04-28 22:08 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-28 21:55 [PATCH] acpi: avoid uninialized-variable warning Arnd Bergmann
2020-04-28 22:08 ` Andy Shevchenko

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