// SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 /******************************************************************************* * * Module Name: utstrsuppt - Support functions for string-to-integer conversion * ******************************************************************************/ #include <acpi/acpi.h> #include "accommon.h" #define _COMPONENT … ACPI_MODULE_NAME("utstrsuppt") /* Local prototypes */ static acpi_status acpi_ut_insert_digit(u64 *accumulated_value, u32 base, int ascii_digit); static acpi_status acpi_ut_strtoul_multiply64(u64 multiplicand, u32 base, u64 *out_product); static acpi_status acpi_ut_strtoul_add64(u64 addend1, u32 digit, u64 *out_sum); /******************************************************************************* * * FUNCTION: acpi_ut_convert_octal_string * * PARAMETERS: string - Null terminated input string * return_value_ptr - Where the converted value is returned * * RETURN: Status and 64-bit converted integer * * DESCRIPTION: Performs a base 8 conversion of the input string to an * integer value, either 32 or 64 bits. * * NOTE: Maximum 64-bit unsigned octal value is 01777777777777777777777 * Maximum 32-bit unsigned octal value is 037777777777 * ******************************************************************************/ acpi_status acpi_ut_convert_octal_string(char *string, u64 *return_value_ptr) { … } /******************************************************************************* * * FUNCTION: acpi_ut_convert_decimal_string * * PARAMETERS: string - Null terminated input string * return_value_ptr - Where the converted value is returned * * RETURN: Status and 64-bit converted integer * * DESCRIPTION: Performs a base 10 conversion of the input string to an * integer value, either 32 or 64 bits. * * NOTE: Maximum 64-bit unsigned decimal value is 18446744073709551615 * Maximum 32-bit unsigned decimal value is 4294967295 * ******************************************************************************/ acpi_status acpi_ut_convert_decimal_string(char *string, u64 *return_value_ptr) { … } /******************************************************************************* * * FUNCTION: acpi_ut_convert_hex_string * * PARAMETERS: string - Null terminated input string * return_value_ptr - Where the converted value is returned * * RETURN: Status and 64-bit converted integer * * DESCRIPTION: Performs a base 16 conversion of the input string to an * integer value, either 32 or 64 bits. * * NOTE: Maximum 64-bit unsigned hex value is 0xFFFFFFFFFFFFFFFF * Maximum 32-bit unsigned hex value is 0xFFFFFFFF * ******************************************************************************/ acpi_status acpi_ut_convert_hex_string(char *string, u64 *return_value_ptr) { … } /******************************************************************************* * * FUNCTION: acpi_ut_remove_leading_zeros * * PARAMETERS: string - Pointer to input ASCII string * * RETURN: Next character after any leading zeros. This character may be * used by the caller to detect end-of-string. * * DESCRIPTION: Remove any leading zeros in the input string. Return the * next character after the final ASCII zero to enable the caller * to check for the end of the string (NULL terminator). * ******************************************************************************/ char acpi_ut_remove_leading_zeros(char **string) { … } /******************************************************************************* * * FUNCTION: acpi_ut_remove_whitespace * * PARAMETERS: string - Pointer to input ASCII string * * RETURN: Next character after any whitespace. This character may be * used by the caller to detect end-of-string. * * DESCRIPTION: Remove any leading whitespace in the input string. Return the * next character after the final ASCII zero to enable the caller * to check for the end of the string (NULL terminator). * ******************************************************************************/ char acpi_ut_remove_whitespace(char **string) { … } /******************************************************************************* * * FUNCTION: acpi_ut_detect_hex_prefix * * PARAMETERS: string - Pointer to input ASCII string * * RETURN: TRUE if a "0x" prefix was found at the start of the string * * DESCRIPTION: Detect and remove a hex "0x" prefix * ******************************************************************************/ u8 acpi_ut_detect_hex_prefix(char **string) { … } /******************************************************************************* * * FUNCTION: acpi_ut_remove_hex_prefix * * PARAMETERS: string - Pointer to input ASCII string * * RETURN: none * * DESCRIPTION: Remove a hex "0x" prefix * ******************************************************************************/ void acpi_ut_remove_hex_prefix(char **string) { … } /******************************************************************************* * * FUNCTION: acpi_ut_detect_octal_prefix * * PARAMETERS: string - Pointer to input ASCII string * * RETURN: True if an octal "0" prefix was found at the start of the * string * * DESCRIPTION: Detect and remove an octal prefix (zero) * ******************************************************************************/ u8 acpi_ut_detect_octal_prefix(char **string) { … } /******************************************************************************* * * FUNCTION: acpi_ut_insert_digit * * PARAMETERS: accumulated_value - Current value of the integer value * accumulator. The new value is * returned here. * base - Radix, either 8/10/16 * ascii_digit - ASCII single digit to be inserted * * RETURN: Status and result of the convert/insert operation. The only * possible returned exception code is numeric overflow of * either the multiply or add conversion operations. * * DESCRIPTION: Generic conversion and insertion function for all bases: * * 1) Multiply the current accumulated/converted value by the * base in order to make room for the new character. * * 2) Convert the new character to binary and add it to the * current accumulated value. * * Note: The only possible exception indicates an integer * overflow (AE_NUMERIC_OVERFLOW) * ******************************************************************************/ static acpi_status acpi_ut_insert_digit(u64 *accumulated_value, u32 base, int ascii_digit) { … } /******************************************************************************* * * FUNCTION: acpi_ut_strtoul_multiply64 * * PARAMETERS: multiplicand - Current accumulated converted integer * base - Base/Radix * out_product - Where the product is returned * * RETURN: Status and 64-bit product * * DESCRIPTION: Multiply two 64-bit values, with checking for 64-bit overflow as * well as 32-bit overflow if necessary (if the current global * integer width is 32). * ******************************************************************************/ static acpi_status acpi_ut_strtoul_multiply64(u64 multiplicand, u32 base, u64 *out_product) { … } /******************************************************************************* * * FUNCTION: acpi_ut_strtoul_add64 * * PARAMETERS: addend1 - Current accumulated converted integer * digit - New hex value/char * out_sum - Where sum is returned (Accumulator) * * RETURN: Status and 64-bit sum * * DESCRIPTION: Add two 64-bit values, with checking for 64-bit overflow as * well as 32-bit overflow if necessary (if the current global * integer width is 32). * ******************************************************************************/ static acpi_status acpi_ut_strtoul_add64(u64 addend1, u32 digit, u64 *out_sum) { … }