diff options
author | Alexey Starikovskiy <astarikovskiy@suse.de> | 2007-10-29 16:29:40 -0400 |
---|---|---|
committer | Len Brown <len.brown@intel.com> | 2007-10-29 16:52:01 -0400 |
commit | 106449e870b3069c049a3486ae7b47995351270c (patch) | |
tree | 9f4e9fb97aa958ecae40adff7fd542949cd27cb5 | |
parent | 0bde7eee9489cc7cce08cf6eba05b4f42a6b2334 (diff) |
ACPI: Battery: Allow extract string from integer
Some machines return integer instead of expected string.
Signed-off-by: Alexey Starikovskiy <astarikovskiy@suse.de>
Tested-by: Andrey Borzenkov <arvidjaar@mail.ru>
Tested-by: Frans Pop <elendil@planet.nl>
Signed-off-by: Len Brown <len.brown@intel.com>
-rw-r--r-- | drivers/acpi/battery.c | 25 |
1 files changed, 15 insertions, 10 deletions
diff --git a/drivers/acpi/battery.c b/drivers/acpi/battery.c index 74caa07ad351..c2ce0ad21693 100644 --- a/drivers/acpi/battery.c +++ b/drivers/acpi/battery.c | |||
@@ -262,7 +262,7 @@ static int extract_package(struct acpi_battery *battery, | |||
262 | union acpi_object *package, | 262 | union acpi_object *package, |
263 | struct acpi_offsets *offsets, int num) | 263 | struct acpi_offsets *offsets, int num) |
264 | { | 264 | { |
265 | int i, *x; | 265 | int i; |
266 | union acpi_object *element; | 266 | union acpi_object *element; |
267 | if (package->type != ACPI_TYPE_PACKAGE) | 267 | if (package->type != ACPI_TYPE_PACKAGE) |
268 | return -EFAULT; | 268 | return -EFAULT; |
@@ -271,16 +271,21 @@ static int extract_package(struct acpi_battery *battery, | |||
271 | return -EFAULT; | 271 | return -EFAULT; |
272 | element = &package->package.elements[i]; | 272 | element = &package->package.elements[i]; |
273 | if (offsets[i].mode) { | 273 | if (offsets[i].mode) { |
274 | if (element->type != ACPI_TYPE_STRING && | 274 | u8 *ptr = (u8 *)battery + offsets[i].offset; |
275 | element->type != ACPI_TYPE_BUFFER) | 275 | if (element->type == ACPI_TYPE_STRING || |
276 | return -EFAULT; | 276 | element->type == ACPI_TYPE_BUFFER) |
277 | strncpy((u8 *)battery + offsets[i].offset, | 277 | strncpy(ptr, element->string.pointer, 32); |
278 | element->string.pointer, 32); | 278 | else if (element->type == ACPI_TYPE_INTEGER) { |
279 | strncpy(ptr, (u8 *)&element->integer.value, | ||
280 | sizeof(acpi_integer)); | ||
281 | ptr[sizeof(acpi_integer)] = 0; | ||
282 | } else return -EFAULT; | ||
279 | } else { | 283 | } else { |
280 | if (element->type != ACPI_TYPE_INTEGER) | 284 | if (element->type == ACPI_TYPE_INTEGER) { |
281 | return -EFAULT; | 285 | int *x = (int *)((u8 *)battery + |
282 | x = (int *)((u8 *)battery + offsets[i].offset); | 286 | offsets[i].offset); |
283 | *x = element->integer.value; | 287 | *x = element->integer.value; |
288 | } else return -EFAULT; | ||
284 | } | 289 | } |
285 | } | 290 | } |
286 | return 0; | 291 | return 0; |