Skip to content

Commit

Permalink
ACPI: x86: s2idle: Fix a logic error parsing AMD constraints table
Browse files Browse the repository at this point in the history
[ Upstream commit 9cc8cd0 ]

The constraints table should be resetting the `list` object
after running through all of `info_obj` iterations.

This adjusts whitespace as well as less code will now be included
with each loop. This fixes a functional problem is fixed where a
badly formed package in the inner loop may have incorrect data.

Fixes: 146f1ed ("ACPI: PM: s2idle: Add AMD support to handle _DSM")
Signed-off-by: Mario Limonciello <mario.limonciello@amd.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
  • Loading branch information
superm1 authored and gregkh committed Sep 13, 2023
1 parent a99f32b commit 7c70932
Showing 1 changed file with 12 additions and 19 deletions.
31 changes: 12 additions & 19 deletions drivers/acpi/x86/s2idle.c
Expand Up @@ -128,12 +128,11 @@ static void lpi_device_get_constraints_amd(void)
struct lpi_constraints *list;
acpi_status status;

list = &lpi_constraints_table[lpi_constraints_table_size];

for (k = 0; k < info_obj->package.count; k++) {
union acpi_object *obj = &info_obj->package.elements[k];

list = &lpi_constraints_table[lpi_constraints_table_size];
list->min_dstate = -1;

switch (k) {
case 0:
dev_info.enabled = obj->integer.value;
Expand All @@ -148,27 +147,21 @@ static void lpi_device_get_constraints_amd(void)
dev_info.min_dstate = obj->integer.value;
break;
}
}

if (!dev_info.enabled || !dev_info.name ||
!dev_info.min_dstate)
continue;
if (!dev_info.enabled || !dev_info.name ||
!dev_info.min_dstate)
continue;

status = acpi_get_handle(NULL, dev_info.name,
&list->handle);
if (ACPI_FAILURE(status))
continue;
status = acpi_get_handle(NULL, dev_info.name, &list->handle);
if (ACPI_FAILURE(status))
continue;

acpi_handle_debug(lps0_device_handle,
"Name:%s\n", dev_info.name);
acpi_handle_debug(lps0_device_handle,
"Name:%s\n", dev_info.name);

list->min_dstate = dev_info.min_dstate;
list->min_dstate = dev_info.min_dstate;

if (list->min_dstate < 0) {
acpi_handle_debug(lps0_device_handle,
"Incomplete constraint defined\n");
continue;
}
}
lpi_constraints_table_size++;
}
}
Expand Down

0 comments on commit 7c70932

Please sign in to comment.