ia64/xen-unstable

view xen/drivers/acpi/tables/tbinstal.c @ 18896:f7f8f44b9292

tools: Fix a few error-path memory leaks.

Signed-off-by: Keir Fraser <keir.fraser@citrix.com>
author Keir Fraser <keir.fraser@citrix.com>
date Tue Dec 09 12:53:19 2008 +0000 (2008-12-09)
parents ae29cd95ba7d
children
line source
1 /******************************************************************************
2 *
3 * Module Name: tbinstal - ACPI table installation and removal
4 *
5 *****************************************************************************/
7 /*
8 * Copyright (C) 2000 - 2008, 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 */
44 #include <xen/init.h>
45 #include <acpi/acpi.h>
46 #include <acpi/acnamesp.h>
47 #include <acpi/actables.h>
49 #define _COMPONENT ACPI_TABLES
50 ACPI_MODULE_NAME("tbinstal")
52 /******************************************************************************
53 *
54 * FUNCTION: acpi_tb_verify_table
55 *
56 * PARAMETERS: table_desc - table
57 *
58 * RETURN: Status
59 *
60 * DESCRIPTION: this function is called to verify and map table
61 *
62 *****************************************************************************/
63 acpi_status acpi_tb_verify_table(struct acpi_table_desc *table_desc)
64 {
65 acpi_status status = AE_OK;
67 ACPI_FUNCTION_TRACE(tb_verify_table);
69 /* Map the table if necessary */
71 if (!table_desc->pointer) {
72 if ((table_desc->flags & ACPI_TABLE_ORIGIN_MASK) ==
73 ACPI_TABLE_ORIGIN_MAPPED) {
74 table_desc->pointer =
75 acpi_os_map_memory(table_desc->address,
76 table_desc->length);
77 }
78 if (!table_desc->pointer) {
79 return_ACPI_STATUS(AE_NO_MEMORY);
80 }
81 }
83 /* FACS is the odd table, has no standard ACPI header and no checksum */
85 if (!ACPI_COMPARE_NAME(&table_desc->signature, ACPI_SIG_FACS)) {
87 /* Always calculate checksum, ignore bad checksum if requested */
89 status =
90 acpi_tb_verify_checksum(table_desc->pointer,
91 table_desc->length);
92 }
94 return_ACPI_STATUS(status);
95 }
97 /*******************************************************************************
98 *
99 * FUNCTION: acpi_tb_resize_root_table_list
100 *
101 * PARAMETERS: None
102 *
103 * RETURN: Status
104 *
105 * DESCRIPTION: Expand the size of global table array
106 *
107 ******************************************************************************/
109 acpi_status __init acpi_tb_resize_root_table_list(void)
110 {
111 struct acpi_table_desc *tables;
113 ACPI_FUNCTION_TRACE(tb_resize_root_table_list);
115 /* allow_resize flag is a parameter to acpi_initialize_tables */
117 if (!(acpi_gbl_root_table_list.flags & ACPI_ROOT_ALLOW_RESIZE)) {
118 ACPI_ERROR((AE_INFO,
119 "Resize of Root Table Array is not allowed"));
120 return_ACPI_STATUS(AE_SUPPORT);
121 }
123 /* Increase the Table Array size */
125 tables = ACPI_ALLOCATE_ZEROED((acpi_gbl_root_table_list.size +
126 ACPI_ROOT_TABLE_SIZE_INCREMENT)
127 * sizeof(struct acpi_table_desc));
128 if (!tables) {
129 ACPI_ERROR((AE_INFO,
130 "Could not allocate new root table array"));
131 return_ACPI_STATUS(AE_NO_MEMORY);
132 }
134 /* Copy and free the previous table array */
136 if (acpi_gbl_root_table_list.tables) {
137 ACPI_MEMCPY(tables, acpi_gbl_root_table_list.tables,
138 acpi_gbl_root_table_list.size *
139 sizeof(struct acpi_table_desc));
141 if (acpi_gbl_root_table_list.flags & ACPI_ROOT_ORIGIN_ALLOCATED) {
142 ACPI_FREE(acpi_gbl_root_table_list.tables);
143 }
144 }
146 acpi_gbl_root_table_list.tables = tables;
147 acpi_gbl_root_table_list.size += ACPI_ROOT_TABLE_SIZE_INCREMENT;
148 acpi_gbl_root_table_list.flags |= (u8) ACPI_ROOT_ORIGIN_ALLOCATED;
150 return_ACPI_STATUS(AE_OK);
151 }