Skip to content

Commit fe8c470

Browse files
arndbrafaeljw
authored andcommitted
ACPI / power: Avoid maybe-uninitialized warning
gcc -O2 cannot always prove that the loop in acpi_power_get_inferred_state() is enterered at least once, so it assumes that cur_state might not get initialized: drivers/acpi/power.c: In function 'acpi_power_get_inferred_state': drivers/acpi/power.c:222:9: error: 'cur_state' may be used uninitialized in this function [-Werror=maybe-uninitialized] This sets the variable to zero at the start of the loop, to ensure that there is well-defined behavior even for an empty list. This gets rid of the warning. The warning first showed up when the -Os flag got removed in a bug fix patch in linux-4.11-rc5. I would suggest merging this addon patch on top of that bug fix to avoid introducing a new warning in the stable kernels. Fixes: 61b79e1 (ACPI: Fix incompatibility with mcount-based function graph tracing) Cc: All applicable <[email protected]> Signed-off-by: Arnd Bergmann <[email protected]> Signed-off-by: Rafael J. Wysocki <[email protected]>
1 parent 4f7d029 commit fe8c470

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

drivers/acpi/power.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ static int acpi_power_get_list_state(struct list_head *list, int *state)
200200
return -EINVAL;
201201

202202
/* The state of the list is 'on' IFF all resources are 'on'. */
203+
cur_state = 0;
203204
list_for_each_entry(entry, list, node) {
204205
struct acpi_power_resource *resource = entry->resource;
205206
acpi_handle handle = resource->device.handle;

0 commit comments

Comments
 (0)