xref: /linux/drivers/acpi/acpica/exnames.c (revision 4fa4616e279df89baeb36287bbee83ab272edaed)
195b482a8SLen Brown /******************************************************************************
295b482a8SLen Brown  *
395b482a8SLen Brown  * Module Name: exnames - interpreter/scanner name load/execute
495b482a8SLen Brown  *
595b482a8SLen Brown  *****************************************************************************/
695b482a8SLen Brown 
795b482a8SLen Brown /*
882a80941SDavid E. Box  * Copyright (C) 2000 - 2015, Intel Corp.
995b482a8SLen Brown  * All rights reserved.
1095b482a8SLen Brown  *
1195b482a8SLen Brown  * Redistribution and use in source and binary forms, with or without
1295b482a8SLen Brown  * modification, are permitted provided that the following conditions
1395b482a8SLen Brown  * are met:
1495b482a8SLen Brown  * 1. Redistributions of source code must retain the above copyright
1595b482a8SLen Brown  *    notice, this list of conditions, and the following disclaimer,
1695b482a8SLen Brown  *    without modification.
1795b482a8SLen Brown  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
1895b482a8SLen Brown  *    substantially similar to the "NO WARRANTY" disclaimer below
1995b482a8SLen Brown  *    ("Disclaimer") and any redistribution must be conditioned upon
2095b482a8SLen Brown  *    including a substantially similar Disclaimer requirement for further
2195b482a8SLen Brown  *    binary redistribution.
2295b482a8SLen Brown  * 3. Neither the names of the above-listed copyright holders nor the names
2395b482a8SLen Brown  *    of any contributors may be used to endorse or promote products derived
2495b482a8SLen Brown  *    from this software without specific prior written permission.
2595b482a8SLen Brown  *
2695b482a8SLen Brown  * Alternatively, this software may be distributed under the terms of the
2795b482a8SLen Brown  * GNU General Public License ("GPL") version 2 as published by the Free
2895b482a8SLen Brown  * Software Foundation.
2995b482a8SLen Brown  *
3095b482a8SLen Brown  * NO WARRANTY
3195b482a8SLen Brown  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
3295b482a8SLen Brown  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
3395b482a8SLen Brown  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
3495b482a8SLen Brown  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
3595b482a8SLen Brown  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
3695b482a8SLen Brown  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
3795b482a8SLen Brown  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
3895b482a8SLen Brown  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
3995b482a8SLen Brown  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
4095b482a8SLen Brown  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
4195b482a8SLen Brown  * POSSIBILITY OF SUCH DAMAGES.
4295b482a8SLen Brown  */
4395b482a8SLen Brown 
4495b482a8SLen Brown #include <acpi/acpi.h>
45e2f7a777SLen Brown #include "accommon.h"
46e2f7a777SLen Brown #include "acinterp.h"
47e2f7a777SLen Brown #include "amlcode.h"
4895b482a8SLen Brown 
4995b482a8SLen Brown #define _COMPONENT          ACPI_EXECUTER
5095b482a8SLen Brown ACPI_MODULE_NAME("exnames")
5195b482a8SLen Brown 
5295b482a8SLen Brown /* Local prototypes */
5395b482a8SLen Brown static char *acpi_ex_allocate_name_string(u32 prefix_count, u32 num_name_segs);
5495b482a8SLen Brown 
551f86e8c1SLv Zheng static acpi_status acpi_ex_name_segment(u8 **in_aml_address, char *name_string);
5695b482a8SLen Brown 
5795b482a8SLen Brown /*******************************************************************************
5895b482a8SLen Brown  *
5995b482a8SLen Brown  * FUNCTION:    acpi_ex_allocate_name_string
6095b482a8SLen Brown  *
6195b482a8SLen Brown  * PARAMETERS:  prefix_count        - Count of parent levels. Special cases:
6295b482a8SLen Brown  *                                    (-1)==root,  0==none
6395b482a8SLen Brown  *              num_name_segs       - count of 4-character name segments
6495b482a8SLen Brown  *
6595b482a8SLen Brown  * RETURN:      A pointer to the allocated string segment. This segment must
6695b482a8SLen Brown  *              be deleted by the caller.
6795b482a8SLen Brown  *
6895b482a8SLen Brown  * DESCRIPTION: Allocate a buffer for a name string. Ensure allocated name
6995b482a8SLen Brown  *              string is long enough, and set up prefix if any.
7095b482a8SLen Brown  *
7195b482a8SLen Brown  ******************************************************************************/
7295b482a8SLen Brown 
7395b482a8SLen Brown static char *acpi_ex_allocate_name_string(u32 prefix_count, u32 num_name_segs)
7495b482a8SLen Brown {
7595b482a8SLen Brown 	char *temp_ptr;
7695b482a8SLen Brown 	char *name_string;
7795b482a8SLen Brown 	u32 size_needed;
7895b482a8SLen Brown 
7995b482a8SLen Brown 	ACPI_FUNCTION_TRACE(ex_allocate_name_string);
8095b482a8SLen Brown 
8195b482a8SLen Brown 	/*
8295b482a8SLen Brown 	 * Allow room for all \ and ^ prefixes, all segments and a multi_name_prefix.
8395b482a8SLen Brown 	 * Also, one byte for the null terminator.
8495b482a8SLen Brown 	 * This may actually be somewhat longer than needed.
8595b482a8SLen Brown 	 */
8695b482a8SLen Brown 	if (prefix_count == ACPI_UINT32_MAX) {
8795b482a8SLen Brown 
8895b482a8SLen Brown 		/* Special case for root */
8995b482a8SLen Brown 
9095b482a8SLen Brown 		size_needed = 1 + (ACPI_NAME_SIZE * num_name_segs) + 2 + 1;
9195b482a8SLen Brown 	} else {
9295b482a8SLen Brown 		size_needed =
9395b482a8SLen Brown 		    prefix_count + (ACPI_NAME_SIZE * num_name_segs) + 2 + 1;
9495b482a8SLen Brown 	}
9595b482a8SLen Brown 
9695b482a8SLen Brown 	/*
9795b482a8SLen Brown 	 * Allocate a buffer for the name.
9895b482a8SLen Brown 	 * This buffer must be deleted by the caller!
9995b482a8SLen Brown 	 */
10095b482a8SLen Brown 	name_string = ACPI_ALLOCATE(size_needed);
10195b482a8SLen Brown 	if (!name_string) {
10295b482a8SLen Brown 		ACPI_ERROR((AE_INFO,
103f6a22b0bSBob Moore 			    "Could not allocate size %u", size_needed));
10495b482a8SLen Brown 		return_PTR(NULL);
10595b482a8SLen Brown 	}
10695b482a8SLen Brown 
10795b482a8SLen Brown 	temp_ptr = name_string;
10895b482a8SLen Brown 
10995b482a8SLen Brown 	/* Set up Root or Parent prefixes if needed */
11095b482a8SLen Brown 
11195b482a8SLen Brown 	if (prefix_count == ACPI_UINT32_MAX) {
11295b482a8SLen Brown 		*temp_ptr++ = AML_ROOT_PREFIX;
11395b482a8SLen Brown 	} else {
11495b482a8SLen Brown 		while (prefix_count--) {
11595b482a8SLen Brown 			*temp_ptr++ = AML_PARENT_PREFIX;
11695b482a8SLen Brown 		}
11795b482a8SLen Brown 	}
11895b482a8SLen Brown 
11995b482a8SLen Brown 	/* Set up Dual or Multi prefixes if needed */
12095b482a8SLen Brown 
12195b482a8SLen Brown 	if (num_name_segs > 2) {
12295b482a8SLen Brown 
12395b482a8SLen Brown 		/* Set up multi prefixes   */
12495b482a8SLen Brown 
12595b482a8SLen Brown 		*temp_ptr++ = AML_MULTI_NAME_PREFIX_OP;
12695b482a8SLen Brown 		*temp_ptr++ = (char)num_name_segs;
12795b482a8SLen Brown 	} else if (2 == num_name_segs) {
12895b482a8SLen Brown 
12995b482a8SLen Brown 		/* Set up dual prefixes */
13095b482a8SLen Brown 
13195b482a8SLen Brown 		*temp_ptr++ = AML_DUAL_NAME_PREFIX;
13295b482a8SLen Brown 	}
13395b482a8SLen Brown 
13495b482a8SLen Brown 	/*
13595b482a8SLen Brown 	 * Terminate string following prefixes. acpi_ex_name_segment() will
13695b482a8SLen Brown 	 * append the segment(s)
13795b482a8SLen Brown 	 */
13895b482a8SLen Brown 	*temp_ptr = 0;
13995b482a8SLen Brown 
14095b482a8SLen Brown 	return_PTR(name_string);
14195b482a8SLen Brown }
14295b482a8SLen Brown 
14395b482a8SLen Brown /*******************************************************************************
14495b482a8SLen Brown  *
14595b482a8SLen Brown  * FUNCTION:    acpi_ex_name_segment
14695b482a8SLen Brown  *
14795b482a8SLen Brown  * PARAMETERS:  in_aml_address  - Pointer to the name in the AML code
14895b482a8SLen Brown  *              name_string     - Where to return the name. The name is appended
14995b482a8SLen Brown  *                                to any existing string to form a namepath
15095b482a8SLen Brown  *
15195b482a8SLen Brown  * RETURN:      Status
15295b482a8SLen Brown  *
15395b482a8SLen Brown  * DESCRIPTION: Extract an ACPI name (4 bytes) from the AML byte stream
15495b482a8SLen Brown  *
15595b482a8SLen Brown  ******************************************************************************/
15695b482a8SLen Brown 
15795b482a8SLen Brown static acpi_status acpi_ex_name_segment(u8 ** in_aml_address, char *name_string)
15895b482a8SLen Brown {
15995b482a8SLen Brown 	char *aml_address = (void *)*in_aml_address;
16095b482a8SLen Brown 	acpi_status status = AE_OK;
16195b482a8SLen Brown 	u32 index;
16295b482a8SLen Brown 	char char_buf[5];
16395b482a8SLen Brown 
16495b482a8SLen Brown 	ACPI_FUNCTION_TRACE(ex_name_segment);
16595b482a8SLen Brown 
16695b482a8SLen Brown 	/*
16795b482a8SLen Brown 	 * If first character is a digit, then we know that we aren't looking at a
16895b482a8SLen Brown 	 * valid name segment
16995b482a8SLen Brown 	 */
17095b482a8SLen Brown 	char_buf[0] = *aml_address;
17195b482a8SLen Brown 
17295b482a8SLen Brown 	if ('0' <= char_buf[0] && char_buf[0] <= '9') {
17395b482a8SLen Brown 		ACPI_ERROR((AE_INFO, "Invalid leading digit: %c", char_buf[0]));
17495b482a8SLen Brown 		return_ACPI_STATUS(AE_CTRL_PENDING);
17595b482a8SLen Brown 	}
17695b482a8SLen Brown 
17795b482a8SLen Brown 	ACPI_DEBUG_PRINT((ACPI_DB_LOAD, "Bytes from stream:\n"));
17895b482a8SLen Brown 
1791f86e8c1SLv Zheng 	for (index = 0;
1801f86e8c1SLv Zheng 	     (index < ACPI_NAME_SIZE)
18195b482a8SLen Brown 	     && (acpi_ut_valid_acpi_char(*aml_address, 0)); index++) {
18295b482a8SLen Brown 		char_buf[index] = *aml_address++;
18395b482a8SLen Brown 		ACPI_DEBUG_PRINT((ACPI_DB_LOAD, "%c\n", char_buf[index]));
18495b482a8SLen Brown 	}
18595b482a8SLen Brown 
18695b482a8SLen Brown 	/* Valid name segment  */
18795b482a8SLen Brown 
18895b482a8SLen Brown 	if (index == 4) {
18995b482a8SLen Brown 
19095b482a8SLen Brown 		/* Found 4 valid characters */
19195b482a8SLen Brown 
19295b482a8SLen Brown 		char_buf[4] = '\0';
19395b482a8SLen Brown 
19495b482a8SLen Brown 		if (name_string) {
195*4fa4616eSBob Moore 			strcat(name_string, char_buf);
19695b482a8SLen Brown 			ACPI_DEBUG_PRINT((ACPI_DB_NAMES,
19795b482a8SLen Brown 					  "Appended to - %s\n", name_string));
19895b482a8SLen Brown 		} else {
19995b482a8SLen Brown 			ACPI_DEBUG_PRINT((ACPI_DB_NAMES,
20095b482a8SLen Brown 					  "No Name string - %s\n", char_buf));
20195b482a8SLen Brown 		}
20295b482a8SLen Brown 	} else if (index == 0) {
20395b482a8SLen Brown 		/*
20495b482a8SLen Brown 		 * First character was not a valid name character,
20595b482a8SLen Brown 		 * so we are looking at something other than a name.
20695b482a8SLen Brown 		 */
20795b482a8SLen Brown 		ACPI_DEBUG_PRINT((ACPI_DB_INFO,
20895b482a8SLen Brown 				  "Leading character is not alpha: %02Xh (not a name)\n",
20995b482a8SLen Brown 				  char_buf[0]));
21095b482a8SLen Brown 		status = AE_CTRL_PENDING;
21195b482a8SLen Brown 	} else {
21295b482a8SLen Brown 		/*
21395b482a8SLen Brown 		 * Segment started with one or more valid characters, but fewer than
21495b482a8SLen Brown 		 * the required 4
21595b482a8SLen Brown 		 */
21695b482a8SLen Brown 		status = AE_AML_BAD_NAME;
21795b482a8SLen Brown 		ACPI_ERROR((AE_INFO,
218f6a22b0bSBob Moore 			    "Bad character 0x%02x in name, at %p",
21995b482a8SLen Brown 			    *aml_address, aml_address));
22095b482a8SLen Brown 	}
22195b482a8SLen Brown 
22295b482a8SLen Brown 	*in_aml_address = ACPI_CAST_PTR(u8, aml_address);
22395b482a8SLen Brown 	return_ACPI_STATUS(status);
22495b482a8SLen Brown }
22595b482a8SLen Brown 
22695b482a8SLen Brown /*******************************************************************************
22795b482a8SLen Brown  *
22895b482a8SLen Brown  * FUNCTION:    acpi_ex_get_name_string
22995b482a8SLen Brown  *
23095b482a8SLen Brown  * PARAMETERS:  data_type           - Object type to be associated with this
23195b482a8SLen Brown  *                                    name
23295b482a8SLen Brown  *              in_aml_address      - Pointer to the namestring in the AML code
23395b482a8SLen Brown  *              out_name_string     - Where the namestring is returned
23495b482a8SLen Brown  *              out_name_length     - Length of the returned string
23595b482a8SLen Brown  *
23695b482a8SLen Brown  * RETURN:      Status, namestring and length
23795b482a8SLen Brown  *
23895b482a8SLen Brown  * DESCRIPTION: Extract a full namepath from the AML byte stream,
23995b482a8SLen Brown  *              including any prefixes.
24095b482a8SLen Brown  *
24195b482a8SLen Brown  ******************************************************************************/
24295b482a8SLen Brown 
24395b482a8SLen Brown acpi_status
24495b482a8SLen Brown acpi_ex_get_name_string(acpi_object_type data_type,
24595b482a8SLen Brown 			u8 * in_aml_address,
24695b482a8SLen Brown 			char **out_name_string, u32 * out_name_length)
24795b482a8SLen Brown {
24895b482a8SLen Brown 	acpi_status status = AE_OK;
24995b482a8SLen Brown 	u8 *aml_address = in_aml_address;
25095b482a8SLen Brown 	char *name_string = NULL;
25195b482a8SLen Brown 	u32 num_segments;
25295b482a8SLen Brown 	u32 prefix_count = 0;
25395b482a8SLen Brown 	u8 has_prefix = FALSE;
25495b482a8SLen Brown 
25595b482a8SLen Brown 	ACPI_FUNCTION_TRACE_PTR(ex_get_name_string, aml_address);
25695b482a8SLen Brown 
25795b482a8SLen Brown 	if (ACPI_TYPE_LOCAL_REGION_FIELD == data_type ||
25895b482a8SLen Brown 	    ACPI_TYPE_LOCAL_BANK_FIELD == data_type ||
25995b482a8SLen Brown 	    ACPI_TYPE_LOCAL_INDEX_FIELD == data_type) {
26095b482a8SLen Brown 
26195b482a8SLen Brown 		/* Disallow prefixes for types associated with field_unit names */
26295b482a8SLen Brown 
26395b482a8SLen Brown 		name_string = acpi_ex_allocate_name_string(0, 1);
26495b482a8SLen Brown 		if (!name_string) {
26595b482a8SLen Brown 			status = AE_NO_MEMORY;
26695b482a8SLen Brown 		} else {
26795b482a8SLen Brown 			status =
26895b482a8SLen Brown 			    acpi_ex_name_segment(&aml_address, name_string);
26995b482a8SLen Brown 		}
27095b482a8SLen Brown 	} else {
27195b482a8SLen Brown 		/*
27295b482a8SLen Brown 		 * data_type is not a field name.
27395b482a8SLen Brown 		 * Examine first character of name for root or parent prefix operators
27495b482a8SLen Brown 		 */
27595b482a8SLen Brown 		switch (*aml_address) {
27695b482a8SLen Brown 		case AML_ROOT_PREFIX:
27795b482a8SLen Brown 
27895b482a8SLen Brown 			ACPI_DEBUG_PRINT((ACPI_DB_LOAD,
27995b482a8SLen Brown 					  "RootPrefix(\\) at %p\n",
28095b482a8SLen Brown 					  aml_address));
28195b482a8SLen Brown 
28295b482a8SLen Brown 			/*
28395b482a8SLen Brown 			 * Remember that we have a root_prefix --
28495b482a8SLen Brown 			 * see comment in acpi_ex_allocate_name_string()
28595b482a8SLen Brown 			 */
28695b482a8SLen Brown 			aml_address++;
28795b482a8SLen Brown 			prefix_count = ACPI_UINT32_MAX;
28895b482a8SLen Brown 			has_prefix = TRUE;
28995b482a8SLen Brown 			break;
29095b482a8SLen Brown 
29195b482a8SLen Brown 		case AML_PARENT_PREFIX:
29295b482a8SLen Brown 
29395b482a8SLen Brown 			/* Increment past possibly multiple parent prefixes */
29495b482a8SLen Brown 
29595b482a8SLen Brown 			do {
29695b482a8SLen Brown 				ACPI_DEBUG_PRINT((ACPI_DB_LOAD,
29795b482a8SLen Brown 						  "ParentPrefix (^) at %p\n",
29895b482a8SLen Brown 						  aml_address));
29995b482a8SLen Brown 
30095b482a8SLen Brown 				aml_address++;
30195b482a8SLen Brown 				prefix_count++;
30295b482a8SLen Brown 
30395b482a8SLen Brown 			} while (*aml_address == AML_PARENT_PREFIX);
30495b482a8SLen Brown 
30595b482a8SLen Brown 			has_prefix = TRUE;
30695b482a8SLen Brown 			break;
30795b482a8SLen Brown 
30895b482a8SLen Brown 		default:
30995b482a8SLen Brown 
31095b482a8SLen Brown 			/* Not a prefix character */
31195b482a8SLen Brown 
31295b482a8SLen Brown 			break;
31395b482a8SLen Brown 		}
31495b482a8SLen Brown 
31595b482a8SLen Brown 		/* Examine first character of name for name segment prefix operator */
31695b482a8SLen Brown 
31795b482a8SLen Brown 		switch (*aml_address) {
31895b482a8SLen Brown 		case AML_DUAL_NAME_PREFIX:
31995b482a8SLen Brown 
32095b482a8SLen Brown 			ACPI_DEBUG_PRINT((ACPI_DB_LOAD,
32195b482a8SLen Brown 					  "DualNamePrefix at %p\n",
32295b482a8SLen Brown 					  aml_address));
32395b482a8SLen Brown 
32495b482a8SLen Brown 			aml_address++;
32595b482a8SLen Brown 			name_string =
32695b482a8SLen Brown 			    acpi_ex_allocate_name_string(prefix_count, 2);
32795b482a8SLen Brown 			if (!name_string) {
32895b482a8SLen Brown 				status = AE_NO_MEMORY;
32995b482a8SLen Brown 				break;
33095b482a8SLen Brown 			}
33195b482a8SLen Brown 
33295b482a8SLen Brown 			/* Indicate that we processed a prefix */
33395b482a8SLen Brown 
33495b482a8SLen Brown 			has_prefix = TRUE;
33595b482a8SLen Brown 
33695b482a8SLen Brown 			status =
33795b482a8SLen Brown 			    acpi_ex_name_segment(&aml_address, name_string);
33895b482a8SLen Brown 			if (ACPI_SUCCESS(status)) {
33995b482a8SLen Brown 				status =
34095b482a8SLen Brown 				    acpi_ex_name_segment(&aml_address,
34195b482a8SLen Brown 							 name_string);
34295b482a8SLen Brown 			}
34395b482a8SLen Brown 			break;
34495b482a8SLen Brown 
34595b482a8SLen Brown 		case AML_MULTI_NAME_PREFIX_OP:
34695b482a8SLen Brown 
34795b482a8SLen Brown 			ACPI_DEBUG_PRINT((ACPI_DB_LOAD,
34895b482a8SLen Brown 					  "MultiNamePrefix at %p\n",
34995b482a8SLen Brown 					  aml_address));
35095b482a8SLen Brown 
35195b482a8SLen Brown 			/* Fetch count of segments remaining in name path */
35295b482a8SLen Brown 
35395b482a8SLen Brown 			aml_address++;
35495b482a8SLen Brown 			num_segments = *aml_address;
35595b482a8SLen Brown 
35695b482a8SLen Brown 			name_string =
35795b482a8SLen Brown 			    acpi_ex_allocate_name_string(prefix_count,
35895b482a8SLen Brown 							 num_segments);
35995b482a8SLen Brown 			if (!name_string) {
36095b482a8SLen Brown 				status = AE_NO_MEMORY;
36195b482a8SLen Brown 				break;
36295b482a8SLen Brown 			}
36395b482a8SLen Brown 
36495b482a8SLen Brown 			/* Indicate that we processed a prefix */
36595b482a8SLen Brown 
36695b482a8SLen Brown 			aml_address++;
36795b482a8SLen Brown 			has_prefix = TRUE;
36895b482a8SLen Brown 
36995b482a8SLen Brown 			while (num_segments &&
37095b482a8SLen Brown 			       (status =
37195b482a8SLen Brown 				acpi_ex_name_segment(&aml_address,
37295b482a8SLen Brown 						     name_string)) == AE_OK) {
37395b482a8SLen Brown 				num_segments--;
37495b482a8SLen Brown 			}
37595b482a8SLen Brown 
37695b482a8SLen Brown 			break;
37795b482a8SLen Brown 
37895b482a8SLen Brown 		case 0:
37995b482a8SLen Brown 
38095b482a8SLen Brown 			/* null_name valid as of 8-12-98 ASL/AML Grammar Update */
38195b482a8SLen Brown 
38295b482a8SLen Brown 			if (prefix_count == ACPI_UINT32_MAX) {
38395b482a8SLen Brown 				ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
38495b482a8SLen Brown 						  "NameSeg is \"\\\" followed by NULL\n"));
38595b482a8SLen Brown 			}
38695b482a8SLen Brown 
38795b482a8SLen Brown 			/* Consume the NULL byte */
38895b482a8SLen Brown 
38995b482a8SLen Brown 			aml_address++;
39095b482a8SLen Brown 			name_string =
39195b482a8SLen Brown 			    acpi_ex_allocate_name_string(prefix_count, 0);
39295b482a8SLen Brown 			if (!name_string) {
39395b482a8SLen Brown 				status = AE_NO_MEMORY;
39495b482a8SLen Brown 				break;
39595b482a8SLen Brown 			}
39695b482a8SLen Brown 
39795b482a8SLen Brown 			break;
39895b482a8SLen Brown 
39995b482a8SLen Brown 		default:
40095b482a8SLen Brown 
40195b482a8SLen Brown 			/* Name segment string */
40295b482a8SLen Brown 
40395b482a8SLen Brown 			name_string =
40495b482a8SLen Brown 			    acpi_ex_allocate_name_string(prefix_count, 1);
40595b482a8SLen Brown 			if (!name_string) {
40695b482a8SLen Brown 				status = AE_NO_MEMORY;
40795b482a8SLen Brown 				break;
40895b482a8SLen Brown 			}
40995b482a8SLen Brown 
41095b482a8SLen Brown 			status =
41195b482a8SLen Brown 			    acpi_ex_name_segment(&aml_address, name_string);
41295b482a8SLen Brown 			break;
41395b482a8SLen Brown 		}
41495b482a8SLen Brown 	}
41595b482a8SLen Brown 
41695b482a8SLen Brown 	if (AE_CTRL_PENDING == status && has_prefix) {
41795b482a8SLen Brown 
41895b482a8SLen Brown 		/* Ran out of segments after processing a prefix */
41995b482a8SLen Brown 
42095b482a8SLen Brown 		ACPI_ERROR((AE_INFO, "Malformed Name at %p", name_string));
42195b482a8SLen Brown 		status = AE_AML_BAD_NAME;
42295b482a8SLen Brown 	}
42395b482a8SLen Brown 
42495b482a8SLen Brown 	if (ACPI_FAILURE(status)) {
42595b482a8SLen Brown 		if (name_string) {
42695b482a8SLen Brown 			ACPI_FREE(name_string);
42795b482a8SLen Brown 		}
42895b482a8SLen Brown 		return_ACPI_STATUS(status);
42995b482a8SLen Brown 	}
43095b482a8SLen Brown 
43195b482a8SLen Brown 	*out_name_string = name_string;
43295b482a8SLen Brown 	*out_name_length = (u32) (aml_address - in_aml_address);
43395b482a8SLen Brown 
43495b482a8SLen Brown 	return_ACPI_STATUS(status);
43595b482a8SLen Brown }
436