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