include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit...
[safe/jmp/linux-2.6] / drivers / acpi / utils.c
index eba55b7..b002a47 100644 (file)
 
 #include <linux/kernel.h>
 #include <linux/module.h>
+#include <linux/slab.h>
 #include <linux/init.h>
 #include <linux/types.h>
 #include <acpi/acpi_bus.h>
 #include <acpi/acpi_drivers.h>
 
+#include "internal.h"
+
 #define _COMPONENT             ACPI_BUS_COMPONENT
 ACPI_MODULE_NAME("utils");
 
@@ -105,12 +108,12 @@ acpi_extract_package(union acpi_object *package,
                case ACPI_TYPE_INTEGER:
                        switch (format_string[i]) {
                        case 'N':
-                               size_required += sizeof(acpi_integer);
-                               tail_offset += sizeof(acpi_integer);
+                               size_required += sizeof(u64);
+                               tail_offset += sizeof(u64);
                                break;
                        case 'S':
                                size_required +=
-                                   sizeof(char *) + sizeof(acpi_integer) +
+                                   sizeof(char *) + sizeof(u64) +
                                    sizeof(char);
                                tail_offset += sizeof(char *);
                                break;
@@ -191,17 +194,17 @@ acpi_extract_package(union acpi_object *package,
                case ACPI_TYPE_INTEGER:
                        switch (format_string[i]) {
                        case 'N':
-                               *((acpi_integer *) head) =
+                               *((u64 *) head) =
                                    element->integer.value;
-                               head += sizeof(acpi_integer);
+                               head += sizeof(u64);
                                break;
                        case 'S':
                                pointer = (u8 **) head;
                                *pointer = tail;
-                               *((acpi_integer *) tail) =
+                               *((u64 *) tail) =
                                    element->integer.value;
-                               head += sizeof(acpi_integer *);
-                               tail += sizeof(acpi_integer);
+                               head += sizeof(u64 *);
+                               tail += sizeof(u64);
                                /* NULL terminate string */
                                *tail = (char)0;
                                tail += sizeof(char);
@@ -256,90 +259,37 @@ EXPORT_SYMBOL(acpi_extract_package);
 acpi_status
 acpi_evaluate_integer(acpi_handle handle,
                      acpi_string pathname,
-                     struct acpi_object_list *arguments, unsigned long *data)
+                     struct acpi_object_list *arguments, unsigned long long *data)
 {
        acpi_status status = AE_OK;
-       union acpi_object *element;
+       union acpi_object element;
        struct acpi_buffer buffer = { 0, NULL };
 
-
        if (!data)
                return AE_BAD_PARAMETER;
 
-       element = kzalloc(sizeof(union acpi_object), irqs_disabled() ? GFP_ATOMIC: GFP_KERNEL);
-       if (!element)
-               return AE_NO_MEMORY;
-
        buffer.length = sizeof(union acpi_object);
-       buffer.pointer = element;
+       buffer.pointer = &element;
        status = acpi_evaluate_object(handle, pathname, arguments, &buffer);
        if (ACPI_FAILURE(status)) {
                acpi_util_eval_error(handle, pathname, status);
-               kfree(element);
                return status;
        }
 
-       if (element->type != ACPI_TYPE_INTEGER) {
+       if (element.type != ACPI_TYPE_INTEGER) {
                acpi_util_eval_error(handle, pathname, AE_BAD_DATA);
-               kfree(element);
                return AE_BAD_DATA;
        }
 
-       *data = element->integer.value;
-       kfree(element);
+       *data = element.integer.value;
 
-       ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Return value [%lu]\n", *data));
+       ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Return value [%llu]\n", *data));
 
        return AE_OK;
 }
 
 EXPORT_SYMBOL(acpi_evaluate_integer);
 
-#if 0
-acpi_status
-acpi_evaluate_string(acpi_handle handle,
-                    acpi_string pathname,
-                    acpi_object_list * arguments, acpi_string * data)
-{
-       acpi_status status = AE_OK;
-       acpi_object *element = NULL;
-       acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
-
-
-       if (!data)
-               return AE_BAD_PARAMETER;
-
-       status = acpi_evaluate_object(handle, pathname, arguments, &buffer);
-       if (ACPI_FAILURE(status)) {
-               acpi_util_eval_error(handle, pathname, status);
-               return status;
-       }
-
-       element = (acpi_object *) buffer.pointer;
-
-       if ((element->type != ACPI_TYPE_STRING)
-           || (element->type != ACPI_TYPE_BUFFER)
-           || !element->string.length) {
-               acpi_util_eval_error(handle, pathname, AE_BAD_DATA);
-               return AE_BAD_DATA;
-       }
-
-       *data = kzalloc(element->string.length + 1, GFP_KERNEL);
-       if (!data) {
-               printk(KERN_ERR PREFIX "Memory allocation\n");
-               return -ENOMEM;
-       }
-
-       memcpy(*data, element->string.pointer, element->string.length);
-
-       ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Return value [%s]\n", *data));
-
-       kfree(buffer.pointer);
-
-       return AE_OK;
-}
-#endif
-
 acpi_status
 acpi_evaluate_reference(acpi_handle handle,
                        acpi_string pathname,
@@ -398,7 +348,7 @@ acpi_evaluate_reference(acpi_handle handle,
 
                element = &(package->package.elements[i]);
 
-               if (element->type != ACPI_TYPE_ANY) {
+               if (element->type != ACPI_TYPE_LOCAL_REFERENCE) {
                        status = AE_BAD_DATA;
                        printk(KERN_ERR PREFIX
                                    "Expecting a [Reference] package element, found type %X\n",
@@ -407,6 +357,12 @@ acpi_evaluate_reference(acpi_handle handle,
                        break;
                }
 
+               if (!element->reference.handle) {
+                       printk(KERN_WARNING PREFIX "Invalid reference in"
+                              " package %s\n", pathname);
+                       status = AE_NULL_ENTRY;
+                       break;
+               }
                /* Get the  acpi_handle. */
 
                list->handles[i] = element->reference.handle;