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