ACPICA: Add const qualifier for appropriate string constants
[safe/jmp/linux-2.6] / drivers / acpi / utilities / utmisc.c
index 4b03051..f34be67 100644 (file)
@@ -5,7 +5,7 @@
  ******************************************************************************/
 
 /*
- * Copyright (C) 2000 - 2006, R. Byron Moore
+ * Copyright (C) 2000 - 2008, Intel Corp.
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -51,6 +51,74 @@ ACPI_MODULE_NAME("utmisc")
 
 /*******************************************************************************
  *
+ * FUNCTION:    acpi_ut_validate_exception
+ *
+ * PARAMETERS:  Status       - The acpi_status code to be formatted
+ *
+ * RETURN:      A string containing the exception text. NULL if exception is
+ *              not valid.
+ *
+ * DESCRIPTION: This function validates and translates an ACPI exception into
+ *              an ASCII string.
+ *
+ ******************************************************************************/
+const char *acpi_ut_validate_exception(acpi_status status)
+{
+       u32 sub_status;
+       const char *exception = NULL;
+
+       ACPI_FUNCTION_ENTRY();
+
+       /*
+        * Status is composed of two parts, a "type" and an actual code
+        */
+       sub_status = (status & ~AE_CODE_MASK);
+
+       switch (status & AE_CODE_MASK) {
+       case AE_CODE_ENVIRONMENTAL:
+
+               if (sub_status <= AE_CODE_ENV_MAX) {
+                       exception = acpi_gbl_exception_names_env[sub_status];
+               }
+               break;
+
+       case AE_CODE_PROGRAMMER:
+
+               if (sub_status <= AE_CODE_PGM_MAX) {
+                       exception = acpi_gbl_exception_names_pgm[sub_status];
+               }
+               break;
+
+       case AE_CODE_ACPI_TABLES:
+
+               if (sub_status <= AE_CODE_TBL_MAX) {
+                       exception = acpi_gbl_exception_names_tbl[sub_status];
+               }
+               break;
+
+       case AE_CODE_AML:
+
+               if (sub_status <= AE_CODE_AML_MAX) {
+                       exception = acpi_gbl_exception_names_aml[sub_status];
+               }
+               break;
+
+       case AE_CODE_CONTROL:
+
+               if (sub_status <= AE_CODE_CTRL_MAX) {
+                       exception = acpi_gbl_exception_names_ctrl[sub_status];
+               }
+               break;
+
+       default:
+               break;
+       }
+
+       return (ACPI_CAST_PTR(const char, exception));
+}
+
+/*******************************************************************************
+ *
  * FUNCTION:    acpi_ut_is_aml_table
  *
  * PARAMETERS:  Table               - An ACPI table
@@ -62,6 +130,7 @@ ACPI_MODULE_NAME("utmisc")
  *              data tables that do not contain AML code.
  *
  ******************************************************************************/
