1 /******************************************************************************
3 * Module Name: nspredef - Validation of ACPI predefined methods and objects
6 *****************************************************************************/
9 * Copyright (C) 2000 - 2008, Intel Corp.
10 * All rights reserved.
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions, and the following disclaimer,
17 * without modification.
18 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
19 * substantially similar to the "NO WARRANTY" disclaimer below
20 * ("Disclaimer") and any redistribution must be conditioned upon
21 * including a substantially similar Disclaimer requirement for further
22 * binary redistribution.
23 * 3. Neither the names of the above-listed copyright holders nor the names
24 * of any contributors may be used to endorse or promote products derived
25 * from this software without specific prior written permission.
27 * Alternatively, this software may be distributed under the terms of the
28 * GNU General Public License ("GPL") version 2 as published by the Free
29 * Software Foundation.
32 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
33 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
34 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
35 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
36 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
37 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
38 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
39 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
40 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
41 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
42 * POSSIBILITY OF SUCH DAMAGES.
45 #include <acpi/acpi.h>
50 #define _COMPONENT ACPI_NAMESPACE
51 ACPI_MODULE_NAME("nspredef")
53 /*******************************************************************************
55 * This module validates predefined ACPI objects that appear in the namespace,
56 * at the time they are evaluated (via acpi_evaluate_object). The purpose of this
57 * validation is to detect problems with BIOS-exposed predefined ACPI objects
58 * before the results are returned to the ACPI-related drivers.
60 * There are several areas that are validated:
62 * 1) The number of input arguments as defined by the method/object in the
63 * ASL is validated against the ACPI specification.
64 * 2) The type of the return object (if any) is validated against the ACPI
66 * 3) For returned package objects, the count of package elements is
67 * validated, as well as the type of each package element. Nested
68 * packages are supported.
70 * For any problems found, a warning message is issued.
72 ******************************************************************************/
73 /* Local prototypes */
75 acpi_ns_check_package(struct acpi_predefined_data *data,
76 union acpi_operand_object **return_object_ptr);
79 acpi_ns_check_package_elements(struct acpi_predefined_data *data,
80 union acpi_operand_object **elements,
83 u8 type2, u32 count2, u32 start_index);
86 acpi_ns_check_object_type(struct acpi_predefined_data *data,
87 union acpi_operand_object **return_object_ptr,
88 u32 expected_btypes, u32 package_index);
91 acpi_ns_check_reference(struct acpi_predefined_data *data,
92 union acpi_operand_object *return_object);
95 acpi_ns_repair_object(struct acpi_predefined_data *data,
98 union acpi_operand_object **return_object_ptr);
100 static void acpi_ns_get_expected_types(char *buffer, u32 expected_btypes);
103 * Names for the types that can be returned by the predefined objects.
104 * Used for warning messages. Must be in the same order as the ACPI_RTYPEs
106 static const char *acpi_rtype_names[] = {
114 /* Object is not a package element */
116 #define ACPI_NOT_PACKAGE_ELEMENT ACPI_UINT32_MAX
118 /* Always emit warning message, not dependent on node flags */
120 #define ACPI_WARN_ALWAYS 0
122 /*******************************************************************************
124 * FUNCTION: acpi_ns_check_predefined_names
126 * PARAMETERS: Node - Namespace node for the method/object
127 * user_param_count - Number of parameters actually passed
128 * return_status - Status from the object evaluation
129 * return_object_ptr - Pointer to the object returned from the
130 * evaluation of a method or object
134 * DESCRIPTION: Check an ACPI name for a match in the predefined name list.
136 ******************************************************************************/
139 acpi_ns_check_predefined_names(struct acpi_namespace_node *node,
140 u32 user_param_count,
141 acpi_status return_status,
142 union acpi_operand_object **return_object_ptr)
144 union acpi_operand_object *return_object = *return_object_ptr;
145 acpi_status status = AE_OK;
146 const union acpi_predefined_info *predefined;
148 struct acpi_predefined_data *data;
150 /* Match the name for this method/object against the predefined list */
152 predefined = acpi_ns_check_for_predefined_name(node);
154 /* Get the full pathname to the object, for use in warning messages */
156 pathname = acpi_ns_get_external_pathname(node);
158 return AE_OK; /* Could not get pathname, ignore */
162 * Check that the parameter count for this method matches the ASL
163 * definition. For predefined names, ensure that both the caller and
164 * the method itself are in accordance with the ACPI specification.
166 acpi_ns_check_parameter_count(pathname, node, user_param_count,
169 /* If not a predefined name, we cannot validate the return object */
176 * If the method failed or did not actually return an object, we cannot
177 * validate the return object
179 if ((return_status != AE_OK) && (return_status != AE_CTRL_RETURN_VALUE)) {
184 * If there is no return value, check if we require a return value for
185 * this predefined name. Either one return value is expected, or none,
186 * for both methods and other objects.
188 * Exit now if there is no return object. Warning if one was expected.
190 if (!return_object) {
191 if ((predefined->info.expected_btypes) &&
192 (!(predefined->info.expected_btypes & ACPI_RTYPE_NONE))) {
193 ACPI_WARN_PREDEFINED((AE_INFO, pathname,
195 "Missing expected return value"));
197 status = AE_AML_NO_RETURN_VALUE;
203 * We have a return value, but if one wasn't expected, just exit, this is
204 * not a problem. For example, if the "Implicit Return" feature is
205 * enabled, methods will always return a value.
207 if (!predefined->info.expected_btypes) {
211 /* Create the parameter data block for object validation */
213 data = ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_predefined_data));
217 data->predefined = predefined;
218 data->node_flags = node->flags;
219 data->pathname = pathname;
222 * Check that the type of the return object is what is expected for
223 * this predefined name
225 status = acpi_ns_check_object_type(data, return_object_ptr,
226 predefined->info.expected_btypes,
227 ACPI_NOT_PACKAGE_ELEMENT);
228 if (ACPI_FAILURE(status)) {
229 goto check_validation_status;
232 /* For returned Package objects, check the type of all sub-objects */
234 if (return_object->common.type == ACPI_TYPE_PACKAGE) {
235 status = acpi_ns_check_package(data, return_object_ptr);
238 check_validation_status:
240 * If the object validation failed or if we successfully repaired one
241 * or more objects, mark the parent node to suppress further warning
242 * messages during the next evaluation of the same method/object.
244 if (ACPI_FAILURE(status) || (data->flags & ACPI_OBJECT_REPAIRED)) {
245 node->flags |= ANOBJ_EVALUATED;
254 /*******************************************************************************
256 * FUNCTION: acpi_ns_check_parameter_count
258 * PARAMETERS: Pathname - Full pathname to the node (for error msgs)
259 * Node - Namespace node for the method/object
260 * user_param_count - Number of args passed in by the caller
261 * Predefined - Pointer to entry in predefined name table
265 * DESCRIPTION: Check that the declared (in ASL/AML) parameter count for a
266 * predefined name is what is expected (i.e., what is defined in
267 * the ACPI specification for this predefined name.)
269 ******************************************************************************/
272 acpi_ns_check_parameter_count(char *pathname,
273 struct acpi_namespace_node *node,
274 u32 user_param_count,
275 const union acpi_predefined_info *predefined)
278 u32 required_params_current;
279 u32 required_params_old;
281 /* Methods have 0-7 parameters. All other types have zero. */
284 if (node->type == ACPI_TYPE_METHOD) {
285 param_count = node->object->method.param_count;
290 * Check the parameter count for non-predefined methods/objects.
292 * Warning if too few or too many arguments have been passed by the
293 * caller. An incorrect number of arguments may not cause the method
294 * to fail. However, the method will fail if there are too few
295 * arguments and the method attempts to use one of the missing ones.
297 if (user_param_count < param_count) {
298 ACPI_WARN_PREDEFINED((AE_INFO, pathname,
300 "Insufficient arguments - needs %u, found %u",
301 param_count, user_param_count));
302 } else if (user_param_count > param_count) {
303 ACPI_WARN_PREDEFINED((AE_INFO, pathname,
305 "Excess arguments - needs %u, found %u",
306 param_count, user_param_count));
312 * Validate the user-supplied parameter count.
313 * Allow two different legal argument counts (_SCP, etc.)
315 required_params_current = predefined->info.param_count & 0x0F;
316 required_params_old = predefined->info.param_count >> 4;
318 if (user_param_count != ACPI_UINT32_MAX) {
319 if ((user_param_count != required_params_current) &&
320 (user_param_count != required_params_old)) {
321 ACPI_WARN_PREDEFINED((AE_INFO, pathname,
323 "Parameter count mismatch - "
324 "caller passed %u, ACPI requires %u",
326 required_params_current));
331 * Check that the ASL-defined parameter count is what is expected for
332 * this predefined name (parameter count as defined by the ACPI
335 if ((param_count != required_params_current) &&
336 (param_count != required_params_old)) {
337 ACPI_WARN_PREDEFINED((AE_INFO, pathname, node->flags,
338 "Parameter count mismatch - ASL declared %u, ACPI requires %u",
339 param_count, required_params_current));
343 /*******************************************************************************
345 * FUNCTION: acpi_ns_check_for_predefined_name
347 * PARAMETERS: Node - Namespace node for the method/object
349 * RETURN: Pointer to entry in predefined table. NULL indicates not found.
351 * DESCRIPTION: Check an object name against the predefined object list.
353 ******************************************************************************/
355 const union acpi_predefined_info *acpi_ns_check_for_predefined_name(struct
359 const union acpi_predefined_info *this_name;
361 /* Quick check for a predefined name, first character must be underscore */
363 if (node->name.ascii[0] != '_') {
367 /* Search info table for a predefined method/object name */
369 this_name = predefined_names;
370 while (this_name->info.name[0]) {
371 if (ACPI_COMPARE_NAME(node->name.ascii, this_name->info.name)) {
376 * Skip next entry in the table if this name returns a Package
377 * (next entry contains the package info)
379 if (this_name->info.expected_btypes & ACPI_RTYPE_PACKAGE) {
386 return (NULL); /* Not found */
389 /*******************************************************************************
391 * FUNCTION: acpi_ns_check_package
393 * PARAMETERS: Data - Pointer to validation data structure
394 * return_object_ptr - Pointer to the object returned from the
395 * evaluation of a method or object
399 * DESCRIPTION: Check a returned package object for the correct count and
400 * correct type of all sub-objects.
402 ******************************************************************************/
405 acpi_ns_check_package(struct acpi_predefined_data *data,
406 union acpi_operand_object **return_object_ptr)
408 union acpi_operand_object *return_object = *return_object_ptr;
409 const union acpi_predefined_info *package;
410 union acpi_operand_object *sub_package;
411 union acpi_operand_object **elements;
412 union acpi_operand_object **sub_elements;
419 ACPI_FUNCTION_NAME(ns_check_package);
421 /* The package info for this name is in the next table entry */
423 package = data->predefined + 1;
425 ACPI_DEBUG_PRINT((ACPI_DB_NAMES,
426 "%s Validating return Package of Type %X, Count %X\n",
427 data->pathname, package->ret_info.type,
428 return_object->package.count));
430 /* Extract package count and elements array */
432 elements = return_object->package.elements;
433 count = return_object->package.count;
435 /* The package must have at least one element, else invalid */
438 ACPI_WARN_PREDEFINED((AE_INFO, data->pathname, data->node_flags,
439 "Return Package has no elements (empty)"));
441 return (AE_AML_OPERAND_VALUE);
445 * Decode the type of the expected package contents
447 * PTYPE1 packages contain no subpackages
448 * PTYPE2 packages contain sub-packages
450 switch (package->ret_info.type) {
451 case ACPI_PTYPE1_FIXED:
454 * The package count is fixed and there are no sub-packages
456 * If package is too small, exit.
457 * If package is larger than expected, issue warning but continue
460 package->ret_info.count1 + package->ret_info.count2;
461 if (count < expected_count) {
462 goto package_too_small;
463 } else if (count > expected_count) {
464 ACPI_WARN_PREDEFINED((AE_INFO, data->pathname,
466 "Return Package is larger than needed - "
467 "found %u, expected %u", count,
471 /* Validate all elements of the returned package */
473 status = acpi_ns_check_package_elements(data, elements,
482 if (ACPI_FAILURE(status)) {
487 case ACPI_PTYPE1_VAR:
490 * The package count is variable, there are no sub-packages, and all
491 * elements must be of the same type
493 for (i = 0; i < count; i++) {
494 status = acpi_ns_check_object_type(data, elements,
497 if (ACPI_FAILURE(status)) {
504 case ACPI_PTYPE1_OPTION:
507 * The package count is variable, there are no sub-packages. There are
508 * a fixed number of required elements, and a variable number of
511 * Check if package is at least as large as the minimum required
513 expected_count = package->ret_info3.count;
514 if (count < expected_count) {
515 goto package_too_small;
518 /* Variable number of sub-objects */
520 for (i = 0; i < count; i++) {
521 if (i < package->ret_info3.count) {
523 /* These are the required package elements (0, 1, or 2) */
526 acpi_ns_check_object_type(data, elements,
531 if (ACPI_FAILURE(status)) {
535 /* These are the optional package elements */
538 acpi_ns_check_object_type(data, elements,
543 if (ACPI_FAILURE(status)) {
551 case ACPI_PTYPE2_PKG_COUNT:
553 /* First element is the (Integer) count of sub-packages to follow */
555 status = acpi_ns_check_object_type(data, elements,
556 ACPI_RTYPE_INTEGER, 0);
557 if (ACPI_FAILURE(status)) {
562 * Count cannot be larger than the parent package length, but allow it
563 * to be smaller. The >= accounts for the Integer above.
565 expected_count = (u32) (*elements)->integer.value;
566 if (expected_count >= count) {
567 goto package_too_small;
570 count = expected_count;
573 /* Now we can walk the sub-packages */
575 /*lint -fallthrough */
578 case ACPI_PTYPE2_FIXED:
579 case ACPI_PTYPE2_MIN:
580 case ACPI_PTYPE2_COUNT:
583 * These types all return a single package that consists of a variable
584 * number of sub-packages
586 for (i = 0; i < count; i++) {
587 sub_package = *elements;
588 sub_elements = sub_package->package.elements;
590 /* Each sub-object must be of type Package */
592 status = acpi_ns_check_object_type(data, &sub_package,
595 if (ACPI_FAILURE(status)) {
599 /* Examine the different types of sub-packages */
601 switch (package->ret_info.type) {
603 case ACPI_PTYPE2_PKG_COUNT:
605 /* Each subpackage has a fixed number of elements */
608 package->ret_info.count1 +
609 package->ret_info.count2;
610 if (sub_package->package.count !=
612 count = sub_package->package.count;
613 goto package_too_small;
617 acpi_ns_check_package_elements(data,
631 if (ACPI_FAILURE(status)) {
636 case ACPI_PTYPE2_FIXED:
638 /* Each sub-package has a fixed length */
640 expected_count = package->ret_info2.count;
641 if (sub_package->package.count < expected_count) {
642 count = sub_package->package.count;
643 goto package_too_small;
646 /* Check the type of each sub-package element */
648 for (j = 0; j < expected_count; j++) {
650 acpi_ns_check_object_type(data,
652 package->ret_info2.object_type[j], j);
653 if (ACPI_FAILURE(status)) {
659 case ACPI_PTYPE2_MIN:
661 /* Each sub-package has a variable but minimum length */
663 expected_count = package->ret_info.count1;
664 if (sub_package->package.count < expected_count) {
665 count = sub_package->package.count;
666 goto package_too_small;
669 /* Check the type of each sub-package element */
672 acpi_ns_check_package_elements(data,
681 if (ACPI_FAILURE(status)) {
686 case ACPI_PTYPE2_COUNT:
688 /* First element is the (Integer) count of elements to follow */
691 acpi_ns_check_object_type(data,
695 if (ACPI_FAILURE(status)) {
699 /* Make sure package is large enough for the Count */
702 (u32) (*sub_elements)->integer.value;
703 if (sub_package->package.count < expected_count) {
704 count = sub_package->package.count;
705 goto package_too_small;
708 /* Check the type of each sub-package element */
711 acpi_ns_check_package_elements(data,
720 if (ACPI_FAILURE(status)) {
735 /* Should not get here if predefined info table is correct */
737 ACPI_WARN_PREDEFINED((AE_INFO, data->pathname, data->node_flags,
738 "Invalid internal return type in table entry: %X",
739 package->ret_info.type));
741 return (AE_AML_INTERNAL);
748 /* Error exit for the case with an incorrect package count */
750 ACPI_WARN_PREDEFINED((AE_INFO, data->pathname, data->node_flags,
751 "Return Package is too small - found %u, expected %u",
752 count, expected_count));
754 return (AE_AML_OPERAND_VALUE);
757 /*******************************************************************************
759 * FUNCTION: acpi_ns_check_package_elements
761 * PARAMETERS: Data - Pointer to validation data structure
762 * Elements - Pointer to the package elements array
763 * Type1 - Object type for first group
764 * Count1 - Count for first group
765 * Type2 - Object type for second group
766 * Count2 - Count for second group
767 * start_index - Start of the first group of elements
771 * DESCRIPTION: Check that all elements of a package are of the correct object
772 * type. Supports up to two groups of different object types.
774 ******************************************************************************/
777 acpi_ns_check_package_elements(struct acpi_predefined_data *data,
778 union acpi_operand_object **elements,
781 u8 type2, u32 count2, u32 start_index)
783 union acpi_operand_object **this_element = elements;
788 * Up to two groups of package elements are supported by the data
789 * structure. All elements in each group must be of the same type.
790 * The second group can have a count of zero.
792 for (i = 0; i < count1; i++) {
793 status = acpi_ns_check_object_type(data, this_element,
794 type1, i + start_index);
795 if (ACPI_FAILURE(status)) {
801 for (i = 0; i < count2; i++) {
802 status = acpi_ns_check_object_type(data, this_element,
804 (i + count1 + start_index));
805 if (ACPI_FAILURE(status)) {
814 /*******************************************************************************
816 * FUNCTION: acpi_ns_check_object_type
818 * PARAMETERS: Data - Pointer to validation data structure
819 * return_object_ptr - Pointer to the object returned from the
820 * evaluation of a method or object
821 * expected_btypes - Bitmap of expected return type(s)
822 * package_index - Index of object within parent package (if
823 * applicable - ACPI_NOT_PACKAGE_ELEMENT
828 * DESCRIPTION: Check the type of the return object against the expected object
829 * type(s). Use of Btype allows multiple expected object types.
831 ******************************************************************************/
834 acpi_ns_check_object_type(struct acpi_predefined_data *data,
835 union acpi_operand_object **return_object_ptr,
836 u32 expected_btypes, u32 package_index)
838 union acpi_operand_object *return_object = *return_object_ptr;
839 acpi_status status = AE_OK;
841 char type_buffer[48]; /* Room for 5 types */
844 * If we get a NULL return_object here, it is a NULL package element,
845 * and this is always an error.
847 if (!return_object) {
848 goto type_error_exit;
851 /* A Namespace node should not get here, but make sure */
853 if (ACPI_GET_DESCRIPTOR_TYPE(return_object) == ACPI_DESC_TYPE_NAMED) {
854 ACPI_WARN_PREDEFINED((AE_INFO, data->pathname, data->node_flags,
855 "Invalid return type - Found a Namespace node [%4.4s] type %s",
856 return_object->node.name.ascii,
857 acpi_ut_get_type_name(return_object->node.
859 return (AE_AML_OPERAND_TYPE);
863 * Convert the object type (ACPI_TYPE_xxx) to a bitmapped object type.
864 * The bitmapped type allows multiple possible return types.
866 * Note, the cases below must handle all of the possible types returned
867 * from all of the predefined names (including elements of returned
870 switch (return_object->common.type) {
871 case ACPI_TYPE_INTEGER:
872 return_btype = ACPI_RTYPE_INTEGER;
875 case ACPI_TYPE_BUFFER:
876 return_btype = ACPI_RTYPE_BUFFER;
879 case ACPI_TYPE_STRING:
880 return_btype = ACPI_RTYPE_STRING;
883 case ACPI_TYPE_PACKAGE:
884 return_btype = ACPI_RTYPE_PACKAGE;
887 case ACPI_TYPE_LOCAL_REFERENCE:
888 return_btype = ACPI_RTYPE_REFERENCE;
892 /* Not one of the supported objects, must be incorrect */
894 goto type_error_exit;
897 /* Is the object one of the expected types? */
899 if (!(return_btype & expected_btypes)) {
901 /* Type mismatch -- attempt repair of the returned object */
903 status = acpi_ns_repair_object(data, expected_btypes,
906 if (ACPI_SUCCESS(status)) {
907 return (AE_OK); /* Repair was successful */
909 goto type_error_exit;
912 /* For reference objects, check that the reference type is correct */
914 if (return_object->common.type == ACPI_TYPE_LOCAL_REFERENCE) {
915 status = acpi_ns_check_reference(data, return_object);
922 /* Create a string with all expected types for this predefined object */
924 acpi_ns_get_expected_types(type_buffer, expected_btypes);
926 if (package_index == ACPI_NOT_PACKAGE_ELEMENT) {
927 ACPI_WARN_PREDEFINED((AE_INFO, data->pathname, data->node_flags,
928 "Return type mismatch - found %s, expected %s",
929 acpi_ut_get_object_type_name
930 (return_object), type_buffer));
932 ACPI_WARN_PREDEFINED((AE_INFO, data->pathname, data->node_flags,
933 "Return Package type mismatch at index %u - "
934 "found %s, expected %s", package_index,
935 acpi_ut_get_object_type_name
936 (return_object), type_buffer));
939 return (AE_AML_OPERAND_TYPE);
942 /*******************************************************************************
944 * FUNCTION: acpi_ns_check_reference
946 * PARAMETERS: Data - Pointer to validation data structure
947 * return_object - Object returned from the evaluation of a
952 * DESCRIPTION: Check a returned reference object for the correct reference
953 * type. The only reference type that can be returned from a
954 * predefined method is a named reference. All others are invalid.
956 ******************************************************************************/
959 acpi_ns_check_reference(struct acpi_predefined_data *data,
960 union acpi_operand_object *return_object)
964 * Check the reference object for the correct reference type (opcode).
965 * The only type of reference that can be converted to an union acpi_object is
966 * a reference to a named object (reference class: NAME)
968 if (return_object->reference.class == ACPI_REFCLASS_NAME) {
972 ACPI_WARN_PREDEFINED((AE_INFO, data->pathname, data->node_flags,
973 "Return type mismatch - unexpected reference object type [%s] %2.2X",
974 acpi_ut_get_reference_name(return_object),
975 return_object->reference.class));
977 return (AE_AML_OPERAND_TYPE);
980 /*******************************************************************************
982 * FUNCTION: acpi_ns_repair_object
984 * PARAMETERS: Data - Pointer to validation data structure
985 * expected_btypes - Object types expected
986 * package_index - Index of object within parent package (if
987 * applicable - ACPI_NOT_PACKAGE_ELEMENT
989 * return_object_ptr - Pointer to the object returned from the
990 * evaluation of a method or object
992 * RETURN: Status. AE_OK if repair was successful.
994 * DESCRIPTION: Attempt to repair/convert a return object of a type that was
997 ******************************************************************************/
1000 acpi_ns_repair_object(struct acpi_predefined_data *data,
1001 u32 expected_btypes,
1003 union acpi_operand_object **return_object_ptr)
1005 union acpi_operand_object *return_object = *return_object_ptr;
1006 union acpi_operand_object *new_object;
1009 switch (return_object->common.type) {
1010 case ACPI_TYPE_BUFFER:
1012 /* Does the method/object legally return a string? */
1014 if (!(expected_btypes & ACPI_RTYPE_STRING)) {
1015 return (AE_AML_OPERAND_TYPE);
1019 * Have a Buffer, expected a String, convert. Use a to_string
1020 * conversion, no transform performed on the buffer data. The best
1021 * example of this is the _BIF method, where the string data from
1022 * the battery is often (incorrectly) returned as buffer object(s).
1025 while ((length < return_object->buffer.length) &&
1026 (return_object->buffer.pointer[length])) {
1030 /* Allocate a new string object */
1032 new_object = acpi_ut_create_string_object(length);
1034 return (AE_NO_MEMORY);
1038 * Copy the raw buffer data with no transform. String is already NULL
1039 * terminated at Length+1.
1041 ACPI_MEMCPY(new_object->string.pointer,
1042 return_object->buffer.pointer, length);
1045 * If the original object is a package element, we need to:
1046 * 1. Set the reference count of the new object to match the
1047 * reference count of the old object.
1048 * 2. Decrement the reference count of the original object.
1050 if (package_index != ACPI_NOT_PACKAGE_ELEMENT) {
1051 new_object->common.reference_count =
1052 return_object->common.reference_count;
1054 if (return_object->common.reference_count > 1) {
1055 return_object->common.reference_count--;
1058 ACPI_WARN_PREDEFINED((AE_INFO, data->pathname,
1060 "Converted Buffer to expected String at index %u",
1063 ACPI_WARN_PREDEFINED((AE_INFO, data->pathname,
1065 "Converted Buffer to expected String"));
1068 /* Delete old object, install the new return object */
1070 acpi_ut_remove_reference(return_object);
1071 *return_object_ptr = new_object;
1072 data->flags |= ACPI_OBJECT_REPAIRED;
1079 return (AE_AML_OPERAND_TYPE);
1082 /*******************************************************************************
1084 * FUNCTION: acpi_ns_get_expected_types
1086 * PARAMETERS: Buffer - Pointer to where the string is returned
1087 * expected_btypes - Bitmap of expected return type(s)
1089 * RETURN: Buffer is populated with type names.
1091 * DESCRIPTION: Translate the expected types bitmap into a string of ascii
1092 * names of expected types, for use in warning messages.
1094 ******************************************************************************/
1096 static void acpi_ns_get_expected_types(char *buffer, u32 expected_btypes)
1104 this_rtype = ACPI_RTYPE_INTEGER;
1106 for (i = 0; i < ACPI_NUM_RTYPES; i++) {
1108 /* If one of the expected types, concatenate the name of this type */
1110 if (expected_btypes & this_rtype) {
1111 ACPI_STRCAT(buffer, &acpi_rtype_names[i][j]);
1112 j = 0; /* Use name separator from now on */
1114 this_rtype <<= 1; /* Next Rtype */