Gitweb:     
http://git.kernel.org/git/?p=linux/kernel/git/torvalds/linux-2.6.git;a=commit;h=106449e870b3069c049a3486ae7b47995351270c
Commit:     106449e870b3069c049a3486ae7b47995351270c
Parent:     0bde7eee9489cc7cce08cf6eba05b4f42a6b2334
Author:     Alexey Starikovskiy <[EMAIL PROTECTED]>
AuthorDate: Mon Oct 29 23:29:40 2007 +0300
Committer:  Len Brown <[EMAIL PROTECTED]>
CommitDate: Mon Oct 29 16:52:01 2007 -0400

    ACPI: Battery: Allow extract string from integer
    
    Some machines return integer instead of expected string.
    
    Signed-off-by: Alexey Starikovskiy <[EMAIL PROTECTED]>
    Tested-by: Andrey Borzenkov <[EMAIL PROTECTED]>
    Tested-by: Frans Pop <[EMAIL PROTECTED]>
    Signed-off-by: Len Brown <[EMAIL PROTECTED]>
---
 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 74caa07..c2ce0ad 100644
--- a/drivers/acpi/battery.c
+++ b/drivers/acpi/battery.c
@@ -262,7 +262,7 @@ static int extract_package(struct acpi_battery *battery,
                           union acpi_object *package,
                           struct acpi_offsets *offsets, int num)
 {
-       int i, *x;
+       int i;
        union acpi_object *element;
        if (package->type != ACPI_TYPE_PACKAGE)
                return -EFAULT;
@@ -271,16 +271,21 @@ static int extract_package(struct acpi_battery *battery,
                        return -EFAULT;
                element = &package->package.elements[i];
                if (offsets[i].mode) {
-                       if (element->type != ACPI_TYPE_STRING &&
-                           element->type != ACPI_TYPE_BUFFER)
-                               return -EFAULT;
-                       strncpy((u8 *)battery + offsets[i].offset,
-                               element->string.pointer, 32);
+                       u8 *ptr = (u8 *)battery + offsets[i].offset;
+                       if (element->type == ACPI_TYPE_STRING ||
+                           element->type == ACPI_TYPE_BUFFER)
+                               strncpy(ptr, 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 {
-                       if (element->type != ACPI_TYPE_INTEGER)
-                               return -EFAULT;
-                       x = (int *)((u8 *)battery + offsets[i].offset);
-                       *x = element->integer.value;
+                       if (element->type == ACPI_TYPE_INTEGER) {
+                               int *x = (int *)((u8 *)battery +
+                                               offsets[i].offset);
+                               *x = element->integer.value;
+                       } else return -EFAULT;
                }
        }
        return 0;
-
To unsubscribe from this list: send the line "unsubscribe git-commits-head" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to