1fe97d287SBob Moore /******************************************************************************* 2fe97d287SBob Moore * 372a29355SBob Moore * Module Name: utstrsuppt - Support functions for string-to-integer conversion 4fe97d287SBob Moore * 5fe97d287SBob Moore ******************************************************************************/ 6fe97d287SBob Moore 7fe97d287SBob Moore /* 8fe97d287SBob Moore * Copyright (C) 2000 - 2017, Intel Corp. 9fe97d287SBob Moore * All rights reserved. 10fe97d287SBob Moore * 11fe97d287SBob Moore * Redistribution and use in source and binary forms, with or without 12fe97d287SBob Moore * modification, are permitted provided that the following conditions 13fe97d287SBob Moore * are met: 14fe97d287SBob Moore * 1. Redistributions of source code must retain the above copyright 15fe97d287SBob Moore * notice, this list of conditions, and the following disclaimer, 16fe97d287SBob Moore * without modification. 17fe97d287SBob Moore * 2. Redistributions in binary form must reproduce at minimum a disclaimer 18fe97d287SBob Moore * substantially similar to the "NO WARRANTY" disclaimer below 19fe97d287SBob Moore * ("Disclaimer") and any redistribution must be conditioned upon 20fe97d287SBob Moore * including a substantially similar Disclaimer requirement for further 21fe97d287SBob Moore * binary redistribution. 22fe97d287SBob Moore * 3. Neither the names of the above-listed copyright holders nor the names 23fe97d287SBob Moore * of any contributors may be used to endorse or promote products derived 24fe97d287SBob Moore * from this software without specific prior written permission. 25fe97d287SBob Moore * 26fe97d287SBob Moore * Alternatively, this software may be distributed under the terms of the 27fe97d287SBob Moore * GNU General Public License ("GPL") version 2 as published by the Free 28fe97d287SBob Moore * Software Foundation. 29fe97d287SBob Moore * 30fe97d287SBob Moore * NO WARRANTY 31fe97d287SBob Moore * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 32fe97d287SBob Moore * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 33fe97d287SBob Moore * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR 34fe97d287SBob Moore * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 35fe97d287SBob Moore * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 36fe97d287SBob Moore * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 37fe97d287SBob Moore * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 38fe97d287SBob Moore * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 39fe97d287SBob Moore * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 40fe97d287SBob Moore * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 41fe97d287SBob Moore * POSSIBILITY OF SUCH DAMAGES. 42fe97d287SBob Moore */ 43fe97d287SBob Moore 44fe97d287SBob Moore #include <acpi/acpi.h> 45fe97d287SBob Moore #include "accommon.h" 46fe97d287SBob Moore 47fe97d287SBob Moore #define _COMPONENT ACPI_UTILITIES 48fe97d287SBob Moore ACPI_MODULE_NAME("utstrsuppt") 49fe97d287SBob Moore 50fe97d287SBob Moore /* Local prototypes */ 51fe97d287SBob Moore static acpi_status 52fe97d287SBob Moore acpi_ut_insert_digit(u64 *accumulated_value, u32 base, int ascii_digit); 53fe97d287SBob Moore 54fe97d287SBob Moore static acpi_status 55db53f7f0SBob Moore acpi_ut_strtoul_multiply64(u64 multiplicand, u32 base, u64 *out_product); 56fe97d287SBob Moore 57db53f7f0SBob Moore static acpi_status acpi_ut_strtoul_add64(u64 addend1, u32 digit, u64 *out_sum); 58fe97d287SBob Moore 59fe97d287SBob Moore /******************************************************************************* 60fe97d287SBob Moore * 61fe97d287SBob Moore * FUNCTION: acpi_ut_convert_octal_string 62fe97d287SBob Moore * 63fe97d287SBob Moore * PARAMETERS: string - Null terminated input string 64fe97d287SBob Moore * return_value_ptr - Where the converted value is returned 65fe97d287SBob Moore * 66fe97d287SBob Moore * RETURN: Status and 64-bit converted integer 67fe97d287SBob Moore * 68fe97d287SBob Moore * DESCRIPTION: Performs a base 8 conversion of the input string to an 69fe97d287SBob Moore * integer value, either 32 or 64 bits. 70fe97d287SBob Moore * 71fe97d287SBob Moore * NOTE: Maximum 64-bit unsigned octal value is 01777777777777777777777 72fe97d287SBob Moore * Maximum 32-bit unsigned octal value is 037777777777 73fe97d287SBob Moore * 74fe97d287SBob Moore ******************************************************************************/ 75fe97d287SBob Moore 76fe97d287SBob Moore acpi_status acpi_ut_convert_octal_string(char *string, u64 *return_value_ptr) 77fe97d287SBob Moore { 78fe97d287SBob Moore u64 accumulated_value = 0; 79fe97d287SBob Moore acpi_status status = AE_OK; 80fe97d287SBob Moore 81fe97d287SBob Moore /* Convert each ASCII byte in the input string */ 82fe97d287SBob Moore 83fe97d287SBob Moore while (*string) { 84fe97d287SBob Moore 8572a29355SBob Moore /* Character must be ASCII 0-7, otherwise terminate with no error */ 86fe97d287SBob Moore 87fe97d287SBob Moore if (!(ACPI_IS_OCTAL_DIGIT(*string))) { 88fe97d287SBob Moore break; 89fe97d287SBob Moore } 90fe97d287SBob Moore 91fe97d287SBob Moore /* Convert and insert this octal digit into the accumulator */ 92fe97d287SBob Moore 93fe97d287SBob Moore status = acpi_ut_insert_digit(&accumulated_value, 8, *string); 94fe97d287SBob Moore if (ACPI_FAILURE(status)) { 95fe97d287SBob Moore status = AE_OCTAL_OVERFLOW; 96fe97d287SBob Moore break; 97fe97d287SBob Moore } 98fe97d287SBob Moore 99fe97d287SBob Moore string++; 100fe97d287SBob Moore } 101fe97d287SBob Moore 102fe97d287SBob Moore /* Always return the value that has been accumulated */ 103fe97d287SBob Moore 104fe97d287SBob Moore *return_value_ptr = accumulated_value; 105fe97d287SBob Moore return (status); 106fe97d287SBob Moore } 107fe97d287SBob Moore 108fe97d287SBob Moore /******************************************************************************* 109fe97d287SBob Moore * 110fe97d287SBob Moore * FUNCTION: acpi_ut_convert_decimal_string 111fe97d287SBob Moore * 112fe97d287SBob Moore * PARAMETERS: string - Null terminated input string 113fe97d287SBob Moore * return_value_ptr - Where the converted value is returned 114fe97d287SBob Moore * 115fe97d287SBob Moore * RETURN: Status and 64-bit converted integer 116fe97d287SBob Moore * 117fe97d287SBob Moore * DESCRIPTION: Performs a base 10 conversion of the input string to an 118fe97d287SBob Moore * integer value, either 32 or 64 bits. 119fe97d287SBob Moore * 120fe97d287SBob Moore * NOTE: Maximum 64-bit unsigned decimal value is 18446744073709551615 121fe97d287SBob Moore * Maximum 32-bit unsigned decimal value is 4294967295 122fe97d287SBob Moore * 123fe97d287SBob Moore ******************************************************************************/ 124fe97d287SBob Moore 125fe97d287SBob Moore acpi_status acpi_ut_convert_decimal_string(char *string, u64 *return_value_ptr) 126fe97d287SBob Moore { 127fe97d287SBob Moore u64 accumulated_value = 0; 128fe97d287SBob Moore acpi_status status = AE_OK; 129fe97d287SBob Moore 130fe97d287SBob Moore /* Convert each ASCII byte in the input string */ 131fe97d287SBob Moore 132fe97d287SBob Moore while (*string) { 133fe97d287SBob Moore 13472a29355SBob Moore /* Character must be ASCII 0-9, otherwise terminate with no error */ 135fe97d287SBob Moore 136fe97d287SBob Moore if (!isdigit(*string)) { 137fe97d287SBob Moore break; 138fe97d287SBob Moore } 139fe97d287SBob Moore 140fe97d287SBob Moore /* Convert and insert this decimal digit into the accumulator */ 141fe97d287SBob Moore 142fe97d287SBob Moore status = acpi_ut_insert_digit(&accumulated_value, 10, *string); 143fe97d287SBob Moore if (ACPI_FAILURE(status)) { 144fe97d287SBob Moore status = AE_DECIMAL_OVERFLOW; 145fe97d287SBob Moore break; 146fe97d287SBob Moore } 147fe97d287SBob Moore 148fe97d287SBob Moore string++; 149fe97d287SBob Moore } 150fe97d287SBob Moore 151fe97d287SBob Moore /* Always return the value that has been accumulated */ 152fe97d287SBob Moore 153fe97d287SBob Moore *return_value_ptr = accumulated_value; 154fe97d287SBob Moore return (status); 155fe97d287SBob Moore } 156fe97d287SBob Moore 157fe97d287SBob Moore /******************************************************************************* 158fe97d287SBob Moore * 159fe97d287SBob Moore * FUNCTION: acpi_ut_convert_hex_string 160fe97d287SBob Moore * 161fe97d287SBob Moore * PARAMETERS: string - Null terminated input string 162fe97d287SBob Moore * return_value_ptr - Where the converted value is returned 163fe97d287SBob Moore * 164fe97d287SBob Moore * RETURN: Status and 64-bit converted integer 165fe97d287SBob Moore * 166fe97d287SBob Moore * DESCRIPTION: Performs a base 16 conversion of the input string to an 167fe97d287SBob Moore * integer value, either 32 or 64 bits. 168fe97d287SBob Moore * 169fe97d287SBob Moore * NOTE: Maximum 64-bit unsigned hex value is 0xFFFFFFFFFFFFFFFF 170fe97d287SBob Moore * Maximum 32-bit unsigned hex value is 0xFFFFFFFF 171fe97d287SBob Moore * 172fe97d287SBob Moore ******************************************************************************/ 173fe97d287SBob Moore 174fe97d287SBob Moore acpi_status acpi_ut_convert_hex_string(char *string, u64 *return_value_ptr) 175fe97d287SBob Moore { 176fe97d287SBob Moore u64 accumulated_value = 0; 177fe97d287SBob Moore acpi_status status = AE_OK; 178fe97d287SBob Moore 179fe97d287SBob Moore /* Convert each ASCII byte in the input string */ 180fe97d287SBob Moore 181fe97d287SBob Moore while (*string) { 182fe97d287SBob Moore 183fe97d287SBob Moore /* Must be ASCII A-F, a-f, or 0-9, otherwise terminate with no error */ 184fe97d287SBob Moore 185fe97d287SBob Moore if (!isxdigit(*string)) { 186fe97d287SBob Moore break; 187fe97d287SBob Moore } 188fe97d287SBob Moore 189fe97d287SBob Moore /* Convert and insert this hex digit into the accumulator */ 190fe97d287SBob Moore 191fe97d287SBob Moore status = acpi_ut_insert_digit(&accumulated_value, 16, *string); 192fe97d287SBob Moore if (ACPI_FAILURE(status)) { 193fe97d287SBob Moore status = AE_HEX_OVERFLOW; 194fe97d287SBob Moore break; 195fe97d287SBob Moore } 196fe97d287SBob Moore 197fe97d287SBob Moore string++; 198fe97d287SBob Moore } 199fe97d287SBob Moore 200fe97d287SBob Moore /* Always return the value that has been accumulated */ 201fe97d287SBob Moore 202fe97d287SBob Moore *return_value_ptr = accumulated_value; 203fe97d287SBob Moore return (status); 204fe97d287SBob Moore } 205fe97d287SBob Moore 206fe97d287SBob Moore /******************************************************************************* 207fe97d287SBob Moore * 208fe97d287SBob Moore * FUNCTION: acpi_ut_remove_leading_zeros 209fe97d287SBob Moore * 210fe97d287SBob Moore * PARAMETERS: string - Pointer to input ASCII string 211fe97d287SBob Moore * 21272a29355SBob Moore * RETURN: Next character after any leading zeros. This character may be 21372a29355SBob Moore * used by the caller to detect end-of-string. 214fe97d287SBob Moore * 21572a29355SBob Moore * DESCRIPTION: Remove any leading zeros in the input string. Return the 21672a29355SBob Moore * next character after the final ASCII zero to enable the caller 21772a29355SBob Moore * to check for the end of the string (NULL terminator). 218fe97d287SBob Moore * 219fe97d287SBob Moore ******************************************************************************/ 220fe97d287SBob Moore 221fe97d287SBob Moore char acpi_ut_remove_leading_zeros(char **string) 222fe97d287SBob Moore { 223fe97d287SBob Moore 224fe97d287SBob Moore while (**string == ACPI_ASCII_ZERO) { 225fe97d287SBob Moore *string += 1; 226fe97d287SBob Moore } 227fe97d287SBob Moore 228fe97d287SBob Moore return (**string); 229fe97d287SBob Moore } 230fe97d287SBob Moore 231fe97d287SBob Moore /******************************************************************************* 232fe97d287SBob Moore * 233c2e56e54SBob Moore * FUNCTION: acpi_ut_remove_whitespace 234c2e56e54SBob Moore * 235c2e56e54SBob Moore * PARAMETERS: string - Pointer to input ASCII string 236c2e56e54SBob Moore * 237c2e56e54SBob Moore * RETURN: Next character after any whitespace. This character may be 238c2e56e54SBob Moore * used by the caller to detect end-of-string. 239c2e56e54SBob Moore * 240c2e56e54SBob Moore * DESCRIPTION: Remove any leading whitespace in the input string. Return the 241c2e56e54SBob Moore * next character after the final ASCII zero to enable the caller 242c2e56e54SBob Moore * to check for the end of the string (NULL terminator). 243c2e56e54SBob Moore * 244c2e56e54SBob Moore ******************************************************************************/ 245c2e56e54SBob Moore 246c2e56e54SBob Moore char acpi_ut_remove_whitespace(char **string) 247c2e56e54SBob Moore { 248c2e56e54SBob Moore 249c2e56e54SBob Moore while (isspace((u8)**string)) { 250c2e56e54SBob Moore *string += 1; 251c2e56e54SBob Moore } 252c2e56e54SBob Moore 253c2e56e54SBob Moore return (**string); 254c2e56e54SBob Moore } 255c2e56e54SBob Moore 256c2e56e54SBob Moore /******************************************************************************* 257c2e56e54SBob Moore * 258fe97d287SBob Moore * FUNCTION: acpi_ut_detect_hex_prefix 259fe97d287SBob Moore * 260fe97d287SBob Moore * PARAMETERS: string - Pointer to input ASCII string 261fe97d287SBob Moore * 26272a29355SBob Moore * RETURN: TRUE if a "0x" prefix was found at the start of the string 263fe97d287SBob Moore * 26472a29355SBob Moore * DESCRIPTION: Detect and remove a hex "0x" prefix 265fe97d287SBob Moore * 266fe97d287SBob Moore ******************************************************************************/ 267fe97d287SBob Moore 268fe97d287SBob Moore u8 acpi_ut_detect_hex_prefix(char **string) 269fe97d287SBob Moore { 270fe97d287SBob Moore 271fe97d287SBob Moore if ((**string == ACPI_ASCII_ZERO) && 272fe97d287SBob Moore (tolower((int)*(*string + 1)) == 'x')) { 273fe97d287SBob Moore *string += 2; /* Go past the leading 0x */ 274fe97d287SBob Moore return (TRUE); 275fe97d287SBob Moore } 276fe97d287SBob Moore 277fe97d287SBob Moore return (FALSE); /* Not a hex string */ 278fe97d287SBob Moore } 279fe97d287SBob Moore 280fe97d287SBob Moore /******************************************************************************* 281fe97d287SBob Moore * 282fe97d287SBob Moore * FUNCTION: acpi_ut_detect_octal_prefix 283fe97d287SBob Moore * 284fe97d287SBob Moore * PARAMETERS: string - Pointer to input ASCII string 285fe97d287SBob Moore * 28672a29355SBob Moore * RETURN: True if an octal "0" prefix was found at the start of the 28772a29355SBob Moore * string 288fe97d287SBob Moore * 289fe97d287SBob Moore * DESCRIPTION: Detect and remove an octal prefix (zero) 290fe97d287SBob Moore * 291fe97d287SBob Moore ******************************************************************************/ 292fe97d287SBob Moore 293fe97d287SBob Moore u8 acpi_ut_detect_octal_prefix(char **string) 294fe97d287SBob Moore { 295fe97d287SBob Moore 296fe97d287SBob Moore if (**string == ACPI_ASCII_ZERO) { 297fe97d287SBob Moore *string += 1; /* Go past the leading 0 */ 298fe97d287SBob Moore return (TRUE); 299fe97d287SBob Moore } 300fe97d287SBob Moore 301fe97d287SBob Moore return (FALSE); /* Not an octal string */ 302fe97d287SBob Moore } 303fe97d287SBob Moore 304fe97d287SBob Moore /******************************************************************************* 305fe97d287SBob Moore * 306fe97d287SBob Moore * FUNCTION: acpi_ut_insert_digit 307fe97d287SBob Moore * 308fe97d287SBob Moore * PARAMETERS: accumulated_value - Current value of the integer value 30972a29355SBob Moore * accumulator. The new value is 310fe97d287SBob Moore * returned here. 31172a29355SBob Moore * base - Radix, either 8/10/16 312fe97d287SBob Moore * ascii_digit - ASCII single digit to be inserted 313fe97d287SBob Moore * 31472a29355SBob Moore * RETURN: Status and result of the convert/insert operation. The only 31572a29355SBob Moore * possible returned exception code is numeric overflow of 31672a29355SBob Moore * either the multiply or add conversion operations. 317fe97d287SBob Moore * 318fe97d287SBob Moore * DESCRIPTION: Generic conversion and insertion function for all bases: 319fe97d287SBob Moore * 32072a29355SBob Moore * 1) Multiply the current accumulated/converted value by the 321fe97d287SBob Moore * base in order to make room for the new character. 322fe97d287SBob Moore * 32372a29355SBob Moore * 2) Convert the new character to binary and add it to the 32472a29355SBob Moore * current accumulated value. 325fe97d287SBob Moore * 326fe97d287SBob Moore * Note: The only possible exception indicates an integer 327fe97d287SBob Moore * overflow (AE_NUMERIC_OVERFLOW) 328fe97d287SBob Moore * 329fe97d287SBob Moore ******************************************************************************/ 330fe97d287SBob Moore 331fe97d287SBob Moore static acpi_status 332fe97d287SBob Moore acpi_ut_insert_digit(u64 *accumulated_value, u32 base, int ascii_digit) 333fe97d287SBob Moore { 334fe97d287SBob Moore acpi_status status; 335fe97d287SBob Moore u64 product; 336fe97d287SBob Moore 337fe97d287SBob Moore /* Make room in the accumulated value for the incoming digit */ 338fe97d287SBob Moore 339fe97d287SBob Moore status = acpi_ut_strtoul_multiply64(*accumulated_value, base, &product); 340fe97d287SBob Moore if (ACPI_FAILURE(status)) { 341fe97d287SBob Moore return (status); 342fe97d287SBob Moore } 343fe97d287SBob Moore 34472a29355SBob Moore /* Add in the new digit, and store the sum to the accumulated value */ 345fe97d287SBob Moore 346fe97d287SBob Moore status = 347fe97d287SBob Moore acpi_ut_strtoul_add64(product, 348fe97d287SBob Moore acpi_ut_ascii_char_to_hex(ascii_digit), 349fe97d287SBob Moore accumulated_value); 350fe97d287SBob Moore 35172a29355SBob Moore return (status); 352fe97d287SBob Moore } 353fe97d287SBob Moore 354fe97d287SBob Moore /******************************************************************************* 355fe97d287SBob Moore * 356fe97d287SBob Moore * FUNCTION: acpi_ut_strtoul_multiply64 357fe97d287SBob Moore * 358fe97d287SBob Moore * PARAMETERS: multiplicand - Current accumulated converted integer 359db53f7f0SBob Moore * base - Base/Radix 360fe97d287SBob Moore * out_product - Where the product is returned 361fe97d287SBob Moore * 362fe97d287SBob Moore * RETURN: Status and 64-bit product 363fe97d287SBob Moore * 364fe97d287SBob Moore * DESCRIPTION: Multiply two 64-bit values, with checking for 64-bit overflow as 365fe97d287SBob Moore * well as 32-bit overflow if necessary (if the current global 366fe97d287SBob Moore * integer width is 32). 367fe97d287SBob Moore * 368fe97d287SBob Moore ******************************************************************************/ 369fe97d287SBob Moore 370fe97d287SBob Moore static acpi_status 371db53f7f0SBob Moore acpi_ut_strtoul_multiply64(u64 multiplicand, u32 base, u64 *out_product) 372fe97d287SBob Moore { 373fe97d287SBob Moore u64 val; 374db53f7f0SBob Moore u64 quotient; 375fe97d287SBob Moore 376fe97d287SBob Moore /* Exit if either operand is zero */ 377fe97d287SBob Moore 378fe97d287SBob Moore *out_product = 0; 379db53f7f0SBob Moore if (!multiplicand || !base) { 380fe97d287SBob Moore return (AE_OK); 381fe97d287SBob Moore } 382fe97d287SBob Moore 383db53f7f0SBob Moore /* 384db53f7f0SBob Moore * Check for 64-bit overflow before the actual multiplication. 385db53f7f0SBob Moore * 386db53f7f0SBob Moore * Notes: 64-bit division is often not supported on 32-bit platforms 387db53f7f0SBob Moore * (it requires a library function), Therefore ACPICA has a local 388db53f7f0SBob Moore * 64-bit divide function. Also, Multiplier is currently only used 389db53f7f0SBob Moore * as the radix (8/10/16), to the 64/32 divide will always work. 390db53f7f0SBob Moore */ 391db53f7f0SBob Moore acpi_ut_short_divide(ACPI_UINT64_MAX, base, "ient, NULL); 392db53f7f0SBob Moore if (multiplicand > quotient) { 393fe97d287SBob Moore return (AE_NUMERIC_OVERFLOW); 394fe97d287SBob Moore } 395fe97d287SBob Moore 396db53f7f0SBob Moore val = multiplicand * base; 397fe97d287SBob Moore 398fe97d287SBob Moore /* Check for 32-bit overflow if necessary */ 399fe97d287SBob Moore 400fe97d287SBob Moore if ((acpi_gbl_integer_bit_width == 32) && (val > ACPI_UINT32_MAX)) { 401fe97d287SBob Moore return (AE_NUMERIC_OVERFLOW); 402fe97d287SBob Moore } 403fe97d287SBob Moore 404fe97d287SBob Moore *out_product = val; 405fe97d287SBob Moore return (AE_OK); 406fe97d287SBob Moore } 407fe97d287SBob Moore 408fe97d287SBob Moore /******************************************************************************* 409fe97d287SBob Moore * 410fe97d287SBob Moore * FUNCTION: acpi_ut_strtoul_add64 411fe97d287SBob Moore * 412fe97d287SBob Moore * PARAMETERS: addend1 - Current accumulated converted integer 413db53f7f0SBob Moore * digit - New hex value/char 414fe97d287SBob Moore * out_sum - Where sum is returned (Accumulator) 415fe97d287SBob Moore * 416fe97d287SBob Moore * RETURN: Status and 64-bit sum 417fe97d287SBob Moore * 418fe97d287SBob Moore * DESCRIPTION: Add two 64-bit values, with checking for 64-bit overflow as 419fe97d287SBob Moore * well as 32-bit overflow if necessary (if the current global 420fe97d287SBob Moore * integer width is 32). 421fe97d287SBob Moore * 422fe97d287SBob Moore ******************************************************************************/ 423fe97d287SBob Moore 424db53f7f0SBob Moore static acpi_status acpi_ut_strtoul_add64(u64 addend1, u32 digit, u64 *out_sum) 425fe97d287SBob Moore { 426fe97d287SBob Moore u64 sum; 427fe97d287SBob Moore 428fe97d287SBob Moore /* Check for 64-bit overflow before the actual addition */ 429fe97d287SBob Moore 430db53f7f0SBob Moore if ((addend1 > 0) && (digit > (ACPI_UINT64_MAX - addend1))) { 431fe97d287SBob Moore return (AE_NUMERIC_OVERFLOW); 432fe97d287SBob Moore } 433fe97d287SBob Moore 434db53f7f0SBob Moore sum = addend1 + digit; 435fe97d287SBob Moore 436fe97d287SBob Moore /* Check for 32-bit overflow if necessary */ 437fe97d287SBob Moore 438fe97d287SBob Moore if ((acpi_gbl_integer_bit_width == 32) && (sum > ACPI_UINT32_MAX)) { 439fe97d287SBob Moore return (AE_NUMERIC_OVERFLOW); 440fe97d287SBob Moore } 441fe97d287SBob Moore 442fe97d287SBob Moore *out_sum = sum; 443fe97d287SBob Moore return (AE_OK); 444fe97d287SBob Moore } 445