- Kai Germaschewski: ISDN update (including Makefiles)
[davej-history.git] / drivers / acpi / common / cmalloc.c
blobb7a64e5b6166800de70068d106193e8dd84b7195
1 /******************************************************************************
3 * Module Name: cmalloc - local memory allocation routines
4 * $Revision: 79 $
6 *****************************************************************************/
8 /*
9 * Copyright (C) 2000 R. Byron Moore
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 #include "acpi.h"
28 #include "acparser.h"
29 #include "acinterp.h"
30 #include "acnamesp.h"
31 #include "acglobal.h"
33 #define _COMPONENT MISCELLANEOUS
34 MODULE_NAME ("cmalloc")
37 /*****************************************************************************
39 * FUNCTION: _Cm_allocate
41 * PARAMETERS: Size - Size of the allocation
42 * Component - Component type of caller
43 * Module - Source file name of caller
44 * Line - Line number of caller
46 * RETURN: Address of the allocated memory on success, NULL on failure.
48 * DESCRIPTION: The subsystem's equivalent of malloc.
50 ****************************************************************************/
52 void *
53 _cm_allocate (
54 u32 size,
55 u32 component,
56 NATIVE_CHAR *module,
57 u32 line)
59 void *address = NULL;
60 DEBUG_ONLY_MEMBERS (\
61 ACPI_STATUS status)
64 /* Check for an inadvertent size of zero bytes */
66 if (!size) {
67 _REPORT_ERROR (module, line, component,
68 ("Cm_allocate: Attempt to allocate zero bytes\n"));
69 size = 1;
72 address = acpi_os_allocate (size);
73 if (!address) {
74 /* Report allocation error */
76 _REPORT_ERROR (module, line, component,
77 ("Cm_allocate: Could not allocate size %X\n", size));
79 return (NULL);
83 return (address);
87 /*****************************************************************************
89 * FUNCTION: _Cm_callocate
91 * PARAMETERS: Size - Size of the allocation
92 * Component - Component type of caller
93 * Module - Source file name of caller
94 * Line - Line number of caller
96 * RETURN: Address of the allocated memory on success, NULL on failure.
98 * DESCRIPTION: Subsystem equivalent of calloc.
100 ****************************************************************************/
102 void *
103 _cm_callocate (
104 u32 size,
105 u32 component,
106 NATIVE_CHAR *module,
107 u32 line)
109 void *address = NULL;
110 DEBUG_ONLY_MEMBERS (\
111 ACPI_STATUS status)
114 /* Check for an inadvertent size of zero bytes */
116 if (!size) {
117 _REPORT_ERROR (module, line, component,
118 ("Cm_callocate: Attempt to allocate zero bytes\n"));
119 return (NULL);
123 address = acpi_os_callocate (size);
125 if (!address) {
126 /* Report allocation error */
128 _REPORT_ERROR (module, line, component,
129 ("Cm_callocate: Could not allocate size %X\n", size));
130 return (NULL);
134 return (address);
138 /*****************************************************************************
140 * FUNCTION: _Cm_free
142 * PARAMETERS: Address - Address of the memory to deallocate
143 * Component - Component type of caller
144 * Module - Source file name of caller
145 * Line - Line number of caller
147 * RETURN: None
149 * DESCRIPTION: Frees the memory at Address
151 ****************************************************************************/
153 void
154 _cm_free (
155 void *address,
156 u32 component,
157 NATIVE_CHAR *module,
158 u32 line)
161 if (NULL == address) {
162 _REPORT_ERROR (module, line, component,
163 ("_Cm_free: Trying to delete a NULL address\n"));
165 return;
169 acpi_os_free (address);
171 return;