minor corrections by M.Taguchi
[reactos.git] / reactos / drivers / bus / acpi / utils / cmalloc.c
1 /******************************************************************************
2 *
3 * Module Name: cmalloc - local memory allocation routines
4 * $Revision: 1.1 $
5 *
6 *****************************************************************************/
7
8 /*
9 * Copyright (C) 2000, 2001 R. Byron Moore
10 *
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.
15 *
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.
20 *
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
24 */
25
26
27 #include "acpi.h"
28 #include "acparser.h"
29 #include "acinterp.h"
30 #include "acnamesp.h"
31 #include "acglobal.h"
32
33 #define _COMPONENT ACPI_UTILITIES
34 MODULE_NAME ("cmalloc")
35
36
37 /*****************************************************************************
38 *
39 * FUNCTION: _Cm_allocate
40 *
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
45 *
46 * RETURN: Address of the allocated memory on success, NULL on failure.
47 *
48 * DESCRIPTION: The subsystem's equivalent of malloc.
49 *
50 ****************************************************************************/
51
52 void *
53 _cm_allocate (
54 u32 size,
55 u32 component,
56 NATIVE_CHAR *module,
57 u32 line)
58 {
59 void *address = NULL;
60
61
62 /* Check for an inadvertent size of zero bytes */
63
64 if (!size) {
65 _REPORT_ERROR (module, line, component,
66 ("Cm_allocate: Attempt to allocate zero bytes\n"));
67 size = 1;
68 }
69
70 address = acpi_os_allocate (size);
71 if (!address) {
72 /* Report allocation error */
73
74 _REPORT_ERROR (module, line, component,
75 ("Cm_allocate: Could not allocate size %X\n", size));
76
77 return (NULL);
78 }
79
80
81 return (address);
82 }
83
84
85 /*****************************************************************************
86 *
87 * FUNCTION: _Cm_callocate
88 *
89 * PARAMETERS: Size - Size of the allocation
90 * Component - Component type of caller
91 * Module - Source file name of caller
92 * Line - Line number of caller
93 *
94 * RETURN: Address of the allocated memory on success, NULL on failure.
95 *
96 * DESCRIPTION: Subsystem equivalent of calloc.
97 *
98 ****************************************************************************/
99
100 void *
101 _cm_callocate (
102 u32 size,
103 u32 component,
104 NATIVE_CHAR *module,
105 u32 line)
106 {
107 void *address = NULL;
108
109
110 /* Check for an inadvertent size of zero bytes */
111
112 if (!size) {
113 _REPORT_ERROR (module, line, component,
114 ("Cm_callocate: Attempt to allocate zero bytes\n"));
115 return (NULL);
116 }
117
118
119 address = acpi_os_callocate (size);
120
121 if (!address) {
122 /* Report allocation error */
123
124 _REPORT_ERROR (module, line, component,
125 ("Cm_callocate: Could not allocate size %X\n", size));
126 return (NULL);
127 }
128
129
130 return (address);
131 }
132
133
134 /*****************************************************************************
135 *
136 * FUNCTION: _Cm_free
137 *
138 * PARAMETERS: Address - Address of the memory to deallocate
139 * Component - Component type of caller
140 * Module - Source file name of caller
141 * Line - Line number of caller
142 *
143 * RETURN: None
144 *
145 * DESCRIPTION: Frees the memory at Address
146 *
147 ****************************************************************************/
148
149 void
150 _cm_free (
151 void *address,
152 u32 component,
153 NATIVE_CHAR *module,
154 u32 line)
155 {
156
157 if (NULL == address) {
158 _REPORT_ERROR (module, line, component,
159 ("_Cm_free: Trying to delete a NULL address\n"));
160
161 return;
162 }
163
164
165 acpi_os_free (address);
166
167 return;
168 }
169
170