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(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
,
84 u8 type2
, u32 count2
, u32 start_index
);
87 acpi_ns_check_object_type(char *pathname
,
88 union acpi_operand_object
**return_object_ptr
,
89 u32 expected_btypes
, u32 package_index
);
92 acpi_ns_check_reference(char *pathname
,
93 union acpi_operand_object
*return_object
);
96 acpi_ns_repair_object(u32 expected_btypes
,
98 union acpi_operand_object
**return_object_ptr
);
101 * Names for the types that can be returned by the predefined objects.
102 * Used for warning messages. Must be in the same order as the ACPI_RTYPEs
104 static const char *acpi_rtype_names
[] = {
112 #define ACPI_NOT_PACKAGE ACPI_UINT32_MAX
114 /*******************************************************************************
116 * FUNCTION: acpi_ns_check_predefined_names
118 * PARAMETERS: Node - Namespace node for the method/object
119 * return_object_ptr - Pointer to the object returned from the
120 * evaluation of a method or object
124 * DESCRIPTION: Check an ACPI name for a match in the predefined name list.
126 ******************************************************************************/
129 acpi_ns_check_predefined_names(struct acpi_namespace_node
*node
,
130 u32 user_param_count
,
131 acpi_status return_status
,
132 union acpi_operand_object
**return_object_ptr
)
134 union acpi_operand_object
*return_object
= *return_object_ptr
;
135 acpi_status status
= AE_OK
;
136 const union acpi_predefined_info
*predefined
;
139 /* Match the name for this method/object against the predefined list */
141 predefined
= acpi_ns_check_for_predefined_name(node
);
143 /* Get the full pathname to the object, for use in error messages */
145 pathname
= acpi_ns_get_external_pathname(node
);
147 pathname
= ACPI_CAST_PTR(char, predefined
->info
.name
);
151 * Check that the parameter count for this method matches the ASL
152 * definition. For predefined names, ensure that both the caller and
153 * the method itself are in accordance with the ACPI specification.
155 acpi_ns_check_parameter_count(pathname
, node
, user_param_count
,
158 /* If not a predefined name, we cannot validate the return object */
164 /* If the method failed, we cannot validate the return object */
166 if ((return_status
!= AE_OK
) && (return_status
!= AE_CTRL_RETURN_VALUE
)) {
171 * Only validate the return value on the first successful evaluation of
172 * the method. This ensures that any warnings will only be emitted during
173 * the very first evaluation of the method/object.
175 if (node
->flags
& ANOBJ_EVALUATED
) {
179 /* Mark the node as having been successfully evaluated */
181 node
->flags
|= ANOBJ_EVALUATED
;
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
))) {
194 "%s: 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
206 * For example, if the "Implicit Return" feature is enabled, methods will
207 * always return a value
209 if (!predefined
->info
.expected_btypes
) {
214 * Check that the type of the return object is what is expected for
215 * this predefined name
217 status
= acpi_ns_check_object_type(pathname
, return_object_ptr
,
218 predefined
->info
.expected_btypes
,
220 if (ACPI_FAILURE(status
)) {
224 /* For returned Package objects, check the type of all sub-objects */
226 if (return_object
->common
.type
== ACPI_TYPE_PACKAGE
) {
228 acpi_ns_check_package(pathname
, return_object_ptr
,
233 if (pathname
!= predefined
->info
.name
) {
240 /*******************************************************************************
242 * FUNCTION: acpi_ns_check_parameter_count
244 * PARAMETERS: Pathname - Full pathname to the node (for error msgs)
245 * Node - Namespace node for the method/object
246 * user_param_count - Number of args passed in by the caller
247 * Predefined - Pointer to entry in predefined name table
251 * DESCRIPTION: Check that the declared (in ASL/AML) parameter count for a
252 * predefined name is what is expected (i.e., what is defined in
253 * the ACPI specification for this predefined name.)
255 ******************************************************************************/
258 acpi_ns_check_parameter_count(char *pathname
,
259 struct acpi_namespace_node
*node
,
260 u32 user_param_count
,
261 const union acpi_predefined_info
*predefined
)
264 u32 required_params_current
;
265 u32 required_params_old
;
267 /* Methods have 0-7 parameters. All other types have zero. */
270 if (node
->type
== ACPI_TYPE_METHOD
) {
271 param_count
= node
->object
->method
.param_count
;
274 /* Argument count check for non-predefined methods/objects */
278 * Warning if too few or too many arguments have been passed by the
279 * caller. An incorrect number of arguments may not cause the method
280 * to fail. However, the method will fail if there are too few
281 * arguments and the method attempts to use one of the missing ones.
283 if (user_param_count
< param_count
) {
284 ACPI_WARNING((AE_INFO
,
285 "%s: Insufficient arguments - needs %d, found %d",
286 pathname
, param_count
, user_param_count
));
287 } else if (user_param_count
> param_count
) {
288 ACPI_WARNING((AE_INFO
,
289 "%s: Excess arguments - needs %d, found %d",
290 pathname
, param_count
, user_param_count
));
295 /* Allow two different legal argument counts (_SCP, etc.) */
297 required_params_current
= predefined
->info
.param_count
& 0x0F;
298 required_params_old
= predefined
->info
.param_count
>> 4;
300 if (user_param_count
!= ACPI_UINT32_MAX
) {
302 /* Validate the user-supplied parameter count */
304 if ((user_param_count
!= required_params_current
) &&
305 (user_param_count
!= required_params_old
)) {
306 ACPI_WARNING((AE_INFO
,
307 "%s: Parameter count mismatch - "
308 "caller passed %d, ACPI requires %d",
309 pathname
, user_param_count
,
310 required_params_current
));
315 * Only validate the argument count on the first successful evaluation of
316 * the method. This ensures that any warnings will only be emitted during
317 * the very first evaluation of the method/object.
319 if (node
->flags
& ANOBJ_EVALUATED
) {
324 * Check that the ASL-defined parameter count is what is expected for
325 * this predefined name.
327 if ((param_count
!= required_params_current
) &&
328 (param_count
!= required_params_old
)) {
329 ACPI_WARNING((AE_INFO
,
330 "%s: Parameter count mismatch - ASL declared %d, ACPI requires %d",
331 pathname
, param_count
, required_params_current
));
335 /*******************************************************************************
337 * FUNCTION: acpi_ns_check_for_predefined_name
339 * PARAMETERS: Node - Namespace node for the method/object
341 * RETURN: Pointer to entry in predefined table. NULL indicates not found.
343 * DESCRIPTION: Check an object name against the predefined object list.
345 ******************************************************************************/
347 const union acpi_predefined_info
*acpi_ns_check_for_predefined_name(struct
351 const union acpi_predefined_info
*this_name
;
353 /* Quick check for a predefined name, first character must be underscore */
355 if (node
->name
.ascii
[0] != '_') {
359 /* Search info table for a predefined method/object name */
361 this_name
= predefined_names
;
362 while (this_name
->info
.name
[0]) {
363 if (ACPI_COMPARE_NAME(node
->name
.ascii
, this_name
->info
.name
)) {
365 /* Return pointer to this table entry */
371 * Skip next entry in the table if this name returns a Package
372 * (next entry contains the package info)
374 if (this_name
->info
.expected_btypes
& ACPI_RTYPE_PACKAGE
) {
384 /*******************************************************************************
386 * FUNCTION: acpi_ns_check_package
388 * PARAMETERS: Pathname - Full pathname to the node (for error msgs)
389 * return_object_ptr - Pointer to the object returned from the
390 * evaluation of a method or object
391 * Predefined - Pointer to entry in predefined name table
395 * DESCRIPTION: Check a returned package object for the correct count and
396 * correct type of all sub-objects.
398 ******************************************************************************/
401 acpi_ns_check_package(char *pathname
,
402 union acpi_operand_object
**return_object_ptr
,
403 const union acpi_predefined_info
*predefined
)
405 union acpi_operand_object
*return_object
= *return_object_ptr
;
406 const union acpi_predefined_info
*package
;
407 union acpi_operand_object
*sub_package
;
408 union acpi_operand_object
**elements
;
409 union acpi_operand_object
**sub_elements
;
416 ACPI_FUNCTION_NAME(ns_check_package
);
418 /* The package info for this name is in the next table entry */
420 package
= predefined
+ 1;
422 ACPI_DEBUG_PRINT((ACPI_DB_NAMES
,
423 "%s Validating return Package of Type %X, Count %X\n",
424 pathname
, package
->ret_info
.type
,
425 return_object
->package
.count
));
427 /* Extract package count and elements array */
429 elements
= return_object
->package
.elements
;
430 count
= return_object
->package
.count
;
432 /* The package must have at least one element, else invalid */
435 ACPI_WARNING((AE_INFO
,
436 "%s: Return Package has no elements (empty)",
439 return (AE_AML_OPERAND_VALUE
);
443 * Decode the type of the expected package contents
445 * PTYPE1 packages contain no subpackages
446 * PTYPE2 packages contain sub-packages
448 switch (package
->ret_info
.type
) {
449 case ACPI_PTYPE1_FIXED
:
452 * The package count is fixed and there are no sub-packages
454 * If package is too small, exit.
455 * If package is larger than expected, issue warning but continue
458 package
->ret_info
.count1
+ package
->ret_info
.count2
;
459 if (count
< expected_count
) {
460 goto package_too_small
;
461 } else if (count
> expected_count
) {
462 ACPI_WARNING((AE_INFO
,
463 "%s: Return Package is larger than needed - "
464 "found %u, expected %u", pathname
, count
,
468 /* Validate all elements of the returned package */
470 status
= acpi_ns_check_package_elements(pathname
, elements
,
479 if (ACPI_FAILURE(status
)) {
484 case ACPI_PTYPE1_VAR
:
487 * The package count is variable, there are no sub-packages, and all
488 * elements must be of the same type
490 for (i
= 0; i
< count
; i
++) {
491 status
= acpi_ns_check_object_type(pathname
, elements
,
494 if (ACPI_FAILURE(status
)) {
501 case ACPI_PTYPE1_OPTION
:
504 * The package count is variable, there are no sub-packages. There are
505 * a fixed number of required elements, and a variable number of
508 * Check if package is at least as large as the minimum required
510 expected_count
= package
->ret_info3
.count
;
511 if (count
< expected_count
) {
512 goto package_too_small
;
515 /* Variable number of sub-objects */
517 for (i
= 0; i
< count
; i
++) {
518 if (i
< package
->ret_info3
.count
) {
520 /* These are the required package elements (0, 1, or 2) */
523 acpi_ns_check_object_type(pathname
,
529 if (ACPI_FAILURE(status
)) {
533 /* These are the optional package elements */
536 acpi_ns_check_object_type(pathname
,
542 if (ACPI_FAILURE(status
)) {
550 case ACPI_PTYPE2_PKG_COUNT
:
552 /* First element is the (Integer) count of sub-packages to follow */
554 status
= acpi_ns_check_object_type(pathname
, elements
,
555 ACPI_RTYPE_INTEGER
, 0);
556 if (ACPI_FAILURE(status
)) {
561 * Count cannot be larger than the parent package length, but allow it
562 * to be smaller. The >= accounts for the Integer above.
564 expected_count
= (u32
) (*elements
)->integer
.value
;
565 if (expected_count
>= count
) {
566 goto package_too_small
;
569 count
= expected_count
;
572 /* Now we can walk the sub-packages */
574 /*lint -fallthrough */
577 case ACPI_PTYPE2_FIXED
:
578 case ACPI_PTYPE2_MIN
:
579 case ACPI_PTYPE2_COUNT
:
582 * These types all return a single package that consists of a variable
583 * number of sub-packages
585 for (i
= 0; i
< count
; i
++) {
586 sub_package
= *elements
;
587 sub_elements
= sub_package
->package
.elements
;
589 /* Each sub-object must be of type Package */
592 acpi_ns_check_object_type(pathname
, &sub_package
,
593 ACPI_RTYPE_PACKAGE
, i
);
594 if (ACPI_FAILURE(status
)) {
598 /* Examine the different types of sub-packages */
600 switch (package
->ret_info
.type
) {
602 case ACPI_PTYPE2_PKG_COUNT
:
604 /* Each subpackage has a fixed number of elements */
607 package
->ret_info
.count1
+
608 package
->ret_info
.count2
;
609 if (sub_package
->package
.count
!=
611 count
= sub_package
->package
.count
;
612 goto package_too_small
;
616 acpi_ns_check_package_elements(pathname
,
630 if (ACPI_FAILURE(status
)) {
635 case ACPI_PTYPE2_FIXED
:
637 /* Each sub-package has a fixed length */
639 expected_count
= package
->ret_info2
.count
;
640 if (sub_package
->package
.count
< expected_count
) {
641 count
= sub_package
->package
.count
;
642 goto package_too_small
;
645 /* Check the type of each sub-package element */
647 for (j
= 0; j
< expected_count
; j
++) {
649 acpi_ns_check_object_type(pathname
,
651 package
->ret_info2
.object_type
[j
], j
);
652 if (ACPI_FAILURE(status
)) {
658 case ACPI_PTYPE2_MIN
:
660 /* Each sub-package has a variable but minimum length */
662 expected_count
= package
->ret_info
.count1
;
663 if (sub_package
->package
.count
< expected_count
) {
664 count
= sub_package
->package
.count
;
665 goto package_too_small
;
668 /* Check the type of each sub-package element */
671 acpi_ns_check_package_elements(pathname
,
680 if (ACPI_FAILURE(status
)) {
685 case ACPI_PTYPE2_COUNT
:
687 /* First element is the (Integer) count of elements to follow */
690 acpi_ns_check_object_type(pathname
,
694 if (ACPI_FAILURE(status
)) {
698 /* Make sure package is large enough for the Count */
701 (u32
) (*sub_elements
)->integer
.value
;
702 if (sub_package
->package
.count
< expected_count
) {
703 count
= sub_package
->package
.count
;
704 goto package_too_small
;
707 /* Check the type of each sub-package element */
710 acpi_ns_check_package_elements(pathname
,
719 if (ACPI_FAILURE(status
)) {
734 /* Should not get here if predefined info table is correct */
736 ACPI_WARNING((AE_INFO
,
737 "%s: Invalid internal return type in table entry: %X",
738 pathname
, package
->ret_info
.type
));
740 return (AE_AML_INTERNAL
);
747 /* Error exit for the case with an incorrect package count */
749 ACPI_WARNING((AE_INFO
, "%s: Return Package is too small - "
750 "found %u, expected %u", pathname
, count
,
753 return (AE_AML_OPERAND_VALUE
);
756 /*******************************************************************************
758 * FUNCTION: acpi_ns_check_package_elements
760 * PARAMETERS: Pathname - Full pathname to the node (for error msgs)
761 * Elements - Pointer to the package elements array
762 * Type1 - Object type for first group
763 * Count1 - Count for first group
764 * Type2 - Object type for second group
765 * Count2 - Count for second group
766 * start_index - Start of the first group of elements
770 * DESCRIPTION: Check that all elements of a package are of the correct object
771 * type. Supports up to two groups of different object types.
773 ******************************************************************************/
776 acpi_ns_check_package_elements(char *pathname
,
777 union acpi_operand_object
**elements
,
780 u8 type2
, u32 count2
, u32 start_index
)
782 union acpi_operand_object
**this_element
= elements
;
787 * Up to two groups of package elements are supported by the data
788 * structure. All elements in each group must be of the same type.
789 * The second group can have a count of zero.
791 for (i
= 0; i
< count1
; i
++) {
792 status
= acpi_ns_check_object_type(pathname
, this_element
,
793 type1
, i
+ start_index
);
794 if (ACPI_FAILURE(status
)) {
800 for (i
= 0; i
< count2
; i
++) {
801 status
= acpi_ns_check_object_type(pathname
, this_element
,
803 (i
+ count1
+ start_index
));
804 if (ACPI_FAILURE(status
)) {
813 /*******************************************************************************
815 * FUNCTION: acpi_ns_check_object_type
817 * PARAMETERS: Pathname - Full pathname to the node (for error msgs)
818 * return_object_ptr - Pointer to the object returned from the
819 * evaluation of a method or object
820 * expected_btypes - Bitmap of expected return type(s)
821 * package_index - Index of object within parent package (if
822 * applicable - ACPI_NOT_PACKAGE otherwise)
826 * DESCRIPTION: Check the type of the return object against the expected object
827 * type(s). Use of Btype allows multiple expected object types.
829 ******************************************************************************/
832 acpi_ns_check_object_type(char *pathname
,
833 union acpi_operand_object
**return_object_ptr
,
834 u32 expected_btypes
, u32 package_index
)
836 union acpi_operand_object
*return_object
= *return_object_ptr
;
837 acpi_status status
= AE_OK
;
839 char type_buffer
[48]; /* Room for 5 types */
845 * If we get a NULL return_object here, it is a NULL package element,
846 * and this is always an error.
848 if (!return_object
) {
849 goto type_error_exit
;
852 /* A Namespace node should not get here, but make sure */
854 if (ACPI_GET_DESCRIPTOR_TYPE(return_object
) == ACPI_DESC_TYPE_NAMED
) {
855 ACPI_WARNING((AE_INFO
,
856 "%s: Invalid return type - Found a Namespace node [%4.4s] type %s",
857 pathname
, return_object
->node
.name
.ascii
,
858 acpi_ut_get_type_name(return_object
->node
.type
)));
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(expected_btypes
, package_index
,
905 if (ACPI_SUCCESS(status
)) {
908 goto type_error_exit
;
911 /* For reference objects, check that the reference type is correct */
913 if (return_object
->common
.type
== ACPI_TYPE_LOCAL_REFERENCE
) {
914 status
= acpi_ns_check_reference(pathname
, return_object
);
921 /* Create a string with all expected types for this predefined object */
925 this_rtype
= ACPI_RTYPE_INTEGER
;
927 for (i
= 0; i
< ACPI_NUM_RTYPES
; i
++) {
929 /* If one of the expected types, concatenate the name of this type */
931 if (expected_btypes
& this_rtype
) {
932 ACPI_STRCAT(type_buffer
, &acpi_rtype_names
[i
][j
]);
933 j
= 0; /* Use name separator from now on */
935 this_rtype
<<= 1; /* Next Rtype */
938 if (package_index
== ACPI_NOT_PACKAGE
) {
939 ACPI_WARNING((AE_INFO
,
940 "%s: Return type mismatch - found %s, expected %s",
942 acpi_ut_get_object_type_name(return_object
),
945 ACPI_WARNING((AE_INFO
,
946 "%s: Return Package type mismatch at index %u - "
947 "found %s, expected %s", pathname
, package_index
,
948 acpi_ut_get_object_type_name(return_object
),
952 return (AE_AML_OPERAND_TYPE
);
955 /*******************************************************************************
957 * FUNCTION: acpi_ns_check_reference
959 * PARAMETERS: Pathname - Full pathname to the node (for error msgs)
960 * return_object - Object returned from the evaluation of a
965 * DESCRIPTION: Check a returned reference object for the correct reference
966 * type. The only reference type that can be returned from a
967 * predefined method is a named reference. All others are invalid.
969 ******************************************************************************/
972 acpi_ns_check_reference(char *pathname
,
973 union acpi_operand_object
*return_object
)
977 * Check the reference object for the correct reference type (opcode).
978 * The only type of reference that can be converted to an union acpi_object is
979 * a reference to a named object (reference class: NAME)
981 if (return_object
->reference
.class == ACPI_REFCLASS_NAME
) {
985 ACPI_WARNING((AE_INFO
,
986 "%s: Return type mismatch - "
987 "unexpected reference object type [%s] %2.2X",
988 pathname
, acpi_ut_get_reference_name(return_object
),
989 return_object
->reference
.class));
991 return (AE_AML_OPERAND_TYPE
);
994 /*******************************************************************************
996 * FUNCTION: acpi_ns_repair_object
998 * PARAMETERS: Pathname - Full pathname to the node (for error msgs)
999 * package_index - Used to determine if target is in a package
1000 * return_object_ptr - Pointer to the object returned from the
1001 * evaluation of a method or object
1003 * RETURN: Status. AE_OK if repair was successful.
1005 * DESCRIPTION: Attempt to repair/convert a return object of a type that was
1008 ******************************************************************************/
1011 acpi_ns_repair_object(u32 expected_btypes
,
1013 union acpi_operand_object
**return_object_ptr
)
1015 union acpi_operand_object
*return_object
= *return_object_ptr
;
1016 union acpi_operand_object
*new_object
;
1019 switch (return_object
->common
.type
) {
1020 case ACPI_TYPE_BUFFER
:
1022 if (!(expected_btypes
& ACPI_RTYPE_STRING
)) {
1023 return (AE_AML_OPERAND_TYPE
);
1027 * Have a Buffer, expected a String, convert. Use a to_string
1028 * conversion, no transform performed on the buffer data. The best
1029 * example of this is the _BIF method, where the string data from
1030 * the battery is often (incorrectly) returned as buffer object(s).
1033 while ((length
< return_object
->buffer
.length
) &&
1034 (return_object
->buffer
.pointer
[length
])) {
1038 /* Allocate a new string object */
1040 new_object
= acpi_ut_create_string_object(length
);
1042 return (AE_NO_MEMORY
);
1046 * Copy the raw buffer data with no transform. String is already NULL
1047 * terminated at Length+1.
1049 ACPI_MEMCPY(new_object
->string
.pointer
,
1050 return_object
->buffer
.pointer
, length
);
1052 /* Install the new return object */
1054 acpi_ut_remove_reference(return_object
);
1055 *return_object_ptr
= new_object
;
1058 * If the object is a package element, we need to:
1059 * 1. Decrement the reference count of the orignal object, it was
1060 * incremented when building the package
1061 * 2. Increment the reference count of the new object, it will be
1062 * decremented when releasing the package
1064 if (package_index
!= ACPI_NOT_PACKAGE
) {
1065 acpi_ut_remove_reference(return_object
);
1066 acpi_ut_add_reference(new_object
);
1074 return (AE_AML_OPERAND_TYPE
);