diff options
author | Bob Moore <robert.moore@intel.com> | 2016-02-19 01:16:27 -0500 |
---|---|---|
committer | Rafael J. Wysocki <rafael.j.wysocki@intel.com> | 2016-02-24 08:14:47 -0500 |
commit | 50db3052dac6e5ff7a8eeaaea138a6aaab6e608e (patch) | |
tree | b8f2b88e623cc0a1a4bc8e38535d398e207b13f2 | |
parent | 27eb7485a77de8ff2bb942a6507e186bef4f191e (diff) |
ACPICA: iASL: Update to use internal acpi_ut_strtoul64 function
ACPICA commit e959584d23b520c53700e90282312d17b9603ed5
Was using a local Strtoul64, update to use the common acpi_ut_strtoul64
and remove the local Strtoul64.
Link: https://github.com/acpica/acpica/commit/e959584d
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/utnonansi.c | 244 |
1 files changed, 206 insertions, 38 deletions
diff --git a/drivers/acpi/acpica/utnonansi.c b/drivers/acpi/acpica/utnonansi.c index d1f4a47577c9..d5c3adf19bd0 100644 --- a/drivers/acpi/acpica/utnonansi.c +++ b/drivers/acpi/acpica/utnonansi.c | |||
@@ -140,6 +140,67 @@ int acpi_ut_stricmp(char *string1, char *string2) | |||
140 | return (c1 - c2); | 140 | return (c1 - c2); |
141 | } | 141 | } |
142 | 142 | ||
143 | #if defined (ACPI_DEBUGGER) || defined (ACPI_APPLICATION) | ||
144 | /******************************************************************************* | ||
145 | * | ||
146 | * FUNCTION: acpi_ut_safe_strcpy, acpi_ut_safe_strcat, acpi_ut_safe_strncat | ||
147 | * | ||
148 | * PARAMETERS: Adds a "DestSize" parameter to each of the standard string | ||
149 | * functions. This is the size of the Destination buffer. | ||
150 | * | ||
151 | * RETURN: TRUE if the operation would overflow the destination buffer. | ||
152 | * | ||
153 | * DESCRIPTION: Safe versions of standard Clib string functions. Ensure that | ||
154 | * the result of the operation will not overflow the output string | ||
155 | * buffer. | ||
156 | * | ||
157 | * NOTE: These functions are typically only helpful for processing | ||
158 | * user input and command lines. For most ACPICA code, the | ||
159 | * required buffer length is precisely calculated before buffer | ||
160 | * allocation, so the use of these functions is unnecessary. | ||
161 | * | ||
162 | ******************************************************************************/ | ||
163 | |||
164 | u8 acpi_ut_safe_strcpy(char *dest, acpi_size dest_size, char *source) | ||
165 | { | ||
166 | |||
167 | if (strlen(source) >= dest_size) { | ||
168 | return (TRUE); | ||
169 | } | ||
170 | |||
171 | strcpy(dest, source); | ||
172 | return (FALSE); | ||
173 | } | ||
174 | |||
175 | u8 acpi_ut_safe_strcat(char *dest, acpi_size dest_size, char *source) | ||
176 | { | ||
177 | |||
178 | if ((strlen(dest) + strlen(source)) >= dest_size) { | ||
179 | return (TRUE); | ||
180 | } | ||
181 | |||
182 | strcat(dest, source); | ||
183 | return (FALSE); | ||
184 | } | ||
185 | |||
186 | u8 | ||
187 | acpi_ut_safe_strncat(char *dest, | ||
188 | acpi_size dest_size, | ||
189 | char *source, acpi_size max_transfer_length) | ||
190 | { | ||
191 | acpi_size actual_transfer_length; | ||
192 | |||
193 | actual_transfer_length = ACPI_MIN(max_transfer_length, strlen(source)); | ||
194 | |||
195 | if ((strlen(dest) + actual_transfer_length) >= dest_size) { | ||
196 | return (TRUE); | ||
197 | } | ||
198 | |||
199 | strncat(dest, source, max_transfer_length); | ||
200 | return (FALSE); | ||
201 | } | ||
202 | #endif | ||
203 | |||
143 | /******************************************************************************* | 204 | /******************************************************************************* |
144 | * | 205 | * |
145 | * FUNCTION: acpi_ut_strtoul64 | 206 | * FUNCTION: acpi_ut_strtoul64 |
@@ -155,7 +216,15 @@ int acpi_ut_stricmp(char *string1, char *string2) | |||
155 | * 32-bit or 64-bit conversion, depending on the current mode | 216 | * 32-bit or 64-bit conversion, depending on the current mode |
156 | * of the interpreter. | 217 | * of the interpreter. |
157 | * | 218 | * |
158 | * NOTE: Does not support Octal strings, not needed. | 219 | * NOTES: acpi_gbl_integer_byte_width should be set to the proper width. |
220 | * For the core ACPICA code, this width depends on the DSDT | ||
221 | * version. For iASL, the default byte width is always 8. | ||
222 | * | ||
223 | * Does not support Octal strings, not needed at this time. | ||
224 | * | ||
225 | * There is an earlier version of the function after this one, | ||
226 | * below. It is slightly different than this one, and the two | ||
227 | * may eventually may need to be merged. (01/2016). | ||
159 | * | 228 | * |
160 | ******************************************************************************/ | 229 | ******************************************************************************/ |
161 | 230 | ||
@@ -318,63 +387,162 @@ error_exit: | |||
318 | } | 387 | } |
319 | } | 388 | } |
320 | 389 | ||
321 | #if defined (ACPI_DEBUGGER) || defined (ACPI_APPLICATION) | 390 | #ifdef _OBSOLETE_FUNCTIONS |
391 | /* TBD: use version in ACPICA main code base? */ | ||
392 | /* DONE: 01/2016 */ | ||
393 | |||
322 | /******************************************************************************* | 394 | /******************************************************************************* |
323 | * | 395 | * |
324 | * FUNCTION: acpi_ut_safe_strcpy, acpi_ut_safe_strcat, acpi_ut_safe_strncat | 396 | * FUNCTION: strtoul64 |
325 | * | 397 | * |
326 | * PARAMETERS: Adds a "DestSize" parameter to each of the standard string | 398 | * PARAMETERS: string - Null terminated string |
327 | * functions. This is the size of the Destination buffer. | 399 | * terminater - Where a pointer to the terminating byte |
400 | * is returned | ||
401 | * base - Radix of the string | ||
328 | * | 402 | * |
329 | * RETURN: TRUE if the operation would overflow the destination buffer. | 403 | * RETURN: Converted value |
330 | * | 404 | * |
331 | * DESCRIPTION: Safe versions of standard Clib string functions. Ensure that | 405 | * DESCRIPTION: Convert a string into an unsigned value. |
332 | * the result of the operation will not overflow the output string | ||
333 | * buffer. | ||
334 | * | ||
335 | * NOTE: These functions are typically only helpful for processing | ||
336 | * user input and command lines. For most ACPICA code, the | ||
337 | * required buffer length is precisely calculated before buffer | ||
338 | * allocation, so the use of these functions is unnecessary. | ||
339 | * | 406 | * |
340 | ******************************************************************************/ | 407 | ******************************************************************************/ |
341 | 408 | ||
342 | u8 acpi_ut_safe_strcpy(char *dest, acpi_size dest_size, char *source) | 409 | acpi_status strtoul64(char *string, u32 base, u64 *ret_integer) |
343 | { | 410 | { |
411 | u32 index; | ||
412 | u32 sign; | ||
413 | u64 return_value = 0; | ||
414 | acpi_status status = AE_OK; | ||
344 | 415 | ||
345 | if (strlen(source) >= dest_size) { | 416 | *ret_integer = 0; |
346 | return (TRUE); | 417 | |
418 | switch (base) { | ||
419 | case 0: | ||
420 | case 8: | ||
421 | case 10: | ||
422 | case 16: | ||
423 | |||
424 | break; | ||
425 | |||
426 | default: | ||
427 | /* | ||
428 | * The specified Base parameter is not in the domain of | ||
429 | * this function: | ||
430 | */ | ||
431 | return (AE_BAD_PARAMETER); | ||
347 | } | 432 | } |
348 | 433 | ||
349 | strcpy(dest, source); | 434 | /* Skip over any white space in the buffer: */ |
350 | return (FALSE); | ||
351 | } | ||
352 | 435 | ||
353 | u8 acpi_ut_safe_strcat(char *dest, acpi_size dest_size, char *source) | 436 | while (isspace((int)*string) || *string == '\t') { |
354 | { | 437 | ++string; |
438 | } | ||
355 | 439 | ||
356 | if ((strlen(dest) + strlen(source)) >= dest_size) { | 440 | /* |
357 | return (TRUE); | 441 | * The buffer may contain an optional plus or minus sign. |
442 | * If it does, then skip over it but remember what is was: | ||
443 | */ | ||
444 | if (*string == '-') { | ||
445 | sign = ACPI_SIGN_NEGATIVE; | ||
446 | ++string; | ||
447 | } else if (*string == '+') { | ||
448 | ++string; | ||
449 | sign = ACPI_SIGN_POSITIVE; | ||
450 | } else { | ||
451 | sign = ACPI_SIGN_POSITIVE; | ||
358 | } | 452 | } |
359 | 453 | ||
360 | strcat(dest, source); | 454 | /* |
361 | return (FALSE); | 455 | * If the input parameter Base is zero, then we need to |
362 | } | 456 | * determine if it is octal, decimal, or hexadecimal: |
457 | */ | ||
458 | if (base == 0) { | ||
459 | if (*string == '0') { | ||
460 | if (tolower((int)*(++string)) == 'x') { | ||
461 | base = 16; | ||
462 | ++string; | ||
463 | } else { | ||
464 | base = 8; | ||
465 | } | ||
466 | } else { | ||
467 | base = 10; | ||
468 | } | ||
469 | } | ||
363 | 470 | ||
364 | u8 | 471 | /* |
365 | acpi_ut_safe_strncat(char *dest, | 472 | * For octal and hexadecimal bases, skip over the leading |
366 | acpi_size dest_size, | 473 | * 0 or 0x, if they are present. |
367 | char *source, acpi_size max_transfer_length) | 474 | */ |
368 | { | 475 | if (base == 8 && *string == '0') { |
369 | acpi_size actual_transfer_length; | 476 | string++; |
477 | } | ||
370 | 478 | ||
371 | actual_transfer_length = ACPI_MIN(max_transfer_length, strlen(source)); | 479 | if (base == 16 && *string == '0' && tolower((int)*(++string)) == 'x') { |
480 | string++; | ||
481 | } | ||
372 | 482 | ||
373 | if ((strlen(dest) + actual_transfer_length) >= dest_size) { | 483 | /* Main loop: convert the string to an unsigned long */ |
374 | return (TRUE); | 484 | |
485 | while (*string) { | ||
486 | if (isdigit((int)*string)) { | ||
487 | index = ((u8)*string) - '0'; | ||
488 | } else { | ||
489 | index = (u8)toupper((int)*string); | ||
490 | if (isupper((int)index)) { | ||
491 | index = index - 'A' + 10; | ||
492 | } else { | ||
493 | goto error_exit; | ||
494 | } | ||
495 | } | ||
496 | |||
497 | if (index >= base) { | ||
498 | goto error_exit; | ||
499 | } | ||
500 | |||
501 | /* Check to see if value is out of range: */ | ||
502 | |||
503 | if (return_value > ((ACPI_UINT64_MAX - (u64)index) / (u64)base)) { | ||
504 | goto error_exit; | ||
505 | } else { | ||
506 | return_value *= base; | ||
507 | return_value += index; | ||
508 | } | ||
509 | |||
510 | ++string; | ||
375 | } | 511 | } |
376 | 512 | ||
377 | strncat(dest, source, max_transfer_length); | 513 | /* If a minus sign was present, then "the conversion is negated": */ |
378 | return (FALSE); | 514 | |
515 | if (sign == ACPI_SIGN_NEGATIVE) { | ||
516 | return_value = (ACPI_UINT32_MAX - return_value) + 1; | ||
517 | } | ||
518 | |||
519 | *ret_integer = return_value; | ||
520 | return (status); | ||
521 | |||
522 | error_exit: | ||
523 | switch (base) { | ||
524 | case 8: | ||
525 | |||
526 | status = AE_BAD_OCTAL_CONSTANT; | ||
527 | break; | ||
528 | |||
529 | case 10: | ||
530 | |||
531 | status = AE_BAD_DECIMAL_CONSTANT; | ||
532 | break; | ||
533 | |||
534 | case 16: | ||
535 | |||
536 | status = AE_BAD_HEX_CONSTANT; | ||
537 | break; | ||
538 | |||
539 | default: | ||
540 | |||
541 | /* Base validated above */ | ||
542 | |||
543 | break; | ||
544 | } | ||
545 | |||
546 | return (status); | ||
379 | } | 547 | } |
380 | #endif | 548 | #endif |