aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBob Moore <robert.moore@intel.com>2017-09-19 22:00:36 -0400
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>2017-10-03 19:43:06 -0400
commitfe97d28704147ba72f7d7859909f80b4bb5a17d4 (patch)
tree50086c700b9106ad82c6a6c2616fc26ffdcd485a
parent81b7cb92958f50da1e0997de3289c09031c044c5 (diff)
ACPICA: Restructure/cleanup all string-to-integer conversion functions
ACPICA commit 610046d444ad781cc36673bf1f030abe50cbc61f Improve adherence to ACPI spec for implicit and explicit conversions Adds octal support for constants in ASL code Adds integer overflow errors for constants during ASL compilation Eliminates most of the existing complex flags parameters Simplify support for implicit/explicit runtime conversions Adds one new file, utilities/utstrsuppt.c Link: https://github.com/acpica/acpica/commit/610046d444ad Signed-off-by: Bob Moore <robert.moore@intel.com> Signed-off-by: Lv Zheng <lv.zheng@intel.com> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
-rw-r--r--drivers/acpi/acpica/Makefile1
-rw-r--r--drivers/acpi/acpica/acinterp.h6
-rw-r--r--drivers/acpi/acpica/acutils.h31
-rw-r--r--drivers/acpi/acpica/dbconvert.c5
-rw-r--r--drivers/acpi/acpica/dswexec.c2
-rw-r--r--drivers/acpi/acpica/exconcat.c2
-rw-r--r--drivers/acpi/acpica/exconvrt.c30
-rw-r--r--drivers/acpi/acpica/exmisc.c2
-rw-r--r--drivers/acpi/acpica/exresop.c2
-rw-r--r--drivers/acpi/acpica/nsconvert.c4
-rw-r--r--drivers/acpi/acpica/utstrsuppt.c417
-rw-r--r--drivers/acpi/acpica/utstrtoul64.c420
-rw-r--r--include/acpi/acexcep.h16
-rw-r--r--tools/power/acpi/tools/acpidump/Makefile1
-rw-r--r--tools/power/acpi/tools/acpidump/apdump.c3
-rw-r--r--tools/power/acpi/tools/acpidump/apmain.c4
16 files changed, 690 insertions, 256 deletions
diff --git a/drivers/acpi/acpica/Makefile b/drivers/acpi/acpica/Makefile
index 1709551bc4aa..2d09b0249ac8 100644
--- a/drivers/acpi/acpica/Makefile
+++ b/drivers/acpi/acpica/Makefile
@@ -177,6 +177,7 @@ acpi-y += \
177 utresrc.o \ 177 utresrc.o \
178 utstate.o \ 178 utstate.o \
179 utstring.o \ 179 utstring.o \
180 utstrsuppt.o \
180 utstrtoul64.o \ 181 utstrtoul64.o \
181 utxface.o \ 182 utxface.o \
182 utxfinit.o \ 183 utxfinit.o \
diff --git a/drivers/acpi/acpica/acinterp.h b/drivers/acpi/acpica/acinterp.h
index 29a863c85318..29555c8789a3 100644
--- a/drivers/acpi/acpica/acinterp.h
+++ b/drivers/acpi/acpica/acinterp.h
@@ -101,7 +101,8 @@ typedef const struct acpi_exdump_info {
101 */ 101 */
102acpi_status 102acpi_status
103acpi_ex_convert_to_integer(union acpi_operand_object *obj_desc, 103acpi_ex_convert_to_integer(union acpi_operand_object *obj_desc,
104 union acpi_operand_object **result_desc, u32 flags); 104 union acpi_operand_object **result_desc,
105 u32 implicit_conversion);
105 106
106acpi_status 107acpi_status
107acpi_ex_convert_to_buffer(union acpi_operand_object *obj_desc, 108acpi_ex_convert_to_buffer(union acpi_operand_object *obj_desc,
@@ -424,9 +425,6 @@ acpi_ex_store_object_to_node(union acpi_operand_object *source_desc,
424 struct acpi_walk_state *walk_state, 425 struct acpi_walk_state *walk_state,
425 u8 implicit_conversion); 426 u8 implicit_conversion);
426 427
427#define ACPI_IMPLICIT_CONVERSION TRUE
428#define ACPI_NO_IMPLICIT_CONVERSION FALSE
429
430/* 428/*
431 * exstoren - resolve/store object 429 * exstoren - resolve/store object
432 */ 430 */
diff --git a/drivers/acpi/acpica/acutils.h b/drivers/acpi/acpica/acutils.h
index 745134ade35f..7a568c604a75 100644
--- a/drivers/acpi/acpica/acutils.h
+++ b/drivers/acpi/acpica/acutils.h
@@ -141,6 +141,11 @@ extern const char *acpi_gbl_ptyp_decode[];
141#define ACPI_MSG_SUFFIX \ 141#define ACPI_MSG_SUFFIX \
142 acpi_os_printf (" (%8.8X/%s-%u)\n", ACPI_CA_VERSION, module_name, line_number) 142 acpi_os_printf (" (%8.8X/%s-%u)\n", ACPI_CA_VERSION, module_name, line_number)
143 143
144/* Flags to indicate implicit or explicit string-to-integer conversion */
145
146#define ACPI_IMPLICIT_CONVERSION TRUE
147#define ACPI_NO_IMPLICIT_CONVERSION FALSE
148
144/* Types for Resource descriptor entries */ 149/* Types for Resource descriptor entries */
145 150
146#define ACPI_INVALID_RESOURCE 0 151#define ACPI_INVALID_RESOURCE 0
@@ -197,15 +202,29 @@ void acpi_ut_strlwr(char *src_string);
197 202
198int acpi_ut_stricmp(char *string1, char *string2); 203int acpi_ut_stricmp(char *string1, char *string2);
199 204
200acpi_status acpi_ut_strtoul64(char *string, u32 flags, u64 *ret_integer); 205/*
206 * utstrsuppt - string-to-integer conversion support functions
207 */
208acpi_status acpi_ut_convert_octal_string(char *string, u64 *return_value);
209
210acpi_status acpi_ut_convert_decimal_string(char *string, u64 *return_value_ptr);
211
212acpi_status acpi_ut_convert_hex_string(char *string, u64 *return_value_ptr);
213
214char acpi_ut_remove_leading_zeros(char **string);
215
216u8 acpi_ut_detect_hex_prefix(char **string);
217
218u8 acpi_ut_detect_octal_prefix(char **string);
201 219
202/* 220/*
203 * Values for Flags above 221 * utstrtoul64 - string-to-integer conversion functions
204 * Note: LIMIT values correspond to acpi_gbl_integer_byte_width values (4/8)
205 */ 222 */
206#define ACPI_STRTOUL_32BIT 0x04 /* 4 bytes */ 223acpi_status acpi_ut_strtoul64(char *string, u64 *ret_integer);
207#define ACPI_STRTOUL_64BIT 0x08 /* 8 bytes */ 224
208#define ACPI_STRTOUL_BASE16 0x10 /* Default: Base10/16 */ 225u64 acpi_ut_explicit_strtoul64(char *string);
226
227u64 acpi_ut_implicit_strtoul64(char *string);
209 228
210/* 229/*
211 * utglobal - Global data structures and procedures 230 * utglobal - Global data structures and procedures
diff --git a/drivers/acpi/acpica/dbconvert.c b/drivers/acpi/acpica/dbconvert.c
index 857dbc43a9b1..32d546f0db2f 100644
--- a/drivers/acpi/acpica/dbconvert.c
+++ b/drivers/acpi/acpica/dbconvert.c
@@ -277,10 +277,7 @@ acpi_db_convert_to_object(acpi_object_type type,
277 default: 277 default:
278 278
279 object->type = ACPI_TYPE_INTEGER; 279 object->type = ACPI_TYPE_INTEGER;
280 status = acpi_ut_strtoul64(string, 280 status = acpi_ut_strtoul64(string, &object->integer.value);
281 (acpi_gbl_integer_byte_width |
282 ACPI_STRTOUL_BASE16),
283 &object->integer.value);
284 break; 281 break;
285 } 282 }
286 283
diff --git a/drivers/acpi/acpica/dswexec.c b/drivers/acpi/acpica/dswexec.c
index 20d7744b06ae..22f45d090733 100644
--- a/drivers/acpi/acpica/dswexec.c
+++ b/drivers/acpi/acpica/dswexec.c
@@ -134,7 +134,7 @@ acpi_ds_get_predicate_value(struct acpi_walk_state *walk_state,
134 * object. Implicitly convert the argument if necessary. 134 * object. Implicitly convert the argument if necessary.
135 */ 135 */
136 status = acpi_ex_convert_to_integer(obj_desc, &local_obj_desc, 136 status = acpi_ex_convert_to_integer(obj_desc, &local_obj_desc,
137 ACPI_STRTOUL_BASE16); 137 ACPI_IMPLICIT_CONVERSION);
138 if (ACPI_FAILURE(status)) { 138 if (ACPI_FAILURE(status)) {
139 goto cleanup; 139 goto cleanup;
140 } 140 }
diff --git a/drivers/acpi/acpica/exconcat.c b/drivers/acpi/acpica/exconcat.c
index 76bfb7dcae2f..59b8de2f07d3 100644
--- a/drivers/acpi/acpica/exconcat.c
+++ b/drivers/acpi/acpica/exconcat.c
@@ -156,7 +156,7 @@ acpi_ex_do_concatenate(union acpi_operand_object *operand0,
156 156
157 status = 157 status =
158 acpi_ex_convert_to_integer(local_operand1, &temp_operand1, 158 acpi_ex_convert_to_integer(local_operand1, &temp_operand1,
159 ACPI_STRTOUL_BASE16); 159 ACPI_IMPLICIT_CONVERSION);
160 break; 160 break;
161 161
162 case ACPI_TYPE_BUFFER: 162 case ACPI_TYPE_BUFFER:
diff --git a/drivers/acpi/acpica/exconvrt.c b/drivers/acpi/acpica/exconvrt.c
index f71028e334ee..23ebadb06a95 100644
--- a/drivers/acpi/acpica/exconvrt.c
+++ b/drivers/acpi/acpica/exconvrt.c
@@ -57,10 +57,10 @@ acpi_ex_convert_to_ascii(u64 integer, u16 base, u8 *string, u8 max_length);
57 * 57 *
58 * FUNCTION: acpi_ex_convert_to_integer 58 * FUNCTION: acpi_ex_convert_to_integer
59 * 59 *
60 * PARAMETERS: obj_desc - Object to be converted. Must be an 60 * PARAMETERS: obj_desc - Object to be converted. Must be an
61 * Integer, Buffer, or String 61 * Integer, Buffer, or String
62 * result_desc - Where the new Integer object is returned 62 * result_desc - Where the new Integer object is returned
63 * flags - Used for string conversion 63 * implicit_conversion - Used for string conversion
64 * 64 *
65 * RETURN: Status 65 * RETURN: Status
66 * 66 *
@@ -70,14 +70,14 @@ acpi_ex_convert_to_ascii(u64 integer, u16 base, u8 *string, u8 max_length);
70 70
71acpi_status 71acpi_status
72acpi_ex_convert_to_integer(union acpi_operand_object *obj_desc, 72acpi_ex_convert_to_integer(union acpi_operand_object *obj_desc,
73 union acpi_operand_object **result_desc, u32 flags) 73 union acpi_operand_object **result_desc,
74 u32 implicit_conversion)
74{ 75{
75 union acpi_operand_object *return_desc; 76 union acpi_operand_object *return_desc;
76 u8 *pointer; 77 u8 *pointer;
77 u64 result; 78 u64 result;
78 u32 i; 79 u32 i;
79 u32 count; 80 u32 count;
80 acpi_status status;
81 81
82 ACPI_FUNCTION_TRACE_PTR(ex_convert_to_integer, obj_desc); 82 ACPI_FUNCTION_TRACE_PTR(ex_convert_to_integer, obj_desc);
83 83
@@ -123,12 +123,18 @@ acpi_ex_convert_to_integer(union acpi_operand_object *obj_desc,
123 * hexadecimal as per the ACPI specification. The only exception (as 123 * hexadecimal as per the ACPI specification. The only exception (as
124 * of ACPI 3.0) is that the to_integer() operator allows both decimal 124 * of ACPI 3.0) is that the to_integer() operator allows both decimal
125 * and hexadecimal strings (hex prefixed with "0x"). 125 * and hexadecimal strings (hex prefixed with "0x").
126 *
127 * Explicit conversion is used only by to_integer.
128 * All other string-to-integer conversions are implicit conversions.
126 */ 129 */
127 status = acpi_ut_strtoul64(ACPI_CAST_PTR(char, pointer), 130 if (implicit_conversion) {
128 (acpi_gbl_integer_byte_width | 131 result =
129 flags), &result); 132 acpi_ut_implicit_strtoul64(ACPI_CAST_PTR
130 if (ACPI_FAILURE(status)) { 133 (char, pointer));
131 return_ACPI_STATUS(status); 134 } else {
135 result =
136 acpi_ut_explicit_strtoul64(ACPI_CAST_PTR
137 (char, pointer));
132 } 138 }
133 break; 139 break;
134 140
@@ -631,7 +637,7 @@ acpi_ex_convert_to_target_type(acpi_object_type destination_type,
631 */ 637 */
632 status = 638 status =
633 acpi_ex_convert_to_integer(source_desc, result_desc, 639 acpi_ex_convert_to_integer(source_desc, result_desc,
634 ACPI_STRTOUL_BASE16); 640 ACPI_IMPLICIT_CONVERSION);
635 break; 641 break;
636 642
637 case ACPI_TYPE_STRING: 643 case ACPI_TYPE_STRING:
diff --git a/drivers/acpi/acpica/exmisc.c b/drivers/acpi/acpica/exmisc.c
index 1e7649ce0a7b..dbad3ebd7df5 100644
--- a/drivers/acpi/acpica/exmisc.c
+++ b/drivers/acpi/acpica/exmisc.c
@@ -330,7 +330,7 @@ acpi_ex_do_logical_op(u16 opcode,
330 case ACPI_TYPE_INTEGER: 330 case ACPI_TYPE_INTEGER:
331 331
332 status = acpi_ex_convert_to_integer(operand1, &local_operand1, 332 status = acpi_ex_convert_to_integer(operand1, &local_operand1,
333 ACPI_STRTOUL_BASE16); 333 ACPI_IMPLICIT_CONVERSION);
334 break; 334 break;
335 335
336 case ACPI_TYPE_STRING: 336 case ACPI_TYPE_STRING:
diff --git a/drivers/acpi/acpica/exresop.c b/drivers/acpi/acpica/exresop.c
index c4852429e2ff..1c7c9962b0de 100644
--- a/drivers/acpi/acpica/exresop.c
+++ b/drivers/acpi/acpica/exresop.c
@@ -415,7 +415,7 @@ acpi_ex_resolve_operands(u16 opcode,
415 * Known as "Implicit Source Operand Conversion" 415 * Known as "Implicit Source Operand Conversion"
416 */ 416 */
417 status = acpi_ex_convert_to_integer(obj_desc, stack_ptr, 417 status = acpi_ex_convert_to_integer(obj_desc, stack_ptr,
418 ACPI_STRTOUL_BASE16); 418 ACPI_IMPLICIT_CONVERSION);
419 if (ACPI_FAILURE(status)) { 419 if (ACPI_FAILURE(status)) {
420 if (status == AE_TYPE) { 420 if (status == AE_TYPE) {
421 ACPI_ERROR((AE_INFO, 421 ACPI_ERROR((AE_INFO,
diff --git a/drivers/acpi/acpica/nsconvert.c b/drivers/acpi/acpica/nsconvert.c
index e4a7da8a11f0..539d775bbc92 100644
--- a/drivers/acpi/acpica/nsconvert.c
+++ b/drivers/acpi/acpica/nsconvert.c
@@ -78,8 +78,8 @@ acpi_ns_convert_to_integer(union acpi_operand_object *original_object,
78 78
79 /* String-to-Integer conversion */ 79 /* String-to-Integer conversion */
80 80
81 status = acpi_ut_strtoul64(original_object->string.pointer, 81 status =
82 acpi_gbl_integer_byte_width, &value); 82 acpi_ut_strtoul64(original_object->string.pointer, &value);
83 if (ACPI_FAILURE(status)) { 83 if (ACPI_FAILURE(status)) {
84 return (status); 84 return (status);
85 } 85 }
diff --git a/drivers/acpi/acpica/utstrsuppt.c b/drivers/acpi/acpica/utstrsuppt.c
new file mode 100644
index 000000000000..ca41f037fd9a
--- /dev/null
+++ b/drivers/acpi/acpica/utstrsuppt.c
@@ -0,0 +1,417 @@
1/*******************************************************************************
2 *
3 * Module Name: utstrsuppt - string-to-integer conversion support functions
4 *
5 ******************************************************************************/
6
7/*
8 * Copyright (C) 2000 - 2017, 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
47#define _COMPONENT ACPI_UTILITIES
48ACPI_MODULE_NAME("utstrsuppt")
49
50/* Local prototypes */
51static acpi_status
52acpi_ut_insert_digit(u64 *accumulated_value, u32 base, int ascii_digit);
53
54static acpi_status
55acpi_ut_strtoul_multiply64(u64 multiplicand, u64 multiplier, u64 *out_product);
56
57static acpi_status
58acpi_ut_strtoul_add64(u64 addend1, u64 addend2, u64 *out_sum);
59
60/*******************************************************************************
61 *
62 * FUNCTION: acpi_ut_convert_octal_string
63 *
64 * PARAMETERS: string - Null terminated input string
65 * return_value_ptr - Where the converted value is returned
66 *
67 * RETURN: Status and 64-bit converted integer
68 *
69 * DESCRIPTION: Performs a base 8 conversion of the input string to an
70 * integer value, either 32 or 64 bits.
71 *
72 * NOTE: Maximum 64-bit unsigned octal value is 01777777777777777777777
73 * Maximum 32-bit unsigned octal value is 037777777777
74 *
75 ******************************************************************************/
76
77acpi_status acpi_ut_convert_octal_string(char *string, u64 *return_value_ptr)
78{
79 u64 accumulated_value = 0;
80 acpi_status status = AE_OK;
81
82 /* Convert each ASCII byte in the input string */
83
84 while (*string) {
85
86 /* Must be ASCII 0-7, otherwise terminate with no error */
87
88 if (!(ACPI_IS_OCTAL_DIGIT(*string))) {
89 break;
90 }
91
92 /* Convert and insert this octal digit into the accumulator */
93
94 status = acpi_ut_insert_digit(&accumulated_value, 8, *string);
95 if (ACPI_FAILURE(status)) {
96 status = AE_OCTAL_OVERFLOW;
97 break;
98 }
99
100 string++;
101 }
102
103 /* Always return the value that has been accumulated */
104
105 *return_value_ptr = accumulated_value;
106 return (status);
107}
108
109/*******************************************************************************
110 *
111 * FUNCTION: acpi_ut_convert_decimal_string
112 *
113 * PARAMETERS: string - Null terminated input string
114 * return_value_ptr - Where the converted value is returned
115 *
116 * RETURN: Status and 64-bit converted integer
117 *
118 * DESCRIPTION: Performs a base 10 conversion of the input string to an
119 * integer value, either 32 or 64 bits.
120 *
121 * NOTE: Maximum 64-bit unsigned decimal value is 18446744073709551615
122 * Maximum 32-bit unsigned decimal value is 4294967295
123 *
124 ******************************************************************************/
125
126acpi_status acpi_ut_convert_decimal_string(char *string, u64 *return_value_ptr)
127{
128 u64 accumulated_value = 0;
129 acpi_status status = AE_OK;
130
131 /* Convert each ASCII byte in the input string */
132
133 while (*string) {
134
135 /* Must be ASCII 0-9, otherwise terminate with no error */
136
137 if (!isdigit(*string)) {
138 break;
139 }
140
141 /* Convert and insert this decimal digit into the accumulator */
142
143 status = acpi_ut_insert_digit(&accumulated_value, 10, *string);
144 if (ACPI_FAILURE(status)) {
145 status = AE_DECIMAL_OVERFLOW;
146 break;
147 }
148
149 string++;
150 }
151
152 /* Always return the value that has been accumulated */
153
154 *return_value_ptr = accumulated_value;
155 return (status);
156}
157
158/*******************************************************************************
159 *
160 * FUNCTION: acpi_ut_convert_hex_string
161 *
162 * PARAMETERS: string - Null terminated input string
163 * return_value_ptr - Where the converted value is returned
164 *
165 * RETURN: Status and 64-bit converted integer
166 *
167 * DESCRIPTION: Performs a base 16 conversion of the input string to an
168 * integer value, either 32 or 64 bits.
169 *
170 * NOTE: Maximum 64-bit unsigned hex value is 0xFFFFFFFFFFFFFFFF
171 * Maximum 32-bit unsigned hex value is 0xFFFFFFFF
172 *
173 ******************************************************************************/
174
175acpi_status acpi_ut_convert_hex_string(char *string, u64 *return_value_ptr)
176{
177 u64 accumulated_value = 0;
178 acpi_status status = AE_OK;
179
180 /* Convert each ASCII byte in the input string */
181
182 while (*string) {
183
184 /* Must be ASCII A-F, a-f, or 0-9, otherwise terminate with no error */
185
186 if (!isxdigit(*string)) {
187 break;
188 }
189
190 /* Convert and insert this hex digit into the accumulator */
191
192 status = acpi_ut_insert_digit(&accumulated_value, 16, *string);
193 if (ACPI_FAILURE(status)) {
194 status = AE_HEX_OVERFLOW;
195 break;
196 }
197
198 string++;
199 }
200
201 /* Always return the value that has been accumulated */
202
203 *return_value_ptr = accumulated_value;
204 return (status);
205}
206
207/*******************************************************************************
208 *
209 * FUNCTION: acpi_ut_remove_leading_zeros
210 *
211 * PARAMETERS: string - Pointer to input ASCII string
212 *
213 * RETURN: Next character after the leading zeros. This behavior may be
214 * Used by the caller to detect end-of-string.
215 *
216 * DESCRIPTION: Remove all leading zeros in the input string. Return the
217 * next character after the final zero to check for the end
218 * of the string (NULL terminator).
219 *
220 ******************************************************************************/
221
222char acpi_ut_remove_leading_zeros(char **string)
223{
224 /* Skip all leading zeros */
225
226 while (**string == ACPI_ASCII_ZERO) {
227 *string += 1;
228 }
229
230 return (**string);
231}
232
233/*******************************************************************************
234 *
235 * FUNCTION: acpi_ut_detect_hex_prefix
236 *
237 * PARAMETERS: string - Pointer to input ASCII string
238 *
239 * RETURN: TRUE if a 0x prefix was found
240 *
241 * DESCRIPTION: Detect and remove a hex 0x prefix
242 *
243 ******************************************************************************/
244
245u8 acpi_ut_detect_hex_prefix(char **string)
246{
247
248 if ((**string == ACPI_ASCII_ZERO) &&
249 (tolower((int)*(*string + 1)) == 'x')) {
250 *string += 2; /* Go past the leading 0x */
251 return (TRUE);
252 }
253
254 return (FALSE); /* Not a hex string */
255}
256
257/*******************************************************************************
258 *
259 * FUNCTION: acpi_ut_detect_octal_prefix
260 *
261 * PARAMETERS: string - Pointer to input ASCII string
262 *
263 * RETURN: True if an octal 0 prefix was found
264 *
265 * DESCRIPTION: Detect and remove an octal prefix (zero)
266 *
267 ******************************************************************************/
268
269u8 acpi_ut_detect_octal_prefix(char **string)
270{
271
272 if (**string == ACPI_ASCII_ZERO) {
273 *string += 1; /* Go past the leading 0 */
274 return (TRUE);
275 }
276
277 return (FALSE); /* Not an octal string */
278}
279
280/*******************************************************************************
281 *
282 * FUNCTION: acpi_ut_insert_digit
283 *
284 * PARAMETERS: accumulated_value - Current value of the integer value
285 * accumulator. The New value is
286 * returned here.
287 * base - Radix, either 8/10/16 supported
288 * ascii_digit - ASCII single digit to be inserted
289 *
290 * RETURN: Status and result of convert/insert operation. The only
291 * exception is numeric overflow of either the multiply or the
292 * add operations.
293 *
294 * DESCRIPTION: Generic conversion and insertion function for all bases:
295 *
296 * 1) Multiply the current accumulated converted value by the
297 * base in order to make room for the new character.
298 *
299 * 2) Add the current accumulated/converted value the new
300 * character (after the character has been converted to a binary
301 * value).
302 *
303 * Note: The only possible exception indicates an integer
304 * overflow (AE_NUMERIC_OVERFLOW)
305 *
306 ******************************************************************************/
307
308static acpi_status
309acpi_ut_insert_digit(u64 *accumulated_value, u32 base, int ascii_digit)
310{
311 acpi_status status;
312 u64 product;
313
314 /* Make room in the accumulated value for the incoming digit */
315
316 status = acpi_ut_strtoul_multiply64(*accumulated_value, base, &product);
317 if (ACPI_FAILURE(status)) {
318 return (status);
319 }
320
321 /* Add in the new digit, and store to the caller's accumulated value */
322
323 status =
324 acpi_ut_strtoul_add64(product,
325 acpi_ut_ascii_char_to_hex(ascii_digit),
326 accumulated_value);
327 if (ACPI_FAILURE(status)) {
328 return (status);
329 }
330
331 return (AE_OK);
332}
333
334/*******************************************************************************
335 *
336 * FUNCTION: acpi_ut_strtoul_multiply64
337 *
338 * PARAMETERS: multiplicand - Current accumulated converted integer
339 * multiplier - Base/Radix
340 * out_product - Where the product is returned
341 *
342 * RETURN: Status and 64-bit product
343 *
344 * DESCRIPTION: Multiply two 64-bit values, with checking for 64-bit overflow as
345 * well as 32-bit overflow if necessary (if the current global
346 * integer width is 32).
347 *
348 ******************************************************************************/
349
350static acpi_status
351acpi_ut_strtoul_multiply64(u64 multiplicand, u64 multiplier, u64 *out_product)
352{
353 u64 val;
354
355 /* Exit if either operand is zero */
356
357 *out_product = 0;
358 if (!multiplicand || !multiplier) {
359 return (AE_OK);
360 }
361
362 /* Check for 64-bit overflow before the actual multiplication */
363
364 acpi_ut_short_divide(ACPI_UINT64_MAX, (u32)multiplier, &val, NULL);
365 if (multiplicand > val) {
366 return (AE_NUMERIC_OVERFLOW);
367 }
368
369 val = multiplicand * multiplier;
370
371 /* Check for 32-bit overflow if necessary */
372
373 if ((acpi_gbl_integer_bit_width == 32) && (val > ACPI_UINT32_MAX)) {
374 return (AE_NUMERIC_OVERFLOW);
375 }
376
377 *out_product = val;
378 return (AE_OK);
379}
380
381/*******************************************************************************
382 *
383 * FUNCTION: acpi_ut_strtoul_add64
384 *
385 * PARAMETERS: addend1 - Current accumulated converted integer
386 * addend2 - New hex value/char
387 * out_sum - Where sum is returned (Accumulator)
388 *
389 * RETURN: Status and 64-bit sum
390 *
391 * DESCRIPTION: Add two 64-bit values, with checking for 64-bit overflow as
392 * well as 32-bit overflow if necessary (if the current global
393 * integer width is 32).
394 *
395 ******************************************************************************/
396
397static acpi_status acpi_ut_strtoul_add64(u64 addend1, u64 addend2, u64 *out_sum)
398{
399 u64 sum;
400
401 /* Check for 64-bit overflow before the actual addition */
402
403 if ((addend1 > 0) && (addend2 > (ACPI_UINT64_MAX - addend1))) {
404 return (AE_NUMERIC_OVERFLOW);
405 }
406
407 sum = addend1 + addend2;
408
409 /* Check for 32-bit overflow if necessary */
410
411 if ((acpi_gbl_integer_bit_width == 32) && (sum > ACPI_UINT32_MAX)) {
412 return (AE_NUMERIC_OVERFLOW);
413 }
414
415 *out_sum = sum;
416 return (AE_OK);
417}
diff --git a/drivers/acpi/acpica/utstrtoul64.c b/drivers/acpi/acpica/utstrtoul64.c
index 9633ee142855..e5a2df3f16e5 100644
--- a/drivers/acpi/acpica/utstrtoul64.c
+++ b/drivers/acpi/acpica/utstrtoul64.c
@@ -1,6 +1,7 @@
1/******************************************************************************* 1/*******************************************************************************
2 * 2 *
3 * Module Name: utstrtoul64 - string to 64-bit integer support 3 * Module Name: utstrtoul64 - string-to-integer support for both 64-bit
4 * and 32-bit integers
4 * 5 *
5 ******************************************************************************/ 6 ******************************************************************************/
6 7
@@ -44,152 +45,74 @@
44#include <acpi/acpi.h> 45#include <acpi/acpi.h>
45#include "accommon.h" 46#include "accommon.h"
46 47
47/*******************************************************************************
48 *
49 * The functions in this module satisfy the need for 64-bit string-to-integer
50 * conversions on both 32-bit and 64-bit platforms.
51 *
52 ******************************************************************************/
53
54#define _COMPONENT ACPI_UTILITIES 48#define _COMPONENT ACPI_UTILITIES
55ACPI_MODULE_NAME("utstrtoul64") 49ACPI_MODULE_NAME("utstrtoul64")
56 50
57/* Local prototypes */
58static u64 acpi_ut_strtoul_base10(char *string, u32 flags);
59
60static u64 acpi_ut_strtoul_base16(char *string, u32 flags);
61
62/******************************************************************************* 51/*******************************************************************************
63 * 52 *
64 * String conversion rules as written in the ACPI specification. The error 53 * This module contains the external string to 64/32-bit unsigned integer
65 * conditions and behavior are different depending on the type of conversion. 54 * conversion functions:
66 *
67 * 55 *
68 * Implicit data type conversion: string-to-integer 56 * 1) Standard strtoul() function with 64-bit support. This is mostly used by
69 * -------------------------------------------------- 57 * the iASL compiler.
70 * 58 * 2) Runtime "Explicit conversion" as defined in the ACPI specification.
71 * Base is always 16. This is the ACPI_STRTOUL_BASE16 case. 59 * 3) Runtime "Implicit conversion" as defined in the ACPI specification.
72 *
73 * Example:
74 * Add ("BA98", Arg0, Local0)
75 *
76 * The integer is initialized to the value zero.
77 * The ASCII string is interpreted as a hexadecimal constant.
78 *
79 * 1) A "0x" prefix is not allowed. However, ACPICA allows this for
80 * compatibility with previous ACPICA. (NO ERROR)
81 *
82 * 2) Terminates when the size of an integer is reached (32 or 64 bits).
83 * (NO ERROR)
84 * 60 *
85 * 3) The first non-hex character terminates the conversion without error. 61 * Current users of this module:
86 * (NO ERROR)
87 * 62 *
88 * 4) Conversion of a null (zero-length) string to an integer is not 63 * interpreter - Implicit and explicit conversions, GPE method names
89 * allowed. However, ACPICA allows this for compatibility with previous 64 * debugger - Command line input string conversion
90 * ACPICA. This conversion returns the value 0. (NO ERROR) 65 * iASL - Main parser, conversion of constants to integers
91 * 66 * iASL - Data Table Compiler parser (constant math expressions)
92 * 67 * iASL - Preprocessor (constant math expressions)
93 * Explicit data type conversion: to_integer() with string operand 68 * acpi_dump - Input table addresses
94 * --------------------------------------------------------------- 69 * acpi_exec - Testing of the acpi_ut_strtoul64 function
95 *
96 * Base is either 10 (default) or 16 (with 0x prefix)
97 *
98 * Examples:
99 * to_integer ("1000")
100 * to_integer ("0xABCD")
101 *
102 * 1) Can be (must be) either a decimal or hexadecimal numeric string.
103 * A hex value must be prefixed by "0x" or it is interpreted as a decimal.
104 * 70 *
105 * 2) The value must not exceed the maximum of an integer value. ACPI spec 71 * Notes concerning users of these interfaces:
106 * states the behavior is "unpredictable", so ACPICA matches the behavior
107 * of the implicit conversion case.(NO ERROR)
108 * 72 *
109 * 3) Behavior on the first non-hex character is not specified by the ACPI 73 * acpi_gbl_integer_byte_width is used to set the 32/64 bit limit. This global
110 * spec, so ACPICA matches the behavior of the implicit conversion case 74 * must be set to the proper width. For the core ACPICA code, the width
111 * and terminates. (NO ERROR) 75 * depends on the DSDT version. For iASL, the default width is 64 bits for
76 * all parsers, but error checking is performed later to flag cases where
77 * a 64-bit constant is wrongly defined in a 32-bit DSDT/SSDT.
112 * 78 *
113 * 4) A null (zero-length) string is illegal. 79 * In ACPI, the only place where octal numbers are supported is within
114 * However, ACPICA allows this for compatibility with previous ACPICA. 80 * the ASL language itself. There is no runtime support for octal.
115 * This conversion returns the value 0. (NO ERROR)
116 * 81 *
117 ******************************************************************************/ 82 ******************************************************************************/
118
119/******************************************************************************* 83/*******************************************************************************
120 * 84 *
121 * FUNCTION: acpi_ut_strtoul64 85 * FUNCTION: acpi_ut_strtoul64
122 * 86 *
123 * PARAMETERS: string - Null terminated input string 87 * PARAMETERS: string - Null terminated input string.
124 * flags - Conversion info, see below 88 * Must be a valid pointer
125 * return_value - Where the converted integer is 89 * return_value - Where the converted integer is
126 * returned 90 * returned. Must be a valid pointer
127 *
128 * RETURN: Status and Converted value
129 *
130 * DESCRIPTION: Convert a string into an unsigned value. Performs either a
131 * 32-bit or 64-bit conversion, depending on the input integer
132 * size in Flags (often the current mode of the interpreter).
133 *
134 * Values for Flags:
135 * ACPI_STRTOUL_32BIT - Max integer value is 32 bits
136 * ACPI_STRTOUL_64BIT - Max integer value is 64 bits
137 * ACPI_STRTOUL_BASE16 - Input string is hexadecimal. Default
138 * is 10/16 based on string prefix (0x).
139 * 91 *
140 * NOTES: 92 * RETURN: Status and converted integer
141 * Negative numbers are not supported, as they are not supported by ACPI. 93 * Returns an exception on numeric overflow
142 * 94 *
143 * Supports only base 16 or base 10 strings/values. Does not 95 * DESCRIPTION: Convert a string into an unsigned integer. Performs either a
144 * support Octal strings, as these are not supported by ACPI. 96 * 32-bit or 64-bit conversion, depending on the current global
97 * integer width. Supports Decimal, Hex, and Octal strings.
145 * 98 *
146 * Current users of this support: 99 * Current users of this function:
147 * 100 *
148 * interpreter - Implicit and explicit conversions, GPE method names
149 * debugger - Command line input string conversion
150 * iASL - Main parser, conversion of constants to integers
151 * iASL - Data Table Compiler parser (constant math expressions)
152 * iASL - Preprocessor (constant math expressions) 101 * iASL - Preprocessor (constant math expressions)
153 * acpi_dump - Input table addresses 102 * iASL - Main parser, conversion of ASL constants to integers
154 * acpi_exec - Testing of the acpi_ut_strtoul64 function 103 * iASL - Data Table Compiler parser (constant math expressions)
155 *
156 * Note concerning callers:
157 * acpi_gbl_integer_byte_width can be used to set the 32/64 limit. If used,
158 * this global should be set to the proper width. For the core ACPICA code,
159 * this width depends on the DSDT version. For iASL, the default byte
160 * width is always 8 for the parser, but error checking is performed later
161 * to flag cases where a 64-bit constant is defined in a 32-bit DSDT/SSDT.
162 * 104 *
163 ******************************************************************************/ 105 ******************************************************************************/
164 106acpi_status acpi_ut_strtoul64(char *string, u64 *return_value)
165acpi_status acpi_ut_strtoul64(char *string, u32 flags, u64 *return_value)
166{ 107{
167 acpi_status status = AE_OK; 108 acpi_status status = AE_OK;
168 u32 base; 109 u32 base = 10; /* Default is decimal */
169 110
170 ACPI_FUNCTION_TRACE_STR(ut_strtoul64, string); 111 ACPI_FUNCTION_TRACE_STR(ut_strtoul64, string);
171 112
172 /* Parameter validation */
173
174 if (!string || !return_value) {
175 return_ACPI_STATUS(AE_BAD_PARAMETER);
176 }
177
178 *return_value = 0; 113 *return_value = 0;
179 114
180 /* Check for zero-length string, returns 0 */ 115 /* Null return string returns a value of zero */
181
182 if (*string == 0) {
183 return_ACPI_STATUS(AE_OK);
184 }
185
186 /* Skip over any white space at start of string */
187
188 while (isspace((int)*string)) {
189 string++;
190 }
191
192 /* End of string? return 0 */
193 116
194 if (*string == 0) { 117 if (*string == 0) {
195 return_ACPI_STATUS(AE_OK); 118 return_ACPI_STATUS(AE_OK);
@@ -198,45 +121,45 @@ acpi_status acpi_ut_strtoul64(char *string, u32 flags, u64 *return_value)
198 /* 121 /*
199 * 1) The "0x" prefix indicates base 16. Per the ACPI specification, 122 * 1) The "0x" prefix indicates base 16. Per the ACPI specification,
200 * the "0x" prefix is only allowed for implicit (non-strict) conversions. 123 * the "0x" prefix is only allowed for implicit (non-strict) conversions.
201 * However, we always allow it for compatibility with older ACPICA. 124 * However, we always allow it for compatibility with older ACPICA and
125 * just plain on principle.
202 */ 126 */
203 if ((*string == ACPI_ASCII_ZERO) && 127 if (acpi_ut_detect_hex_prefix(&string)) {
204 (tolower((int)*(string + 1)) == 'x')) {
205 string += 2; /* Go past the 0x */
206 if (*string == 0) {
207 return_ACPI_STATUS(AE_OK); /* Return value 0 */
208 }
209
210 base = 16;
211 }
212
213 /* 2) Force to base 16 (implicit conversion case) */
214
215 else if (flags & ACPI_STRTOUL_BASE16) {
216 base = 16; 128 base = 16;
217 } 129 }
218 130
219 /* 3) Default fallback is to Base 10 */ 131 /*
220 132 * 2) Check for an octal constant, defined to be a leading zero
221 else { 133 * followed by an valid octal digit (0-7)
222 base = 10; 134 */
135 else if (acpi_ut_detect_octal_prefix(&string)) {
136 base = 8;
223 } 137 }
224 138
225 /* Skip all leading zeros */ 139 if (!acpi_ut_remove_leading_zeros(&string)) {
226 140 return_ACPI_STATUS(AE_OK); /* Return value 0 */
227 while (*string == ACPI_ASCII_ZERO) {
228 string++;
229 if (*string == 0) {
230 return_ACPI_STATUS(AE_OK); /* Return value 0 */
231 }
232 } 141 }
233 142
234 /* Perform the base 16 or 10 conversion */ 143 /*
235 144 * Perform the base 8, 10, or 16 conversion. A numeric overflow will
236 if (base == 16) { 145 * return an exception.
237 *return_value = acpi_ut_strtoul_base16(string, flags); 146 */
238 } else { 147 switch (base) {
239 *return_value = acpi_ut_strtoul_base10(string, flags); 148 case 8:
149 status = acpi_ut_convert_octal_string(string, return_value);
150 break;
151
152 case 10:
153 status = acpi_ut_convert_decimal_string(string, return_value);
154 break;
155
156 case 16:
157 status = acpi_ut_convert_hex_string(string, return_value);
158 break;
159
160 default:
161 status = AE_AML_INTERNAL; /* Should never happen */
162 break;
240 } 163 }
241 164
242 return_ACPI_STATUS(status); 165 return_ACPI_STATUS(status);
@@ -244,104 +167,167 @@ acpi_status acpi_ut_strtoul64(char *string, u32 flags, u64 *return_value)
244 167
245/******************************************************************************* 168/*******************************************************************************
246 * 169 *
247 * FUNCTION: acpi_ut_strtoul_base10 170 * FUNCTION: acpi_ut_implicit_strtoul64
171 *
172 * PARAMETERS: string - Null terminated input string.
173 * Must be a valid pointer
248 * 174 *
249 * PARAMETERS: string - Null terminated input string 175 * RETURN: Converted integer
250 * flags - Conversion info
251 * 176 *
252 * RETURN: 64-bit converted integer 177 * DESCRIPTION: Perform a 64-bit conversion with restrictions placed upon
178 * an "implicit conversion" by the ACPI specification. Used by
179 * many ASL operators that require an integer operand, and support
180 * an automatic (implicit) conversion from a string operand
181 * to the final integer operand. The restriction is that only
182 * hex strings are supported.
253 * 183 *
254 * DESCRIPTION: Performs a base 10 conversion of the input string to an 184 * -----------------------------------------------------------------------------
255 * integer value, either 32 or 64 bits. 185 *
256 * Note: String must be valid and non-null. 186 * Base is always 16, either with or without the 0x prefix.
187 *
188 * Examples (both are hex values):
189 * Add ("BA98", Arg0, Local0)
190 * Subtract ("0x12345678", Arg1, Local1)
191 *
192 * Rules extracted from the ACPI specification:
193 *
194 * The converted integer is initialized to the value zero.
195 * The ASCII string is interpreted as a hexadecimal constant.
196 *
197 * 1) A "0x" prefix is not allowed. However, ACPICA allows this as an
198 * ACPI extension on general principle. (NO ERROR)
199 *
200 * 2) Terminates when the size of an integer is reached (32 or 64 bits).
201 * There are no numeric overflow conditions. (NO ERROR)
202 *
203 * 3) The first non-hex character terminates the conversion and returns
204 * the current accumulated value of the converted integer (NO ERROR).
205 *
206 * 4) Conversion of a null (zero-length) string to an integer is
207 * technically allowed. However, ACPICA allows as an ACPI extension.
208 * The conversion returns the value 0. (NO ERROR)
209 *
210 * Note: there are no error conditions returned by this function. At
211 * the minimum, a value of zero is returned.
212 *
213 * Current users of this function:
214 *
215 * interpreter - All runtime implicit conversions, as per ACPI specification
216 * iASL - Data Table Compiler parser (constant math expressions)
257 * 217 *
258 ******************************************************************************/ 218 ******************************************************************************/
259 219
260static u64 acpi_ut_strtoul_base10(char *string, u32 flags) 220u64 acpi_ut_implicit_strtoul64(char *string)
261{ 221{
262 int ascii_digit; 222 u64 converted_integer = 0;
263 u64 next_value;
264 u64 return_value = 0;
265 223
266 /* Main loop: convert each ASCII byte in the input string */ 224 ACPI_FUNCTION_TRACE_STR(ut_implicit_strtoul64, string);
267 225
268 while (*string) { 226 /*
269 ascii_digit = *string; 227 * Per the ACPI specification, only hexadecimal is supported for
270 if (!isdigit(ascii_digit)) { 228 * implicit conversions, and the "0x" prefix is "not allowed".
271 229 * However, allow a "0x" prefix as an ACPI extension.
272 /* Not ASCII 0-9, terminate */ 230 */
273 231 acpi_ut_detect_hex_prefix(&string);
274 goto exit;
275 }
276
277 /* Convert and insert (add) the decimal digit */
278
279 acpi_ut_short_multiply(return_value, 10, &next_value);
280 next_value += (ascii_digit - ACPI_ASCII_ZERO);
281
282 /* Check for overflow (32 or 64 bit) - return current converted value */
283
284 if (((flags & ACPI_STRTOUL_32BIT) && (next_value > ACPI_UINT32_MAX)) || (next_value < return_value)) { /* 64-bit overflow case */
285 goto exit;
286 }
287 232
288 return_value = next_value; 233 if (!acpi_ut_remove_leading_zeros(&string)) {
289 string++; 234 return_VALUE(0);
290 } 235 }
291 236
292exit: 237 /*
293 return (return_value); 238 * Ignore overflow as per the ACPI specification. This is implemented by
239 * ignoring the return status below. On overflow, the input string is
240 * simply truncated.
241 */
242 acpi_ut_convert_hex_string(string, &converted_integer);
243 return_VALUE(converted_integer);
294} 244}
295 245
296/******************************************************************************* 246/*******************************************************************************
297 * 247 *
298 * FUNCTION: acpi_ut_strtoul_base16 248 * FUNCTION: acpi_ut_explicit_strtoul64
249 *
250 * PARAMETERS: string - Null terminated input string.
251 * Must be a valid pointer
252 *
253 * RETURN: Converted integer
254 *
255 * DESCRIPTION: Perform a 64-bit conversion with the restrictions placed upon
256 * an "explicit conversion" by the ACPI specification. The
257 * main restriction is that only hex and decimal are supported.
258 *
259 * -----------------------------------------------------------------------------
260 *
261 * Base is either 10 (default) or 16 (with 0x prefix). There is no octal
262 * (base 8), as per the ACPI specification.
263 *
264 * Examples:
265 * to_integer ("1000") Decimal
266 * to_integer ("0xABCD") Hex
267 *
268 * Rules extracted from the ACPI specification:
269 *
270 * 1) Thi input string is either a decimal or hexadecimal numeric string.
271 * A hex value must be prefixed by "0x" or it is interpreted as decimal.
272 *
273 * 2) The value must not exceed the maximum of an integer value
274 * (32 or 64 bits). The ACPI specification states the behavior is
275 * "unpredictable", so ACPICA matches the behavior of the implicit
276 * conversion case. There are no numeric overflow conditions. (NO ERROR)
277 *
278 * 3) Behavior on the first non-hex character is not specified by the ACPI
279 * specification (for the to_integer operator), so ACPICA matches the
280 * behavior of the implicit conversion case. It terminates the
281 * conversion and returns the current accumulated value of the converted
282 * integer. (NO ERROR)
299 * 283 *
300 * PARAMETERS: string - Null terminated input string 284 * 4) Conversion of a null (zero-length) string to an integer is
301 * flags - conversion info 285 * technically allowed. However, ACPICA allows as an ACPI extension.
286 * The conversion returns the value 0. (NO ERROR)
302 * 287 *
303 * RETURN: 64-bit converted integer 288 * Note: there are no error conditions returned by this function. At
289 * the minimum, a value of zero is returned.
304 * 290 *
305 * DESCRIPTION: Performs a base 16 conversion of the input string to an 291 * Current users of this function:
306 * integer value, either 32 or 64 bits. 292 *
307 * Note: String must be valid and non-null. 293 * interpreter - Runtime ASL to_integer operator, as per the ACPI specification
308 * 294 *
309 ******************************************************************************/ 295 ******************************************************************************/
310 296
311static u64 acpi_ut_strtoul_base16(char *string, u32 flags) 297u64 acpi_ut_explicit_strtoul64(char *string)
312{ 298{
313 int ascii_digit; 299 u64 converted_integer = 0;
314 u32 valid_digits = 1; 300 u32 base = 10; /* Default is decimal */
315 u64 return_value = 0;
316
317 /* Main loop: convert each ASCII byte in the input string */
318
319 while (*string) {
320
321 /* Check for overflow (32 or 64 bit) - return current converted value */
322
323 if ((valid_digits > 16) ||
324 ((valid_digits > 8) && (flags & ACPI_STRTOUL_32BIT))) {
325 goto exit;
326 }
327
328 ascii_digit = *string;
329 if (!isxdigit(ascii_digit)) {
330
331 /* Not Hex ASCII A-F, a-f, or 0-9, terminate */
332 301
333 goto exit; 302 ACPI_FUNCTION_TRACE_STR(ut_explicit_strtoul64, string);
334 }
335 303
336 /* Convert and insert the hex digit */ 304 /*
305 * Only Hex and Decimal are supported, as per the ACPI specification.
306 * 0x prefix means hex; otherwise decimal is assumed.
307 */
308 if (acpi_ut_detect_hex_prefix(&string)) {
309 base = 16;
310 }
337 311
338 acpi_ut_short_shift_left(return_value, 4, &return_value); 312 if (!acpi_ut_remove_leading_zeros(&string)) {
339 return_value |= acpi_ut_ascii_char_to_hex(ascii_digit); 313 return_VALUE(0);
314 }
340 315
341 string++; 316 /*
342 valid_digits++; 317 * Ignore overflow as per the ACPI specification. This is implemented by
318 * ignoring the return status below. On overflow, the input string is
319 * simply truncated.
320 */
321 switch (base) {
322 case 10:
323 default:
324 acpi_ut_convert_decimal_string(string, &converted_integer);
325 break;
326
327 case 16:
328 acpi_ut_convert_hex_string(string, &converted_integer);
329 break;
343 } 330 }
344 331
345exit: 332 return_VALUE(converted_integer);
346 return (return_value);
347} 333}
diff --git a/include/acpi/acexcep.h b/include/acpi/acexcep.h
index ad54610ea6cd..17d61b1f2511 100644
--- a/include/acpi/acexcep.h
+++ b/include/acpi/acexcep.h
@@ -126,8 +126,12 @@ struct acpi_exception_info {
126#define AE_NOT_CONFIGURED EXCEP_ENV (0x001C) 126#define AE_NOT_CONFIGURED EXCEP_ENV (0x001C)
127#define AE_ACCESS EXCEP_ENV (0x001D) 127#define AE_ACCESS EXCEP_ENV (0x001D)
128#define AE_IO_ERROR EXCEP_ENV (0x001E) 128#define AE_IO_ERROR EXCEP_ENV (0x001E)
129#define AE_NUMERIC_OVERFLOW EXCEP_ENV (0x001F)
130#define AE_HEX_OVERFLOW EXCEP_ENV (0x0020)
131#define AE_DECIMAL_OVERFLOW EXCEP_ENV (0x0021)
132#define AE_OCTAL_OVERFLOW EXCEP_ENV (0x0022)
129 133
130#define AE_CODE_ENV_MAX 0x001E 134#define AE_CODE_ENV_MAX 0x0022
131 135
132/* 136/*
133 * Programmer exceptions 137 * Programmer exceptions
@@ -263,7 +267,15 @@ static const struct acpi_exception_info acpi_gbl_exception_names_env[] = {
263 EXCEP_TXT("AE_NOT_CONFIGURED", 267 EXCEP_TXT("AE_NOT_CONFIGURED",
264 "The interface is not part of the current subsystem configuration"), 268 "The interface is not part of the current subsystem configuration"),
265 EXCEP_TXT("AE_ACCESS", "Permission denied for the requested operation"), 269 EXCEP_TXT("AE_ACCESS", "Permission denied for the requested operation"),
266 EXCEP_TXT("AE_IO_ERROR", "An I/O error occurred") 270 EXCEP_TXT("AE_IO_ERROR", "An I/O error occurred"),
271 EXCEP_TXT("AE_NUMERIC_OVERFLOW",
272 "Overflow during string-to-integer conversion"),
273 EXCEP_TXT("AE_HEX_OVERFLOW",
274 "Overflow during ASCII hex-to-binary conversion"),
275 EXCEP_TXT("AE_DECIMAL_OVERFLOW",
276 "Overflow during ASCII decimal-to-binary conversion"),
277 EXCEP_TXT("AE_OCTAL_OVERFLOW",
278 "Overflow during ASCII octal-to-binary conversion")
267}; 279};
268 280
269static const struct acpi_exception_info acpi_gbl_exception_names_pgm[] = { 281static const struct acpi_exception_info acpi_gbl_exception_names_pgm[] = {
diff --git a/tools/power/acpi/tools/acpidump/Makefile b/tools/power/acpi/tools/acpidump/Makefile
index f7c7af1f9258..b436f8675f6a 100644
--- a/tools/power/acpi/tools/acpidump/Makefile
+++ b/tools/power/acpi/tools/acpidump/Makefile
@@ -39,6 +39,7 @@ TOOL_OBJS = \
39 utnonansi.o\ 39 utnonansi.o\
40 utprint.o\ 40 utprint.o\
41 utstring.o\ 41 utstring.o\
42 utstrsuppt.o\
42 utstrtoul64.o\ 43 utstrtoul64.o\
43 utxferror.o\ 44 utxferror.o\
44 oslinuxtbl.o\ 45 oslinuxtbl.o\
diff --git a/tools/power/acpi/tools/acpidump/apdump.c b/tools/power/acpi/tools/acpidump/apdump.c
index 60df1fbd4a77..0634449156d8 100644
--- a/tools/power/acpi/tools/acpidump/apdump.c
+++ b/tools/power/acpi/tools/acpidump/apdump.c
@@ -287,8 +287,7 @@ int ap_dump_table_by_address(char *ascii_address)
287 287
288 /* Convert argument to an integer physical address */ 288 /* Convert argument to an integer physical address */
289 289
290 status = acpi_ut_strtoul64(ascii_address, ACPI_STRTOUL_64BIT, 290 status = acpi_ut_strtoul64(ascii_address, &long_address);
291 &long_address);
292 if (ACPI_FAILURE(status)) { 291 if (ACPI_FAILURE(status)) {
293 fprintf(stderr, "%s: Could not convert to a physical address\n", 292 fprintf(stderr, "%s: Could not convert to a physical address\n",
294 ascii_address); 293 ascii_address);
diff --git a/tools/power/acpi/tools/acpidump/apmain.c b/tools/power/acpi/tools/acpidump/apmain.c
index 943b6b614683..22c3b4ee1617 100644
--- a/tools/power/acpi/tools/acpidump/apmain.c
+++ b/tools/power/acpi/tools/acpidump/apmain.c
@@ -208,9 +208,7 @@ static int ap_do_options(int argc, char **argv)
208 case 'r': /* Dump tables from specified RSDP */ 208 case 'r': /* Dump tables from specified RSDP */
209 209
210 status = 210 status =
211 acpi_ut_strtoul64(acpi_gbl_optarg, 211 acpi_ut_strtoul64(acpi_gbl_optarg, &gbl_rsdp_base);
212 ACPI_STRTOUL_64BIT,
213 &gbl_rsdp_base);
214 if (ACPI_FAILURE(status)) { 212 if (ACPI_FAILURE(status)) {
215 fprintf(stderr, 213 fprintf(stderr,
216 "%s: Could not convert to a physical address\n", 214 "%s: Could not convert to a physical address\n",