Skip to content

Commit 6a0df32

Browse files
acpibobrafaeljw
authored andcommitted
ACPICA: Move all ASCII utilities to a common file
ACPICA commit ba60e4500053010bf775d58f6f61febbdb94d817 New file is utascii.c Link: acpica/acpica@ba60e450 Signed-off-by: Bob Moore <[email protected]> Signed-off-by: Lv Zheng <[email protected]> Signed-off-by: Rafael J. Wysocki <[email protected]>
1 parent 66b1ed5 commit 6a0df32

File tree

13 files changed

+168
-111
lines changed

13 files changed

+168
-111
lines changed

drivers/acpi/acpica/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ acpi-y += \
150150
acpi-y += \
151151
utaddress.o \
152152
utalloc.o \
153+
utascii.o \
153154
utbuffer.o \
154155
utcopy.o \
155156
utexcep.o \

drivers/acpi/acpica/actables.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,6 @@ acpi_tb_install_fixed_table(acpi_physical_address address,
161161

162162
acpi_status acpi_tb_parse_root_table(acpi_physical_address rsdp_address);
163163

164-
u8 acpi_is_valid_signature(char *signature);
165-
166164
/*
167165
* tbxfload
168166
*/

drivers/acpi/acpica/acutils.h

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,15 @@ struct acpi_pkg_info {
166166
#define DB_DWORD_DISPLAY 4
167167
#define DB_QWORD_DISPLAY 8
168168

169+
/*
170+
* utascii - ASCII utilities
171+
*/
172+
u8 acpi_ut_valid_nameseg(char *signature);
173+
174+
u8 acpi_ut_valid_name_char(char character, u32 position);
175+
176+
void acpi_ut_check_and_repair_ascii(u8 *name, char *repaired_name, u32 count);
177+
169178
/*
170179
* utnonansi - Non-ANSI C library functions
171180
*/
@@ -579,10 +588,6 @@ void acpi_ut_print_string(char *string, u16 max_length);
579588
void ut_convert_backslashes(char *pathname);
580589
#endif
581590

582-
u8 acpi_ut_valid_acpi_name(char *name);
583-
584-
u8 acpi_ut_valid_acpi_char(char character, u32 position);
585-
586591
void acpi_ut_repair_name(char *name);
587592

588593
#if defined (ACPI_DEBUGGER) || defined (ACPI_APPLICATION)

drivers/acpi/acpica/dbnames.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -709,7 +709,7 @@ acpi_db_integrity_walk(acpi_handle obj_handle,
709709
return (AE_OK);
710710
}
711711

712-
if (!acpi_ut_valid_acpi_name(node->name.ascii)) {
712+
if (!acpi_ut_valid_nameseg(node->name.ascii)) {
713713
acpi_os_printf("Invalid AcpiName for Node %p\n", node);
714714
return (AE_OK);
715715
}

drivers/acpi/acpica/exnames.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ static acpi_status acpi_ex_name_segment(u8 ** in_aml_address, char *name_string)
178178

179179
for (index = 0;
180180
(index < ACPI_NAME_SIZE)
181-
&& (acpi_ut_valid_acpi_char(*aml_address, 0)); index++) {
181+
&& (acpi_ut_valid_name_char(*aml_address, 0)); index++) {
182182
char_buf[index] = *aml_address++;
183183
ACPI_DEBUG_PRINT((ACPI_DB_LOAD, "%c\n", char_buf[index]));
184184
}

drivers/acpi/acpica/tbdata.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -401,9 +401,9 @@ acpi_tb_verify_temp_table(struct acpi_table_desc *table_desc, char *signature)
401401
ACPI_EXCEPTION((AE_INFO, AE_NO_MEMORY,
402402
"%4.4s 0x%8.8X%8.8X"
403403
" Attempted table install failed",
404-
acpi_ut_valid_acpi_name(table_desc->
405-
signature.
406-
ascii) ?
404+
acpi_ut_valid_nameseg(table_desc->
405+
signature.
406+
ascii) ?
407407
table_desc->signature.ascii : "????",
408408
ACPI_FORMAT_UINT64(table_desc->
409409
address)));

drivers/acpi/acpica/tbfind.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ acpi_tb_find_table(char *signature,
7676

7777
/* Validate the input table signature */
7878

79-
if (!acpi_is_valid_signature(signature)) {
79+
if (!acpi_ut_valid_nameseg(signature)) {
8080
return_ACPI_STATUS(AE_BAD_SIGNATURE);
8181
}
8282

drivers/acpi/acpica/tbinstal.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -299,9 +299,9 @@ acpi_tb_install_standard_table(acpi_physical_address address,
299299
ACPI_BIOS_ERROR((AE_INFO,
300300
"Table has invalid signature [%4.4s] (0x%8.8X), "
301301
"must be SSDT or OEMx",
302-
acpi_ut_valid_acpi_name(new_table_desc.
303-
signature.
304-
ascii) ?
302+
acpi_ut_valid_nameseg(new_table_desc.
303+
signature.
304+
ascii) ?
305305
new_table_desc.signature.
306306
ascii : "????",
307307
new_table_desc.signature.integer));

drivers/acpi/acpica/tbutils.c

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -380,30 +380,3 @@ acpi_status __init acpi_tb_parse_root_table(acpi_physical_address rsdp_address)
380380
acpi_os_unmap_memory(table, length);
381381
return_ACPI_STATUS(AE_OK);
382382
}
383-
384-
/*******************************************************************************
385-
*
386-
* FUNCTION: acpi_is_valid_signature
387-
*
388-
* PARAMETERS: signature - Sig string to be validated
389-
*
390-
* RETURN: TRUE if signature is has 4 valid ACPI characters
391-
*
392-
* DESCRIPTION: Validate an ACPI table signature.
393-
*
394-
******************************************************************************/
395-
396-
u8 acpi_is_valid_signature(char *signature)
397-
{
398-
u32 i;
399-
400-
/* Validate each character in the signature */
401-
402-
for (i = 0; i < ACPI_NAME_SIZE; i++) {
403-
if (!acpi_ut_valid_acpi_char(signature[i], i)) {
404-
return (FALSE);
405-
}
406-
}
407-
408-
return (TRUE);
409-
}

drivers/acpi/acpica/utascii.c

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
/******************************************************************************
2+
*
3+
* Module Name: utascii - Utility ascii functions
4+
*
5+
*****************************************************************************/
6+
7+
/*
8+
* Copyright (C) 2000 - 2016, Intel Corp.
9+
* All rights reserved.
10+
*
11+
* Redistribution and use in source and binary forms, with or without
12+
* modification, are permitted provided that the following conditions
13+
* are met:
14+
* 1. Redistributions of source code must retain the above copyright
15+
* notice, this list of conditions, and the following disclaimer,
16+
* without modification.
17+
* 2. Redistributions in binary form must reproduce at minimum a disclaimer
18+
* substantially similar to the "NO WARRANTY" disclaimer below
19+
* ("Disclaimer") and any redistribution must be conditioned upon
20+
* including a substantially similar Disclaimer requirement for further
21+
* binary redistribution.
22+
* 3. Neither the names of the above-listed copyright holders nor the names
23+
* of any contributors may be used to endorse or promote products derived
24+
* from this software without specific prior written permission.
25+
*
26+
* Alternatively, this software may be distributed under the terms of the
27+
* GNU General Public License ("GPL") version 2 as published by the Free
28+
* Software Foundation.
29+
*
30+
* NO WARRANTY
31+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32+
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33+
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34+
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35+
* HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37+
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38+
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39+
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40+
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41+
* POSSIBILITY OF SUCH DAMAGES.
42+
*/
43+
44+
#include <acpi/acpi.h>
45+
#include "accommon.h"
46+
47+
/*******************************************************************************
48+
*
49+
* FUNCTION: acpi_ut_valid_nameseg
50+
*
51+
* PARAMETERS: name - The name or table signature to be examined.
52+
* Four characters, does not have to be a
53+
* NULL terminated string.
54+
*
55+
* RETURN: TRUE if signature is has 4 valid ACPI characters
56+
*
57+
* DESCRIPTION: Validate an ACPI table signature.
58+
*
59+
******************************************************************************/
60+
61+
u8 acpi_ut_valid_nameseg(char *name)
62+
{
63+
u32 i;
64+
65+
/* Validate each character in the signature */
66+
67+
for (i = 0; i < ACPI_NAME_SIZE; i++) {
68+
if (!acpi_ut_valid_name_char(name[i], i)) {
69+
return (FALSE);
70+
}
71+
}
72+
73+
return (TRUE);
74+
}
75+
76+
/*******************************************************************************
77+
*
78+
* FUNCTION: acpi_ut_valid_name_char
79+
*
80+
* PARAMETERS: char - The character to be examined
81+
* position - Byte position (0-3)
82+
*
83+
* RETURN: TRUE if the character is valid, FALSE otherwise
84+
*
85+
* DESCRIPTION: Check for a valid ACPI character. Must be one of:
86+
* 1) Upper case alpha
87+
* 2) numeric
88+
* 3) underscore
89+
*
90+
* We allow a '!' as the last character because of the ASF! table
91+
*
92+
******************************************************************************/
93+
94+
u8 acpi_ut_valid_name_char(char character, u32 position)
95+
{
96+
97+
if (!((character >= 'A' && character <= 'Z') ||
98+
(character >= '0' && character <= '9') || (character == '_'))) {
99+
100+
/* Allow a '!' in the last position */
101+
102+
if (character == '!' && position == 3) {
103+
return (TRUE);
104+
}
105+
106+
return (FALSE);
107+
}
108+
109+
return (TRUE);
110+
}
111+
112+
/*******************************************************************************
113+
*
114+
* FUNCTION: acpi_ut_check_and_repair_ascii
115+
*
116+
* PARAMETERS: name - Ascii string
117+
* count - Number of characters to check
118+
*
119+
* RETURN: None
120+
*
121+
* DESCRIPTION: Ensure that the requested number of characters are printable
122+
* Ascii characters. Sets non-printable and null chars to <space>.
123+
*
124+
******************************************************************************/
125+
126+
void acpi_ut_check_and_repair_ascii(u8 *name, char *repaired_name, u32 count)
127+
{
128+
u32 i;
129+
130+
for (i = 0; i < count; i++) {
131+
repaired_name[i] = (char)name[i];
132+
133+
if (!name[i]) {
134+
return;
135+
}
136+
if (!isprint(name[i])) {
137+
repaired_name[i] = ' ';
138+
}
139+
}
140+
}

drivers/acpi/acpica/utstring.c

Lines changed: 1 addition & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -143,73 +143,6 @@ void acpi_ut_print_string(char *string, u16 max_length)
143143
}
144144
}
145145

146-
/*******************************************************************************
147-
*
148-
* FUNCTION: acpi_ut_valid_acpi_char
149-
*
150-
* PARAMETERS: char - The character to be examined
151-
* position - Byte position (0-3)
152-
*
153-
* RETURN: TRUE if the character is valid, FALSE otherwise
154-
*
155-
* DESCRIPTION: Check for a valid ACPI character. Must be one of:
156-
* 1) Upper case alpha
157-
* 2) numeric
158-
* 3) underscore
159-
*
160-
* We allow a '!' as the last character because of the ASF! table
161-
*
162-
******************************************************************************/
163-
164-
u8 acpi_ut_valid_acpi_char(char character, u32 position)
165-
{
166-
167-
if (!((character >= 'A' && character <= 'Z') ||
168-
(character >= '0' && character <= '9') || (character == '_'))) {
169-
170-
/* Allow a '!' in the last position */
171-
172-
if (character == '!' && position == 3) {
173-
return (TRUE);
174-
}
175-
176-
return (FALSE);
177-
}
178-
179-
return (TRUE);
180-
}
181-
182-
/*******************************************************************************
183-
*
184-
* FUNCTION: acpi_ut_valid_acpi_name
185-
*
186-
* PARAMETERS: name - The name to be examined. Does not have to
187-
* be NULL terminated string.
188-
*
189-
* RETURN: TRUE if the name is valid, FALSE otherwise
190-
*
191-
* DESCRIPTION: Check for a valid ACPI name. Each character must be one of:
192-
* 1) Upper case alpha
193-
* 2) numeric
194-
* 3) underscore
195-
*
196-
******************************************************************************/
197-
198-
u8 acpi_ut_valid_acpi_name(char *name)
199-
{
200-
u32 i;
201-
202-
ACPI_FUNCTION_ENTRY();
203-
204-
for (i = 0; i < ACPI_NAME_SIZE; i++) {
205-
if (!acpi_ut_valid_acpi_char(name[i], i)) {
206-
return (FALSE);
207-
}
208-
}
209-
210-
return (TRUE);
211-
}
212-
213146
/*******************************************************************************
214147
*
215148
* FUNCTION: acpi_ut_repair_name
@@ -253,7 +186,7 @@ void acpi_ut_repair_name(char *name)
253186
/* Check each character in the name */
254187

255188
for (i = 0; i < ACPI_NAME_SIZE; i++) {
256-
if (acpi_ut_valid_acpi_char(name[i], i)) {
189+
if (acpi_ut_valid_name_char(name[i], i)) {
257190
continue;
258191
}
259192

tools/power/acpi/tools/acpidump/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ TOOL_OBJS = \
3131
osunixxf.o\
3232
tbprint.o\
3333
tbxfroot.o\
34+
utascii.o\
3435
utbuffer.o\
3536
utdebug.o\
3637
utexcep.o\

tools/power/acpi/tools/acpidump/apdump.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ u8 ap_is_valid_header(struct acpi_table_header *table)
6868

6969
/* Make sure signature is all ASCII and a valid ACPI name */
7070

71-
if (!acpi_ut_valid_acpi_name(table->signature)) {
71+
if (!acpi_ut_valid_nameseg(table->signature)) {
7272
acpi_log_error("Table signature (0x%8.8X) is invalid\n",
7373
*(u32 *)table->signature);
7474
return (FALSE);
@@ -407,6 +407,12 @@ int ap_dump_table_from_file(char *pathname)
407407
return (-1);
408408
}
409409

410+
if (!acpi_ut_valid_nameseg(table->signature)) {
411+
acpi_log_error
412+
("No valid ACPI signature was found in input file %s\n",
413+
pathname);
414+
}
415+
410416
/* File must be at least as long as the table length */
411417

412418
if (table->length > file_size) {

0 commit comments

Comments
 (0)