提交 106449e8 编写于 作者: A Alexey Starikovskiy 提交者: Len Brown

ACPI: Battery: Allow extract string from integer

Some machines return integer instead of expected string.
Signed-off-by: NAlexey Starikovskiy <astarikovskiy@suse.de>
Tested-by: NAndrey Borzenkov <arvidjaar@mail.ru>
Tested-by: NFrans Pop <elendil@planet.nl>
Signed-off-by: NLen Brown <len.brown@intel.com>
上级 0bde7eee
...@@ -262,7 +262,7 @@ static int extract_package(struct acpi_battery *battery, ...@@ -262,7 +262,7 @@ static int extract_package(struct acpi_battery *battery,
union acpi_object *package, union acpi_object *package,
struct acpi_offsets *offsets, int num) struct acpi_offsets *offsets, int num)
{ {
int i, *x; int i;
union acpi_object *element; union acpi_object *element;
if (package->type != ACPI_TYPE_PACKAGE) if (package->type != ACPI_TYPE_PACKAGE)
return -EFAULT; return -EFAULT;
...@@ -271,16 +271,21 @@ static int extract_package(struct acpi_battery *battery, ...@@ -271,16 +271,21 @@ static int extract_package(struct acpi_battery *battery,
return -EFAULT; return -EFAULT;
element = &package->package.elements[i]; element = &package->package.elements[i];
if (offsets[i].mode) { if (offsets[i].mode) {
if (element->type != ACPI_TYPE_STRING && u8 *ptr = (u8 *)battery + offsets[i].offset;
element->type != ACPI_TYPE_BUFFER) if (element->type == ACPI_TYPE_STRING ||
return -EFAULT; element->type == ACPI_TYPE_BUFFER)
strncpy((u8 *)battery + offsets[i].offset, strncpy(ptr, element->string.pointer, 32);
element->string.pointer, 32); else if (element->type == ACPI_TYPE_INTEGER) {
strncpy(ptr, (u8 *)&element->integer.value,
sizeof(acpi_integer));
ptr[sizeof(acpi_integer)] = 0;
} else return -EFAULT;
} else { } else {
if (element->type != ACPI_TYPE_INTEGER) if (element->type == ACPI_TYPE_INTEGER) {
return -EFAULT; int *x = (int *)((u8 *)battery +
x = (int *)((u8 *)battery + offsets[i].offset); offsets[i].offset);
*x = element->integer.value; *x = element->integer.value;
} else return -EFAULT;
} }
} }
return 0; return 0;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册