Commit | Line | Data |
---|---|---|
b2deadd5 BM |
1 | /****************************************************************************** |
2 | * | |
3 | * Module Name: nsrepair - Repair for objects returned by predefined methods | |
4 | * | |
5 | *****************************************************************************/ | |
6 | ||
7 | /* | |
8 | * Copyright (C) 2000 - 2009, Intel Corp. | |
9 | * All rights reserved. | |
10 | * | |
11 | * Redistribution and use in source and binary forms, with or without | |
12 | * modification, are permitted provided that the following conditions | |
13 | * are met: | |
14 | * 1. Redistributions of source code must retain the above copyright | |
15 | * notice, this list of conditions, and the following disclaimer, | |
16 | * without modification. | |
17 | * 2. Redistributions in binary form must reproduce at minimum a disclaimer | |
18 | * substantially similar to the "NO WARRANTY" disclaimer below | |
19 | * ("Disclaimer") and any redistribution must be conditioned upon | |
20 | * including a substantially similar Disclaimer requirement for further | |
21 | * binary redistribution. | |
22 | * 3. Neither the names of the above-listed copyright holders nor the names | |
23 | * of any contributors may be used to endorse or promote products derived | |
24 | * from this software without specific prior written permission. | |
25 | * | |
26 | * Alternatively, this software may be distributed under the terms of the | |
27 | * GNU General Public License ("GPL") version 2 as published by the Free | |
28 | * Software Foundation. | |
29 | * | |
30 | * NO WARRANTY | |
31 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
32 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
33 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR | |
34 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
35 | * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
36 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
37 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
38 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | |
39 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING | |
40 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
41 | * POSSIBILITY OF SUCH DAMAGES. | |
42 | */ | |
43 | ||
44 | #include <acpi/acpi.h> | |
45 | #include "accommon.h" | |
46 | #include "acnamesp.h" | |
47 | #include "acpredef.h" | |
48 | ||
49 | #define _COMPONENT ACPI_NAMESPACE | |
50 | ACPI_MODULE_NAME("nsrepair") | |
51 | ||
52 | /******************************************************************************* | |
53 | * | |
54 | * FUNCTION: acpi_ns_repair_object | |
55 | * | |
56 | * PARAMETERS: Data - Pointer to validation data structure | |
57 | * expected_btypes - Object types expected | |
58 | * package_index - Index of object within parent package (if | |
59 | * applicable - ACPI_NOT_PACKAGE_ELEMENT | |
60 | * otherwise) | |
61 | * return_object_ptr - Pointer to the object returned from the | |
62 | * evaluation of a method or object | |
63 | * | |
64 | * RETURN: Status. AE_OK if repair was successful. | |
65 | * | |
66 | * DESCRIPTION: Attempt to repair/convert a return object of a type that was | |
67 | * not expected. | |
68 | * | |
69 | ******************************************************************************/ | |
70 | acpi_status | |
71 | acpi_ns_repair_object(struct acpi_predefined_data *data, | |
72 | u32 expected_btypes, | |
73 | u32 package_index, | |
74 | union acpi_operand_object **return_object_ptr) | |
75 | { | |
76 | union acpi_operand_object *return_object = *return_object_ptr; | |
77 | union acpi_operand_object *new_object; | |
78 | acpi_size length; | |
79 | ||
80 | switch (return_object->common.type) { | |
81 | case ACPI_TYPE_BUFFER: | |
82 | ||
83 | /* Does the method/object legally return a string? */ | |
84 | ||
85 | if (!(expected_btypes & ACPI_RTYPE_STRING)) { | |
86 | return (AE_AML_OPERAND_TYPE); | |
87 | } | |
88 | ||
89 | /* | |
90 | * Have a Buffer, expected a String, convert. Use a to_string | |
91 | * conversion, no transform performed on the buffer data. The best | |
92 | * example of this is the _BIF method, where the string data from | |
93 | * the battery is often (incorrectly) returned as buffer object(s). | |
94 | */ | |
95 | length = 0; | |
96 | while ((length < return_object->buffer.length) && | |
97 | (return_object->buffer.pointer[length])) { | |
98 | length++; | |
99 | } | |
100 | ||
101 | /* Allocate a new string object */ | |
102 | ||
103 | new_object = acpi_ut_create_string_object(length); | |
104 | if (!new_object) { | |
105 | return (AE_NO_MEMORY); | |
106 | } | |
107 | ||
108 | /* | |
109 | * Copy the raw buffer data with no transform. String is already NULL | |
110 | * terminated at Length+1. | |
111 | */ | |
112 | ACPI_MEMCPY(new_object->string.pointer, | |
113 | return_object->buffer.pointer, length); | |
114 | ||
115 | /* | |
116 | * If the original object is a package element, we need to: | |
117 | * 1. Set the reference count of the new object to match the | |
118 | * reference count of the old object. | |
119 | * 2. Decrement the reference count of the original object. | |
120 | */ | |
121 | if (package_index != ACPI_NOT_PACKAGE_ELEMENT) { | |
122 | new_object->common.reference_count = | |
123 | return_object->common.reference_count; | |
124 | ||
125 | if (return_object->common.reference_count > 1) { | |
126 | return_object->common.reference_count--; | |
127 | } | |
128 | ||
129 | ACPI_WARN_PREDEFINED((AE_INFO, data->pathname, | |
130 | data->node_flags, | |
131 | "Converted Buffer to expected String at index %u", | |
132 | package_index)); | |
133 | } else { | |
134 | ACPI_WARN_PREDEFINED((AE_INFO, data->pathname, | |
135 | data->node_flags, | |
136 | "Converted Buffer to expected String")); | |
137 | } | |
138 | ||
139 | /* Delete old object, install the new return object */ | |
140 | ||
141 | acpi_ut_remove_reference(return_object); | |
142 | *return_object_ptr = new_object; | |
143 | data->flags |= ACPI_OBJECT_REPAIRED; | |
144 | return (AE_OK); | |
145 | ||
146 | default: | |
147 | break; | |
148 | } | |
149 | ||
150 | return (AE_AML_OPERAND_TYPE); | |
151 | } |