1 // SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
2 /******************************************************************************
4 * Module Name: utascii - Utility ascii functions
6 * Copyright (C) 2000 - 2019, Intel Corp.
8 *****************************************************************************/
10 #include <acpi/acpi.h>
13 /*******************************************************************************
15 * FUNCTION: acpi_ut_valid_nameseg
17 * PARAMETERS: name - The name or table signature to be examined.
18 * Four characters, does not have to be a
19 * NULL terminated string.
21 * RETURN: TRUE if signature is has 4 valid ACPI characters
23 * DESCRIPTION: Validate an ACPI table signature.
25 ******************************************************************************/
27 u8
acpi_ut_valid_nameseg(char *name
)
31 /* Validate each character in the signature */
33 for (i
= 0; i
< ACPI_NAME_SIZE
; i
++) {
34 if (!acpi_ut_valid_name_char(name
[i
], i
)) {
42 /*******************************************************************************
44 * FUNCTION: acpi_ut_valid_name_char
46 * PARAMETERS: char - The character to be examined
47 * position - Byte position (0-3)
49 * RETURN: TRUE if the character is valid, FALSE otherwise
51 * DESCRIPTION: Check for a valid ACPI character. Must be one of:
56 * We allow a '!' as the last character because of the ASF! table
58 ******************************************************************************/
60 u8
acpi_ut_valid_name_char(char character
, u32 position
)
63 if (!((character
>= 'A' && character
<= 'Z') ||
64 (character
>= '0' && character
<= '9') || (character
== '_'))) {
66 /* Allow a '!' in the last position */
68 if (character
== '!' && position
== 3) {
78 /*******************************************************************************
80 * FUNCTION: acpi_ut_check_and_repair_ascii
82 * PARAMETERS: name - Ascii string
83 * count - Number of characters to check
87 * DESCRIPTION: Ensure that the requested number of characters are printable
88 * Ascii characters. Sets non-printable and null chars to <space>.
90 ******************************************************************************/
92 void acpi_ut_check_and_repair_ascii(u8
*name
, char *repaired_name
, u32 count
)
96 for (i
= 0; i
< count
; i
++) {
97 repaired_name
[i
] = (char)name
[i
];
102 if (!isprint(name
[i
])) {
103 repaired_name
[i
] = ' ';