+
 u8 acpi_ut_is_aml_table(struct acpi_table_header *table)
 {
 
@@ -92,9 +161,9 @@ u8 acpi_ut_is_aml_table(struct acpi_table_header *table)
 
 acpi_status acpi_ut_allocate_owner_id(acpi_owner_id * owner_id)
 {
-       acpi_native_uint i;
-       acpi_native_uint j;
-       acpi_native_uint k;
+       u32 i;
+       u32 j;
+       u32 k;
        acpi_status status;
 
        ACPI_FUNCTION_TRACE(ut_allocate_owner_id);
@@ -200,7 +269,7 @@ void acpi_ut_release_owner_id(acpi_owner_id * owner_id_ptr)
 {
        acpi_owner_id owner_id = *owner_id_ptr;
        acpi_status status;
-       acpi_native_uint index;
+       u32 index;
        u32 bit;
 
        ACPI_FUNCTION_TRACE_U32(ut_release_owner_id, owner_id);
@@ -520,7 +589,7 @@ acpi_ut_display_init_pathname(u8 type,
  *
  ******************************************************************************/
 
-u8 acpi_ut_valid_acpi_char(char character, acpi_native_uint position)
+u8 acpi_ut_valid_acpi_char(char character, u32 position)
 {
 
        if (!((character >= 'A' && character <= 'Z') ||
@@ -555,7 +624,7 @@ u8 acpi_ut_valid_acpi_char(char character, acpi_native_uint position)
 
 u8 acpi_ut_valid_acpi_name(u32 name)
 {
-       acpi_native_uint i;
+       u32 i;
 
        ACPI_FUNCTION_ENTRY();
 
@@ -582,26 +651,25 @@ u8 acpi_ut_valid_acpi_name(u32 name)
  *
  ******************************************************************************/
 
-acpi_name acpi_ut_repair_name(acpi_name name)
+acpi_name acpi_ut_repair_name(char *name)
 {
-       char *name_ptr = ACPI_CAST_PTR(char, &name);
+       u32 i;
        char new_name[ACPI_NAME_SIZE];
-       acpi_native_uint i;
 
        for (i = 0; i < ACPI_NAME_SIZE; i++) {
-               new_name[i] = name_ptr[i];
+               new_name[i] = name[i];
 
                /*
                 * Replace a bad character with something printable, yet technically
                 * still invalid. This prevents any collisions with existing "good"
                 * names in the namespace.
                 */
-               if (!acpi_ut_valid_acpi_char(name_ptr[i], i)) {
+               if (!acpi_ut_valid_acpi_char(name[i], i)) {
                        new_name[i] = '*';
                }
        }
 
-       return (*ACPI_CAST_PTR(u32, new_name));
+       return (*(u32 *) new_name);
 }
 
 /*******************************************************************************
@@ -730,9 +798,8 @@ acpi_ut_strtoul64(char *string, u32 base, acpi_integer * ret_integer)
 
                valid_digits++;
 
-               if (sign_of0x
-                   && ((valid_digits > 16)
-                       || ((valid_digits > 8) && mode32))) {
+               if (sign_of0x && ((valid_digits > 16)
+                                 || ((valid_digits > 8) && mode32))) {
                        /*
                         * This is to_integer operation case.
                         * No any restrictions for string-to-integer conversion,
@@ -953,7 +1020,7 @@ acpi_ut_walk_package_tree(union acpi_operand_object * source_object,
  ******************************************************************************/
 
 void ACPI_INTERNAL_VAR_XFACE
-acpi_ut_error(char *module_name, u32 line_number, char *format, ...)
+acpi_ut_error(const char *module_name, u32 line_number, const char *format, ...)
 {
        va_list args;
 
@@ -962,11 +1029,12 @@ acpi_ut_error(char *module_name, u32 line_number, char *format, ...)
        va_start(args, format);
        acpi_os_vprintf(format, args);
        acpi_os_printf(" [%X]\n", ACPI_CA_VERSION);
+       va_end(args);
 }
 
 void ACPI_INTERNAL_VAR_XFACE
-acpi_ut_exception(char *module_name,
-                 u32 line_number, acpi_status status, char *format, ...)
+acpi_ut_exception(const char *module_name,
+                 u32 line_number, acpi_status status, const char *format, ...)
 {
        va_list args;
 
@@ -976,11 +1044,14 @@ acpi_ut_exception(char *module_name,
        va_start(args, format);
        acpi_os_vprintf(format, args);
        acpi_os_printf(" [%X]\n", ACPI_CA_VERSION);
+       va_end(args);
 }
+
 EXPORT_SYMBOL(acpi_ut_exception);
 
 void ACPI_INTERNAL_VAR_XFACE
-acpi_ut_warning(char *module_name, u32 line_number, char *format, ...)
+acpi_ut_warning(const char *module_name,
+               u32 line_number, const char *format, ...)
 {
        va_list args;
 
@@ -989,10 +1060,11 @@ acpi_ut_warning(char *module_name, u32 line_number, char *format, ...)
        va_start(args, format);
        acpi_os_vprintf(format, args);
        acpi_os_printf(" [%X]\n", ACPI_CA_VERSION);
+       va_end(args);
 }
 
 void ACPI_INTERNAL_VAR_XFACE
-acpi_ut_info(char *module_name, u32 line_number, char *format, ...)
+acpi_ut_info(const char *module_name, u32 line_number, const char *format, ...)
 {
        va_list args;
 
@@ -1005,4 +1077,5 @@ acpi_ut_info(char *module_name, u32 line_number, char *format, ...)
        va_start(args, format);
        acpi_os_vprintf(format, args);
        acpi_os_printf("\n");
+       va_end(args);
 }