diff options
-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; |