Merge tag 'trace-v5.11-rc2' of git://git.kernel.org/pub/scm/linux/kernel/git/rostedt...
[linux/fpc-iii.git] / drivers / acpi / acpica / utascii.c
blobd78656d960e8375a7b89ddc741658b2e34026bc0
1 // SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
2 /******************************************************************************
4 * Module Name: utascii - Utility ascii functions
6 * Copyright (C) 2000 - 2020, Intel Corp.
8 *****************************************************************************/
10 #include <acpi/acpi.h>
11 #include "accommon.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)
29 u32 i;
31 /* Validate each character in the signature */
33 for (i = 0; i < ACPI_NAMESEG_SIZE; i++) {
34 if (!acpi_ut_valid_name_char(name[i], i)) {
35 return (FALSE);
39 return (TRUE);
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:
52 * 1) Upper case alpha
53 * 2) numeric
54 * 3) underscore
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) {
69 return (TRUE);
72 return (FALSE);
75 return (TRUE);
78 /*******************************************************************************
80 * FUNCTION: acpi_ut_check_and_repair_ascii
82 * PARAMETERS: name - Ascii string
83 * count - Number of characters to check
85 * RETURN: None
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)
94 u32 i;
96 for (i = 0; i < count; i++) {
97 repaired_name[i] = (char)name[i];
99 if (!name[i]) {
100 return;
102 if (!isprint(name[i])) {
103 repaired_name[i] = ' ';