aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/acpi/acpica/utalloc.c
diff options
context:
space:
mode:
authorLv Zheng <lv.zheng@intel.com>2013-10-28 21:29:27 -0400
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>2013-10-30 07:24:21 -0400
commitb3c86c30efd83ebfa7010c5890e2ebf2678e49f8 (patch)
treef354d1d0a7a01d40345b155e3d271ca9275adb09 /drivers/acpi/acpica/utalloc.c
parent73424473d0801f7079258897901ba1edc660dbd3 (diff)
ACPICA: Cleanup memory allocation macros and configurability.
In the common case, the ACPI_ALLOCATE and related macros now resolve directly to their respective acpi_os* OSL interfaces. Two options: 1) The ACPI_ALLOCATE_ZEROED macro defaults to a simple local implementation by default, unless overridden by the USE_NATIVE_ALLOCATE_ZEROED define. 2) For ACPI execution simulation environment (AcpiExec) which is not shipped with the Linux kernel, the macros can optionally be resolved to the local interfaces that track each allocation (used to immediately detect memory leaks). Signed-off-by: Lv Zheng <lv.zheng@intel.com> Signed-off-by: Bob Moore <robert.moore@intel.com> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Diffstat (limited to 'drivers/acpi/acpica/utalloc.c')
-rw-r--r--drivers/acpi/acpica/utalloc.c113
1 files changed, 34 insertions, 79 deletions
diff --git a/drivers/acpi/acpica/utalloc.c b/drivers/acpi/acpica/utalloc.c
index e0ffb580f4b0..d84479610971 100644
--- a/drivers/acpi/acpica/utalloc.c
+++ b/drivers/acpi/acpica/utalloc.c
@@ -48,6 +48,39 @@
48#define _COMPONENT ACPI_UTILITIES 48#define _COMPONENT ACPI_UTILITIES
49ACPI_MODULE_NAME("utalloc") 49ACPI_MODULE_NAME("utalloc")
50 50
51#if !defined (USE_NATIVE_ALLOCATE_ZEROED)
52/*******************************************************************************
53 *
54 * FUNCTION: acpi_os_allocate_zeroed
55 *
56 * PARAMETERS: size - Size of the allocation
57 *
58 * RETURN: Address of the allocated memory on success, NULL on failure.
59 *
60 * DESCRIPTION: Subsystem equivalent of calloc. Allocate and zero memory.
61 * This is the default implementation. Can be overridden via the
62 * USE_NATIVE_ALLOCATE_ZEROED flag.
63 *
64 ******************************************************************************/
65void *acpi_os_allocate_zeroed(acpi_size size)
66{
67 void *allocation;
68
69 ACPI_FUNCTION_ENTRY();
70
71 allocation = acpi_os_allocate(size);
72 if (allocation) {
73
74 /* Clear the memory block */
75
76 ACPI_MEMSET(allocation, 0, size);
77 }
78
79 return (allocation);
80}
81
82#endif /* !USE_NATIVE_ALLOCATE_ZEROED */
83
51/******************************************************************************* 84/*******************************************************************************
52 * 85 *
53 * FUNCTION: acpi_ut_create_caches 86 * FUNCTION: acpi_ut_create_caches
@@ -59,6 +92,7 @@ ACPI_MODULE_NAME("utalloc")
59 * DESCRIPTION: Create all local caches 92 * DESCRIPTION: Create all local caches
60 * 93 *
61 ******************************************************************************/ 94 ******************************************************************************/
95
62acpi_status acpi_ut_create_caches(void) 96acpi_status acpi_ut_create_caches(void)
63{ 97{
64 acpi_status status; 98 acpi_status status;
@@ -302,82 +336,3 @@ acpi_ut_initialize_buffer(struct acpi_buffer * buffer,
302 ACPI_MEMSET(buffer->pointer, 0, required_length); 336 ACPI_MEMSET(buffer->pointer, 0, required_length);
303 return (AE_OK); 337 return (AE_OK);
304} 338}
305
306#ifdef NOT_USED_BY_LINUX
307/*******************************************************************************
308 *
309 * FUNCTION: acpi_ut_allocate
310 *
311 * PARAMETERS: size - Size of the allocation
312 * component - Component type of caller
313 * module - Source file name of caller
314 * line - Line number of caller
315 *
316 * RETURN: Address of the allocated memory on success, NULL on failure.
317 *
318 * DESCRIPTION: Subsystem equivalent of malloc.
319 *
320 ******************************************************************************/
321
322void *acpi_ut_allocate(acpi_size size,
323 u32 component, const char *module, u32 line)
324{
325 void *allocation;
326
327 ACPI_FUNCTION_TRACE_U32(ut_allocate, size);
328
329 /* Check for an inadvertent size of zero bytes */
330
331 if (!size) {
332 ACPI_WARNING((module, line,
333 "Attempt to allocate zero bytes, allocating 1 byte"));
334 size = 1;
335 }
336
337 allocation = acpi_os_allocate(size);
338 if (!allocation) {
339
340 /* Report allocation error */
341
342 ACPI_WARNING((module, line,
343 "Could not allocate size %u", (u32) size));
344
345 return_PTR(NULL);
346 }
347
348 return_PTR(allocation);
349}
350
351/*******************************************************************************
352 *
353 * FUNCTION: acpi_ut_allocate_zeroed
354 *
355 * PARAMETERS: size - Size of the allocation
356 * component - Component type of caller
357 * module - Source file name of caller
358 * line - Line number of caller
359 *
360 * RETURN: Address of the allocated memory on success, NULL on failure.
361 *
362 * DESCRIPTION: Subsystem equivalent of calloc. Allocate and zero memory.
363 *
364 ******************************************************************************/
365
366void *acpi_ut_allocate_zeroed(acpi_size size,
367 u32 component, const char *module, u32 line)
368{
369 void *allocation;
370
371 ACPI_FUNCTION_ENTRY();
372
373 allocation = acpi_ut_allocate(size, component, module, line);
374 if (allocation) {
375
376 /* Clear the memory block */
377
378 ACPI_MEMSET(allocation, 0, size);
379 }
380
381 return (allocation);
382}
383#endif