brintos

brintos / linux-shallow public Read only

0
0
Text · 2.8 KiB · 2be3767 Raw
107 lines · c
1// SPDX-License-Identifier: BSD-3-Clause OR GPL-2.02/******************************************************************************3 *4 * Module Name: utascii - Utility ascii functions5 *6 * Copyright (C) 2000 - 2023, Intel Corp.7 *8 *****************************************************************************/9 10#include <acpi/acpi.h>11#include "accommon.h"12 13/*******************************************************************************14 *15 * FUNCTION:    acpi_ut_valid_nameseg16 *17 * PARAMETERS:  name            - The name or table signature to be examined.18 *                                Four characters, does not have to be a19 *                                NULL terminated string.20 *21 * RETURN:      TRUE if signature is has 4 valid ACPI characters22 *23 * DESCRIPTION: Validate an ACPI table signature.24 *25 ******************************************************************************/26 27u8 acpi_ut_valid_nameseg(char *name)28{29	u32 i;30 31	/* Validate each character in the signature */32 33	for (i = 0; i < ACPI_NAMESEG_SIZE; i++) {34		if (!acpi_ut_valid_name_char(name[i], i)) {35			return (FALSE);36		}37	}38 39	return (TRUE);40}41 42/*******************************************************************************43 *44 * FUNCTION:    acpi_ut_valid_name_char45 *46 * PARAMETERS:  char            - The character to be examined47 *              position        - Byte position (0-3)48 *49 * RETURN:      TRUE if the character is valid, FALSE otherwise50 *51 * DESCRIPTION: Check for a valid ACPI character. Must be one of:52 *              1) Upper case alpha53 *              2) numeric54 *              3) underscore55 *56 *              We allow a '!' as the last character because of the ASF! table57 *58 ******************************************************************************/59 60u8 acpi_ut_valid_name_char(char character, u32 position)61{62 63	if (!((character >= 'A' && character <= 'Z') ||64	      (character >= '0' && character <= '9') || (character == '_'))) {65 66		/* Allow a '!' in the last position */67 68		if (character == '!' && position == 3) {69			return (TRUE);70		}71 72		return (FALSE);73	}74 75	return (TRUE);76}77 78/*******************************************************************************79 *80 * FUNCTION:    acpi_ut_check_and_repair_ascii81 *82 * PARAMETERS:  name                - Ascii string83 *              count               - Number of characters to check84 *85 * RETURN:      None86 *87 * DESCRIPTION: Ensure that the requested number of characters are printable88 *              Ascii characters. Sets non-printable and null chars to <space>.89 *90 ******************************************************************************/91 92void acpi_ut_check_and_repair_ascii(u8 *name, char *repaired_name, u32 count)93{94	u32 i;95 96	for (i = 0; i < count; i++) {97		repaired_name[i] = (char)name[i];98 99		if (!name[i]) {100			return;101		}102		if (!isprint(name[i])) {103			repaired_name[i] = ' ';104		}105	}106}107