Skip to contentSkip to conversation

acpi: avoid uninialized-variable warning

PATCH In review Arnd Bergmann 2 participants 2 messages Apr 28, 2020 ACPI

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 acpi: avoid uninialized-variable warning

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.

---
 drivers/acpi/property.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/acpi/property.c +3 -1
index e601c4511a8b..3aa71daeb0b4 100644
@@ -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. */
Signature · 1 line
2.26.0
#1 lore raw
Quoted 26 lines · Arnd Bergmann

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.

---
 drivers/acpi/property.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/acpi/property.c +0 -0
index e601c4511a8b..3aa71daeb0b4 100644

drivers/acpi/property.c static int acpi_data_get_property_array(const struct acpi_device_data *data, · line 590

Quoted 5 lines
drivers/acpi/property.c +1 -1
@@ -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;
}

Quoted 9 lines
drivers/acpi/property.c +2 -1
+               *obj = NULL;
                return ret;
+       }
 
        if (type != ACPI_TYPE_ANY) {
                /* Check that all elements are of correct type. */
--

2.26.0

Signature · 2 lines
With Best Regards,
Andy Shevchenko