Merge tag 'trace-v5.11-rc2' of git://git.kernel.org/pub/scm/linux/kernel/git/rostedt...
[linux/fpc-iii.git] / drivers / acpi / acpica / utstring.c
blobc39b5483045df0d98b4f98d8ec790a79abce9da3
1 // SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
2 /*******************************************************************************
4 * Module Name: utstring - Common functions for strings and characters
6 ******************************************************************************/
8 #include <acpi/acpi.h>
9 #include "accommon.h"
10 #include "acnamesp.h"
12 #define _COMPONENT ACPI_UTILITIES
13 ACPI_MODULE_NAME("utstring")
15 /*******************************************************************************
17 * FUNCTION: acpi_ut_print_string
19 * PARAMETERS: string - Null terminated ASCII string
20 * max_length - Maximum output length. Used to constrain the
21 * length of strings during debug output only.
23 * RETURN: None
25 * DESCRIPTION: Dump an ASCII string with support for ACPI-defined escape
26 * sequences.
28 ******************************************************************************/
29 void acpi_ut_print_string(char *string, u16 max_length)
31 u32 i;
33 if (!string) {
34 acpi_os_printf("<\"NULL STRING PTR\">");
35 return;
38 acpi_os_printf("\"");
39 for (i = 0; (i < max_length) && string[i]; i++) {
41 /* Escape sequences */
43 switch (string[i]) {
44 case 0x07:
46 acpi_os_printf("\\a"); /* BELL */
47 break;
49 case 0x08:
51 acpi_os_printf("\\b"); /* BACKSPACE */
52 break;
54 case 0x0C:
56 acpi_os_printf("\\f"); /* FORMFEED */
57 break;
59 case 0x0A:
61 acpi_os_printf("\\n"); /* LINEFEED */
62 break;
64 case 0x0D:
66 acpi_os_printf("\\r"); /* CARRIAGE RETURN */
67 break;
69 case 0x09:
71 acpi_os_printf("\\t"); /* HORIZONTAL TAB */
72 break;
74 case 0x0B:
76 acpi_os_printf("\\v"); /* VERTICAL TAB */
77 break;
79 case '\'': /* Single Quote */
80 case '\"': /* Double Quote */
81 case '\\': /* Backslash */
83 acpi_os_printf("\\%c", (int)string[i]);
84 break;
86 default:
88 /* Check for printable character or hex escape */
90 if (isprint((int)string[i])) {
91 /* This is a normal character */
93 acpi_os_printf("%c", (int)string[i]);
94 } else {
95 /* All others will be Hex escapes */
97 acpi_os_printf("\\x%2.2X", (s32)string[i]);
99 break;
103 acpi_os_printf("\"");
105 if (i == max_length && string[i]) {
106 acpi_os_printf("...");
110 /*******************************************************************************
112 * FUNCTION: acpi_ut_repair_name
114 * PARAMETERS: name - The ACPI name to be repaired
116 * RETURN: Repaired version of the name
118 * DESCRIPTION: Repair an ACPI name: Change invalid characters to '*' and
119 * return the new name. NOTE: the Name parameter must reside in
120 * read/write memory, cannot be a const.
122 * An ACPI Name must consist of valid ACPI characters. We will repair the name
123 * if necessary because we don't want to abort because of this, but we want
124 * all namespace names to be printable. A warning message is appropriate.
126 * This issue came up because there are in fact machines that exhibit
127 * this problem, and we want to be able to enable ACPI support for them,
128 * even though there are a few bad names.
130 ******************************************************************************/
132 void acpi_ut_repair_name(char *name)
134 u32 i;
135 u8 found_bad_char = FALSE;
136 u32 original_name;
138 ACPI_FUNCTION_NAME(ut_repair_name);
141 * Special case for the root node. This can happen if we get an
142 * error during the execution of module-level code.
144 if (ACPI_COMPARE_NAMESEG(name, ACPI_ROOT_PATHNAME)) {
145 return;
148 ACPI_COPY_NAMESEG(&original_name, name);
150 /* Check each character in the name */
152 for (i = 0; i < ACPI_NAMESEG_SIZE; i++) {
153 if (acpi_ut_valid_name_char(name[i], i)) {
154 continue;
158 * Replace a bad character with something printable, yet technically
159 * still invalid. This prevents any collisions with existing "good"
160 * names in the namespace.
162 name[i] = '*';
163 found_bad_char = TRUE;
166 if (found_bad_char) {
168 /* Report warning only if in strict mode or debug mode */
170 if (!acpi_gbl_enable_interpreter_slack) {
171 ACPI_WARNING((AE_INFO,
172 "Invalid character(s) in name (0x%.8X), repaired: [%4.4s]",
173 original_name, name));
174 } else {
175 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
176 "Invalid character(s) in name (0x%.8X), repaired: [%4.4s]",
177 original_name, name));
182 #if defined ACPI_ASL_COMPILER || defined ACPI_EXEC_APP
183 /*******************************************************************************
185 * FUNCTION: ut_convert_backslashes
187 * PARAMETERS: pathname - File pathname string to be converted
189 * RETURN: Modifies the input Pathname
191 * DESCRIPTION: Convert all backslashes (0x5C) to forward slashes (0x2F) within
192 * the entire input file pathname string.
194 ******************************************************************************/
196 void ut_convert_backslashes(char *pathname)
199 if (!pathname) {
200 return;
203 while (*pathname) {
204 if (*pathname == '\\') {
205 *pathname = '/';
208 pathname++;
211 #endif