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>
46 #include <acpi/accommon.h>
47 #include <acpi/acnamesp.h>
48 #include <acpi/acpredef.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(char *pathname
,
76 union acpi_operand_object
**return_object_ptr
,
77 const union acpi_predefined_info
*predefined
);
80 acpi_ns_check_package_elements(char *pathname
,
81 union acpi_operand_object
**elements
,
82 u8 type1
, u32 count1
, u8 type2
, u32 count2
);
85 acpi_ns_check_object_type(char *pathname
,
86 union acpi_operand_object
**return_object_ptr
,
87 u32 expected_btypes
, u32 package_index
);
90 acpi_ns_check_reference(char *pathname
,
91 union acpi_operand_object
*return_object
);
94 acpi_ns_repair_object(u32 expected_btypes
,
96 union acpi_operand_object
**return_object_ptr
);
99 * Names for the types that can be returned by the predefined objects.
100 * Used for warning messages. Must be in the same order as the ACPI_RTYPEs
102 static const char *acpi_rtype_names
[] = {
110 #define ACPI_NOT_PACKAGE ACPI_UINT32_MAX
112 /*******************************************************************************
114 * FUNCTION: acpi_ns_check_predefined_names
116 * PARAMETERS: Node - Namespace node for the method/object
117 * return_object_ptr - Pointer to the object returned from the
118 * evaluation of a method or object
122 * DESCRIPTION: Check an ACPI name for a match in the predefined name list.
124 ******************************************************************************/
127 acpi_ns_check_predefined_names(struct acpi_namespace_node
*node
,
128 u32 user_param_count
,
129 acpi_status return_status
,
130 union acpi_operand_object
**return_object_ptr
)
132 union acpi_operand_object
*return_object
= *return_object_ptr
;
133 acpi_status status
= AE_OK
;
134 const union acpi_predefined_info
*predefined
;
137 /* Match the name for this method/object against the predefined list */
139 predefined
= acpi_ns_check_for_predefined_name(node
);
141 /* Get the full pathname to the object, for use in error messages */
143 pathname
= acpi_ns_get_external_pathname(node
);
145 pathname
= ACPI_CAST_PTR(char, predefined
->info
.name
);
149 * Check that the parameter count for this method matches the ASL
150 * definition. For predefined names, ensure that both the caller and
151 * the method itself are in accordance with the ACPI specification.
153 acpi_ns_check_parameter_count(pathname
, node
, user_param_count
,
156 /* If not a predefined name, we cannot validate the return object */
162 /* If the method failed, we cannot validate the return object */
164 if ((return_status
!= AE_OK
) && (return_status
!= AE_CTRL_RETURN_VALUE
)) {
169 * Only validate the return value on the first successful evaluation of
170 * the method. This ensures that any warnings will only be emitted during
171 * the very first evaluation of the method/object.
173 if (node
->flags
& ANOBJ_EVALUATED
) {
177 /* Mark the node as having been successfully evaluated */
179 node
->flags
|= ANOBJ_EVALUATED
;
182 * If there is no return value, check if we require a return value for
183 * this predefined name. Either one return value is expected, or none,
184 * for both methods and other objects.
186 * Exit now if there is no return object. Warning if one was expected.
188 if (!return_object
) {
189 if ((predefined
->info
.expected_btypes
) &&
190 (!(predefined
->info
.expected_btypes
& ACPI_RTYPE_NONE
))) {
192 "%s: Missing expected return value",
195 status
= AE_AML_NO_RETURN_VALUE
;
201 * We have a return value, but if one wasn't expected, just exit, this is
204 * For example, if the "Implicit Return" feature is enabled, methods will
205 * always return a value
207 if (!predefined
->info
.expected_btypes
) {
212 * Check that the type of the return object is what is expected for
213 * this predefined name
215 status
= acpi_ns_check_object_type(pathname
, return_object_ptr
,
216 predefined
->info
.expected_btypes
,
218 if (ACPI_FAILURE(status
)) {
222 /* For returned Package objects, check the type of all sub-objects */
224 if (ACPI_GET_OBJECT_TYPE(return_object
) == ACPI_TYPE_PACKAGE
) {
226 acpi_ns_check_package(pathname
, return_object_ptr
,
231 if (pathname
!= predefined
->info
.name
) {
238 /*******************************************************************************
240 * FUNCTION: acpi_ns_check_parameter_count
242 * PARAMETERS: Pathname - Full pathname to the node (for error msgs)
243 * Node - Namespace node for the method/object
244 * user_param_count - Number of args passed in by the caller
245 * Predefined - Pointer to entry in predefined name table
249 * DESCRIPTION: Check that the declared (in ASL/AML) parameter count for a
250 * predefined name is what is expected (i.e., what is defined in
251 * the ACPI specification for this predefined name.)
253 ******************************************************************************/
256 acpi_ns_check_parameter_count(char *pathname
,
257 struct acpi_namespace_node
*node
,
258 u32 user_param_count
,
259 const union acpi_predefined_info
*predefined
)
262 u32 required_params_current
;
263 u32 required_params_old
;
265 /* Methods have 0-7 parameters. All other types have zero. */
268 if (node
->type
== ACPI_TYPE_METHOD
) {
269 param_count
= node
->object
->method
.param_count
;
272 /* Argument count check for non-predefined methods/objects */
276 * Warning if too few or too many arguments have been passed by the
277 * caller. An incorrect number of arguments may not cause the method
278 * to fail. However, the method will fail if there are too few
279 * arguments and the method attempts to use one of the missing ones.
281 if (user_param_count
< param_count
) {
282 ACPI_WARNING((AE_INFO
,
283 "%s: Insufficient arguments - needs %d, found %d",
284 pathname
, param_count
, user_param_count
));
285 } else if (user_param_count
> param_count
) {
286 ACPI_WARNING((AE_INFO
,
287 "%s: Excess arguments - needs %d, found %d",
288 pathname
, param_count
, user_param_count
));
293 /* Allow two different legal argument counts (_SCP, etc.) */
295 required_params_current
= predefined
->info
.param_count
& 0x0F;
296 required_params_old
= predefined
->info
.param_count
>> 4;
298 if (user_param_count
!= ACPI_UINT32_MAX
) {
300 /* Validate the user-supplied parameter count */
302 if ((user_param_count
!= required_params_current
) &&
303 (user_param_count
!= required_params_old
)) {
304 ACPI_WARNING((AE_INFO
,
305 "%s: Parameter count mismatch - caller passed %d, ACPI requires %d",
306 pathname
, user_param_count
,
307 required_params_current
));
312 * Only validate the argument count on the first successful evaluation of
313 * the method. This ensures that any warnings will only be emitted during
314 * the very first evaluation of the method/object.
316 if (node
->flags
& ANOBJ_EVALUATED
) {
321 * Check that the ASL-defined parameter count is what is expected for
322 * this predefined name.
324 if ((param_count
!= required_params_current
) &&
325 (param_count
!= required_params_old
)) {
326 ACPI_WARNING((AE_INFO
,
327 "%s: Parameter count mismatch - ASL declared %d, ACPI requires %d",
328 pathname
, param_count
, required_params_current
));
332 /*******************************************************************************
334 * FUNCTION: acpi_ns_check_for_predefined_name
336 * PARAMETERS: Node - Namespace node for the method/object
338 * RETURN: Pointer to entry in predefined table. NULL indicates not found.
340 * DESCRIPTION: Check an object name against the predefined object list.
342 ******************************************************************************/
344 const union acpi_predefined_info
*acpi_ns_check_for_predefined_name(struct
348 const union acpi_predefined_info
*this_name
;
350 /* Quick check for a predefined name, first character must be underscore */
352 if (node
->name
.ascii
[0] != '_') {
356 /* Search info table for a predefined method/object name */
358 this_name
= predefined_names
;
359 while (this_name
->info
.name
[0]) {
360 if (ACPI_COMPARE_NAME(node
->name
.ascii
, this_name
->info
.name
)) {
362 /* Return pointer to this table entry */
368 * Skip next entry in the table if this name returns a Package
369 * (next entry contains the package info)
371 if (this_name
->info
.expected_btypes
& ACPI_RTYPE_PACKAGE
) {
381 /*******************************************************************************
383 * FUNCTION: acpi_ns_check_package
385 * PARAMETERS: Pathname - Full pathname to the node (for error msgs)
386 * return_object_ptr - Pointer to the object returned from the
387 * evaluation of a method or object
388 * Predefined - Pointer to entry in predefined name table
392 * DESCRIPTION: Check a returned package object for the correct count and
393 * correct type of all sub-objects.
395 ******************************************************************************/
398 acpi_ns_check_package(char *pathname
,
399 union acpi_operand_object
**return_object_ptr
,
400 const union acpi_predefined_info
*predefined
)
402 union acpi_operand_object
*return_object
= *return_object_ptr
;
403 const union acpi_predefined_info
*package
;
404 union acpi_operand_object
*sub_package
;
405 union acpi_operand_object
**elements
;
406 union acpi_operand_object
**sub_elements
;
413 ACPI_FUNCTION_NAME(ns_check_package
);
415 /* The package info for this name is in the next table entry */
417 package
= predefined
+ 1;
419 ACPI_DEBUG_PRINT((ACPI_DB_NAMES
,
420 "%s Validating return Package of Type %X, Count %X\n",
421 pathname
, package
->ret_info
.type
,
422 return_object
->package
.count
));
424 /* Extract package count and elements array */
426 elements
= return_object
->package
.elements
;
427 count
= return_object
->package
.count
;
429 /* The package must have at least one element, else invalid */
432 ACPI_WARNING((AE_INFO
,
433 "%s: Return Package has no elements (empty)",
436 return (AE_AML_OPERAND_VALUE
);
440 * Decode the type of the expected package contents
442 * PTYPE1 packages contain no subpackages
443 * PTYPE2 packages contain sub-packages
445 switch (package
->ret_info
.type
) {
446 case ACPI_PTYPE1_FIXED
:
449 * The package count is fixed and there are no sub-packages
451 * If package is too small, exit.
452 * If package is larger than expected, issue warning but continue
455 package
->ret_info
.count1
+ package
->ret_info
.count2
;
456 if (count
< expected_count
) {
457 goto package_too_small
;
458 } else if (count
> expected_count
) {
459 ACPI_WARNING((AE_INFO
,
460 "%s: Return Package is larger than needed - "
461 "found %u, expected %u", pathname
, count
,
465 /* Validate all elements of the returned package */
467 status
= acpi_ns_check_package_elements(pathname
, elements
,
476 if (ACPI_FAILURE(status
)) {
481 case ACPI_PTYPE1_VAR
:
484 * The package count is variable, there are no sub-packages, and all
485 * elements must be of the same type
487 for (i
= 0; i
< count
; i
++) {
488 status
= acpi_ns_check_object_type(pathname
, elements
,
491 if (ACPI_FAILURE(status
)) {
498 case ACPI_PTYPE1_OPTION
:
501 * The package count is variable, there are no sub-packages. There are
502 * a fixed number of required elements, and a variable number of
505 * Check if package is at least as large as the minimum required
507 expected_count
= package
->ret_info3
.count
;
508 if (count
< expected_count
) {
509 goto package_too_small
;
512 /* Variable number of sub-objects */
514 for (i
= 0; i
< count
; i
++) {
515 if (i
< package
->ret_info3
.count
) {
517 /* These are the required package elements (0, 1, or 2) */
520 acpi_ns_check_object_type(pathname
,
526 if (ACPI_FAILURE(status
)) {
530 /* These are the optional package elements */
533 acpi_ns_check_object_type(pathname
,
539 if (ACPI_FAILURE(status
)) {
547 case ACPI_PTYPE2_PKG_COUNT
:
549 /* First element is the (Integer) count of sub-packages to follow */
551 status
= acpi_ns_check_object_type(pathname
, elements
,
552 ACPI_RTYPE_INTEGER
, 0);
553 if (ACPI_FAILURE(status
)) {
558 * Count cannot be larger than the parent package length, but allow it
559 * to be smaller. The >= accounts for the Integer above.
561 expected_count
= (u32
) (*elements
)->integer
.value
;
562 if (expected_count
>= count
) {
563 goto package_too_small
;
566 count
= expected_count
;
569 /* Now we can walk the sub-packages */
571 /*lint -fallthrough */
574 case ACPI_PTYPE2_FIXED
:
575 case ACPI_PTYPE2_MIN
:
576 case ACPI_PTYPE2_COUNT
:
579 * These types all return a single package that consists of a variable
580 * number of sub-packages
582 for (i
= 0; i
< count
; i
++) {
583 sub_package
= *elements
;
584 sub_elements
= sub_package
->package
.elements
;
586 /* Each sub-object must be of type Package */
589 acpi_ns_check_object_type(pathname
, &sub_package
,
590 ACPI_RTYPE_PACKAGE
, i
);
591 if (ACPI_FAILURE(status
)) {
595 /* Examine the different types of sub-packages */
597 switch (package
->ret_info
.type
) {
599 case ACPI_PTYPE2_PKG_COUNT
:
601 /* Each subpackage has a fixed number of elements */
604 package
->ret_info
.count1
+
605 package
->ret_info
.count2
;
606 if (sub_package
->package
.count
!=
608 count
= sub_package
->package
.count
;
609 goto package_too_small
;
613 acpi_ns_check_package_elements(pathname
,
627 if (ACPI_FAILURE(status
)) {
632 case ACPI_PTYPE2_FIXED
:
634 /* Each sub-package has a fixed length */
636 expected_count
= package
->ret_info2
.count
;
637 if (sub_package
->package
.count
< expected_count
) {
638 count
= sub_package
->package
.count
;
639 goto package_too_small
;
642 /* Check the type of each sub-package element */
644 for (j
= 0; j
< expected_count
; j
++) {
646 acpi_ns_check_object_type(pathname
,
648 package
->ret_info2
.object_type
[j
], j
);
649 if (ACPI_FAILURE(status
)) {
655 case ACPI_PTYPE2_MIN
:
657 /* Each sub-package has a variable but minimum length */
659 expected_count
= package
->ret_info
.count1
;
660 if (sub_package
->package
.count
< expected_count
) {
661 count
= sub_package
->package
.count
;
662 goto package_too_small
;
665 /* Check the type of each sub-package element */
668 acpi_ns_check_package_elements(pathname
,
676 if (ACPI_FAILURE(status
)) {
681 case ACPI_PTYPE2_COUNT
:
683 /* First element is the (Integer) count of elements to follow */
686 acpi_ns_check_object_type(pathname
,
690 if (ACPI_FAILURE(status
)) {
694 /* Make sure package is large enough for the Count */
697 (u32
) (*sub_elements
)->integer
.value
;
698 if (sub_package
->package
.count
< expected_count
) {
699 count
= sub_package
->package
.count
;
700 goto package_too_small
;
703 /* Check the type of each sub-package element */
706 acpi_ns_check_package_elements(pathname
,
714 if (ACPI_FAILURE(status
)) {
729 /* Should not get here if predefined info table is correct */
731 ACPI_WARNING((AE_INFO
,
732 "%s: Invalid internal return type in table entry: %X",
733 pathname
, package
->ret_info
.type
));
735 return (AE_AML_INTERNAL
);
742 /* Error exit for the case with an incorrect package count */
744 ACPI_WARNING((AE_INFO
, "%s: Return Package is too small - "
745 "found %u, expected %u", pathname
, count
,
748 return (AE_AML_OPERAND_VALUE
);
751 /*******************************************************************************
753 * FUNCTION: acpi_ns_check_package_elements
755 * PARAMETERS: Pathname - Full pathname to the node (for error msgs)
756 * Elements - Pointer to the package elements array
757 * Type1 - Object type for first group
758 * Count1 - Count for first group
759 * Type2 - Object type for second group
760 * Count2 - Count for second group
764 * DESCRIPTION: Check that all elements of a package are of the correct object
765 * type. Supports up to two groups of different object types.
767 ******************************************************************************/
770 acpi_ns_check_package_elements(char *pathname
,
771 union acpi_operand_object
**elements
,
772 u8 type1
, u32 count1
, u8 type2
, u32 count2
)
774 union acpi_operand_object
**this_element
= elements
;
779 * Up to two groups of package elements are supported by the data
780 * structure. All elements in each group must be of the same type.
781 * The second group can have a count of zero.
783 for (i
= 0; i
< count1
; i
++) {
784 status
= acpi_ns_check_object_type(pathname
, this_element
,
786 if (ACPI_FAILURE(status
)) {
792 for (i
= 0; i
< count2
; i
++) {
793 status
= acpi_ns_check_object_type(pathname
, this_element
,
794 type2
, (i
+ count1
));
795 if (ACPI_FAILURE(status
)) {
804 /*******************************************************************************
806 * FUNCTION: acpi_ns_check_object_type
808 * PARAMETERS: Pathname - Full pathname to the node (for error msgs)
809 * return_object_ptr - Pointer to the object returned from the
810 * evaluation of a method or object
811 * expected_btypes - Bitmap of expected return type(s)
812 * package_index - Index of object within parent package (if
813 * applicable - ACPI_NOT_PACKAGE otherwise)
817 * DESCRIPTION: Check the type of the return object against the expected object
818 * type(s). Use of Btype allows multiple expected object types.
820 ******************************************************************************/
823 acpi_ns_check_object_type(char *pathname
,
824 union acpi_operand_object
**return_object_ptr
,
825 u32 expected_btypes
, u32 package_index
)
827 union acpi_operand_object
*return_object
= *return_object_ptr
;
828 acpi_status status
= AE_OK
;
830 char type_buffer
[48]; /* Room for 5 types */
836 * If we get a NULL return_object here, it is a NULL package element,
837 * and this is always an error.
839 if (!return_object
) {
840 goto type_error_exit
;
843 /* A Namespace node should not get here, but make sure */
845 if (ACPI_GET_DESCRIPTOR_TYPE(return_object
) == ACPI_DESC_TYPE_NAMED
) {
846 ACPI_WARNING((AE_INFO
,
847 "%s: Invalid return type - Found a Namespace node [%4.4s] type %s",
848 pathname
, return_object
->node
.name
.ascii
,
849 acpi_ut_get_type_name(return_object
->node
.type
)));
850 return (AE_AML_OPERAND_TYPE
);
854 * Convert the object type (ACPI_TYPE_xxx) to a bitmapped object type.
855 * The bitmapped type allows multiple possible return types.
857 * Note, the cases below must handle all of the possible types returned
858 * from all of the predefined names (including elements of returned
861 switch (ACPI_GET_OBJECT_TYPE(return_object
)) {
862 case ACPI_TYPE_INTEGER
:
863 return_btype
= ACPI_RTYPE_INTEGER
;
866 case ACPI_TYPE_BUFFER
:
867 return_btype
= ACPI_RTYPE_BUFFER
;
870 case ACPI_TYPE_STRING
:
871 return_btype
= ACPI_RTYPE_STRING
;
874 case ACPI_TYPE_PACKAGE
:
875 return_btype
= ACPI_RTYPE_PACKAGE
;
878 case ACPI_TYPE_LOCAL_REFERENCE
:
879 return_btype
= ACPI_RTYPE_REFERENCE
;
883 /* Not one of the supported objects, must be incorrect */
885 goto type_error_exit
;
888 /* Is the object one of the expected types? */
890 if (!(return_btype
& expected_btypes
)) {
892 /* Type mismatch -- attempt repair of the returned object */
894 status
= acpi_ns_repair_object(expected_btypes
, package_index
,
896 if (ACPI_SUCCESS(status
)) {
899 goto type_error_exit
;
902 /* For reference objects, check that the reference type is correct */
904 if (ACPI_GET_OBJECT_TYPE(return_object
) == ACPI_TYPE_LOCAL_REFERENCE
) {
905 status
= acpi_ns_check_reference(pathname
, return_object
);
912 /* Create a string with all expected types for this predefined object */
916 this_rtype
= ACPI_RTYPE_INTEGER
;
918 for (i
= 0; i
< ACPI_NUM_RTYPES
; i
++) {
920 /* If one of the expected types, concatenate the name of this type */
922 if (expected_btypes
& this_rtype
) {
923 ACPI_STRCAT(type_buffer
, &acpi_rtype_names
[i
][j
]);
924 j
= 0; /* Use name separator from now on */
926 this_rtype
<<= 1; /* Next Rtype */
929 if (package_index
== ACPI_NOT_PACKAGE
) {
930 ACPI_WARNING((AE_INFO
,
931 "%s: Return type mismatch - found %s, expected %s",
933 acpi_ut_get_object_type_name(return_object
),
936 ACPI_WARNING((AE_INFO
,
937 "%s: Return Package type mismatch at index %u - "
938 "found %s, expected %s", pathname
, package_index
,
939 acpi_ut_get_object_type_name(return_object
),
943 return (AE_AML_OPERAND_TYPE
);
946 /*******************************************************************************
948 * FUNCTION: acpi_ns_check_reference
950 * PARAMETERS: Pathname - Full pathname to the node (for error msgs)
951 * return_object - Object returned from the evaluation of a
956 * DESCRIPTION: Check a returned reference object for the correct reference
957 * type. The only reference type that can be returned from a
958 * predefined method is a named reference. All others are invalid.
960 ******************************************************************************/
963 acpi_ns_check_reference(char *pathname
,
964 union acpi_operand_object
*return_object
)
968 * Check the reference object for the correct reference type (opcode).
969 * The only type of reference that can be converted to an union acpi_object is
970 * a reference to a named object (reference class: NAME)
972 if (return_object
->reference
.class == ACPI_REFCLASS_NAME
) {
976 ACPI_WARNING((AE_INFO
,
977 "%s: Return type mismatch - unexpected reference object type [%s] %2.2X",
978 pathname
, acpi_ut_get_reference_name(return_object
),
979 return_object
->reference
.class));
981 return (AE_AML_OPERAND_TYPE
);
984 /*******************************************************************************
986 * FUNCTION: acpi_ns_repair_object
988 * PARAMETERS: Pathname - Full pathname to the node (for error msgs)
989 * package_index - Used to determine if target is in a package
990 * return_object_ptr - Pointer to the object returned from the
991 * evaluation of a method or object
993 * RETURN: Status. AE_OK if repair was successful.
995 * DESCRIPTION: Attempt to repair/convert a return object of a type that was
998 ******************************************************************************/
1001 acpi_ns_repair_object(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 (ACPI_GET_OBJECT_TYPE(return_object
)) {
1010 case ACPI_TYPE_BUFFER
:
1012 if (!(expected_btypes
& ACPI_RTYPE_STRING
)) {
1013 return (AE_AML_OPERAND_TYPE
);
1017 * Have a Buffer, expected a String, convert. Use a to_string
1018 * conversion, no transform performed on the buffer data. The best
1019 * example of this is the _BIF method, where the string data from
1020 * the battery is often (incorrectly) returned as buffer object(s).
1023 while ((length
< return_object
->buffer
.length
) &&
1024 (return_object
->buffer
.pointer
[length
])) {
1028 /* Allocate a new string object */
1030 new_object
= acpi_ut_create_string_object(length
);
1032 return (AE_NO_MEMORY
);
1036 * Copy the raw buffer data with no transform. String is already NULL
1037 * terminated at Length+1.
1039 ACPI_MEMCPY(new_object
->string
.pointer
,
1040 return_object
->buffer
.pointer
, length
);
1042 /* Install the new return object */
1044 acpi_ut_remove_reference(return_object
);
1045 *return_object_ptr
= new_object
;
1048 * If the object is a package element, we need to:
1049 * 1. Decrement the reference count of the orignal object, it was
1050 * incremented when building the package
1051 * 2. Increment the reference count of the new object, it will be
1052 * decremented when releasing the package
1054 if (package_index
!= ACPI_NOT_PACKAGE
) {
1055 acpi_ut_remove_reference(return_object
);
1056 acpi_ut_add_reference(new_object
);
1064 return (AE_AML_OPERAND_TYPE
);