]> git.proxmox.com Git - mirror_ubuntu-eoan-kernel.git/commitdiff
ACPICA: Cleanup memory allocation macros and configurability.
authorLv Zheng <lv.zheng@intel.com>
Tue, 29 Oct 2013 01:29:27 +0000 (09:29 +0800)
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>
Wed, 30 Oct 2013 11:24:21 +0000 (12:24 +0100)
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>
drivers/acpi/acpica/acmacros.h
drivers/acpi/acpica/acutils.h
drivers/acpi/acpica/utalloc.c
drivers/acpi/acpica/uttrack.c
include/acpi/acpiosxf.h
include/acpi/acpixf.h
include/acpi/actypes.h
include/acpi/platform/aclinux.h

index 530a2f8c1252da88d0598071b3f32da2bb739f1d..2a86c65d873bb6625d3a028b24d299fb2b6101ce 100644 (file)
 #define ACPI_DEBUGGER_EXEC(a)
 #endif
 
-/*
- * Memory allocation tracking (DEBUG ONLY)
- */
-#define ACPI_MEM_PARAMETERS         _COMPONENT, _acpi_module_name, __LINE__
-
-#ifndef ACPI_DBG_TRACK_ALLOCATIONS
-
-/* Memory allocation */
-
-#ifndef ACPI_ALLOCATE
-#define ACPI_ALLOCATE(a)            acpi_ut_allocate((acpi_size) (a), ACPI_MEM_PARAMETERS)
-#endif
-#ifndef ACPI_ALLOCATE_ZEROED
-#define ACPI_ALLOCATE_ZEROED(a)     acpi_ut_allocate_zeroed((acpi_size) (a), ACPI_MEM_PARAMETERS)
-#endif
-#ifndef ACPI_FREE
-#define ACPI_FREE(a)                acpi_os_free(a)
-#endif
-#define ACPI_MEM_TRACKING(a)
-
-#else
-
-/* Memory allocation */
-
-#define ACPI_ALLOCATE(a)            acpi_ut_allocate_and_track((acpi_size) (a), ACPI_MEM_PARAMETERS)
-#define ACPI_ALLOCATE_ZEROED(a)     acpi_ut_allocate_zeroed_and_track((acpi_size) (a), ACPI_MEM_PARAMETERS)
-#define ACPI_FREE(a)                acpi_ut_free_and_track(a, ACPI_MEM_PARAMETERS)
-#define ACPI_MEM_TRACKING(a)        a
-
-#endif                         /* ACPI_DBG_TRACK_ALLOCATIONS */
-
 /*
  * Macros used for ACPICA utilities only
  */
index 4f25e8f0cd5f3e78cc06a4131d0c77ae66a5a8dd..be8180c17d7e772ec520dae60dc43b514c5295c1 100644 (file)
@@ -663,12 +663,6 @@ acpi_status
 acpi_ut_initialize_buffer(struct acpi_buffer *buffer,
                          acpi_size required_length);
 
-void *acpi_ut_allocate(acpi_size size,
-                      u32 component, const char *module, u32 line);
-
-void *acpi_ut_allocate_zeroed(acpi_size size,
-                             u32 component, const char *module, u32 line);
-
 #ifdef ACPI_DBG_TRACK_ALLOCATIONS
 void *acpi_ut_allocate_and_track(acpi_size size,
                                 u32 component, const char *module, u32 line);
index e0ffb580f4b06eba27e05ad03bc55e47f9654ff6..d84479610971a6914ff95b2cfaee920f7b72496f 100644 (file)
 #define _COMPONENT          ACPI_UTILITIES
 ACPI_MODULE_NAME("utalloc")
 
+#if !defined (USE_NATIVE_ALLOCATE_ZEROED)
+/*******************************************************************************
+ *
+ * FUNCTION:    acpi_os_allocate_zeroed
+ *
+ * PARAMETERS:  size                - Size of the allocation
+ *
+ * RETURN:      Address of the allocated memory on success, NULL on failure.
+ *
+ * DESCRIPTION: Subsystem equivalent of calloc. Allocate and zero memory.
+ *              This is the default implementation. Can be overridden via the
+ *              USE_NATIVE_ALLOCATE_ZEROED flag.
+ *
+ ******************************************************************************/
+void *acpi_os_allocate_zeroed(acpi_size size)
+{
+       void *allocation;
+
+       ACPI_FUNCTION_ENTRY();
+
+       allocation = acpi_os_allocate(size);
+       if (allocation) {
+
+               /* Clear the memory block */
+
+               ACPI_MEMSET(allocation, 0, size);
+       }
+
+       return (allocation);
+}
+
+#endif                         /* !USE_NATIVE_ALLOCATE_ZEROED */
+
 /*******************************************************************************
  *
  * FUNCTION:    acpi_ut_create_caches
@@ -59,6 +92,7 @@ ACPI_MODULE_NAME("utalloc")
  * DESCRIPTION: Create all local caches
  *
  ******************************************************************************/
+
 acpi_status acpi_ut_create_caches(void)
 {
        acpi_status status;
@@ -302,82 +336,3 @@ acpi_ut_initialize_buffer(struct acpi_buffer * buffer,
        ACPI_MEMSET(buffer->pointer, 0, required_length);
        return (AE_OK);
 }
-
-#ifdef NOT_USED_BY_LINUX
-/*******************************************************************************
- *
- * FUNCTION:    acpi_ut_allocate
- *
- * PARAMETERS:  size                - Size of the allocation
- *              component           - Component type of caller
- *              module              - Source file name of caller
- *              line                - Line number of caller
- *
- * RETURN:      Address of the allocated memory on success, NULL on failure.
- *
- * DESCRIPTION: Subsystem equivalent of malloc.
- *
- ******************************************************************************/
-
-void *acpi_ut_allocate(acpi_size size,
-                      u32 component, const char *module, u32 line)
-{
-       void *allocation;
-
-       ACPI_FUNCTION_TRACE_U32(ut_allocate, size);
-
-       /* Check for an inadvertent size of zero bytes */
-
-       if (!size) {
-               ACPI_WARNING((module, line,
-                             "Attempt to allocate zero bytes, allocating 1 byte"));
-               size = 1;
-       }
-
-       allocation = acpi_os_allocate(size);
-       if (!allocation) {
-
-               /* Report allocation error */
-
-               ACPI_WARNING((module, line,
-                             "Could not allocate size %u", (u32) size));
-
-               return_PTR(NULL);
-       }
-
-       return_PTR(allocation);
-}
-
-/*******************************************************************************
- *
- * FUNCTION:    acpi_ut_allocate_zeroed
- *
- * PARAMETERS:  size                - Size of the allocation
- *              component           - Component type of caller
- *              module              - Source file name of caller
- *              line                - Line number of caller
- *
- * RETURN:      Address of the allocated memory on success, NULL on failure.
- *
- * DESCRIPTION: Subsystem equivalent of calloc. Allocate and zero memory.
- *
- ******************************************************************************/
-
-void *acpi_ut_allocate_zeroed(acpi_size size,
-                             u32 component, const char *module, u32 line)
-{
-       void *allocation;
-
-       ACPI_FUNCTION_ENTRY();
-
-       allocation = acpi_ut_allocate(size, component, module, line);
-       if (allocation) {
-
-               /* Clear the memory block */
-
-               ACPI_MEMSET(allocation, 0, size);
-       }
-
-       return (allocation);
-}
-#endif
index 160f13f4aab51a196200184c60cc625a5de4acc6..77e3eb7d7c04c5b1c6454cb124930da845999150 100644 (file)
@@ -130,10 +130,23 @@ void *acpi_ut_allocate_and_track(acpi_size size,
        struct acpi_debug_mem_block *allocation;
        acpi_status status;
 
+       /* Check for an inadvertent size of zero bytes */
+
+       if (!size) {
+               ACPI_WARNING((module, line,
+                             "Attempt to allocate zero bytes, allocating 1 byte"));
+               size = 1;
+       }
+
        allocation =
-           acpi_ut_allocate(size + sizeof(struct acpi_debug_mem_header),
-                            component, module, line);
+           acpi_os_allocate(size + sizeof(struct acpi_debug_mem_header));
        if (!allocation) {
+
+               /* Report allocation error */
+
+               ACPI_WARNING((module, line,
+                             "Could not allocate size %u", (u32)size));
+
                return (NULL);
        }
 
@@ -179,9 +192,17 @@ void *acpi_ut_allocate_zeroed_and_track(acpi_size size,
        struct acpi_debug_mem_block *allocation;
        acpi_status status;
 
+       /* Check for an inadvertent size of zero bytes */
+
+       if (!size) {
+               ACPI_WARNING((module, line,
+                             "Attempt to allocate zero bytes, allocating 1 byte"));
+               size = 1;
+       }
+
        allocation =
-           acpi_ut_allocate_zeroed(size + sizeof(struct acpi_debug_mem_header),
-                                   component, module, line);
+           acpi_os_allocate_zeroed(size +
+                                   sizeof(struct acpi_debug_mem_header));
        if (!allocation) {
 
                /* Report allocation error */
index 64b8c7639520d1e41e1439bc558d7a35424e25ef..7f95215e77543d4f3ccba67ebb69b73e69c8b5a2 100644 (file)
@@ -146,6 +146,8 @@ void acpi_os_release_mutex(acpi_mutex handle);
  */
 void *acpi_os_allocate(acpi_size size);
 
+void *acpi_os_allocate_zeroed(acpi_size size);
+
 void acpi_os_free(void *memory);
 
 void __iomem *acpi_os_map_memory(acpi_physical_address where,
index ebab0d89c70b320207fa7600285804b580e70ec6..ddde61b43041096d93e22b944805f2204c1ca254 100644 (file)
@@ -158,15 +158,6 @@ acpi_status
 acpi_decode_pld_buffer(u8 *in_buffer,
                       acpi_size length, struct acpi_pld_info **return_buffer);
 
-/*
- * ACPI Memory management
- */
-void *acpi_allocate(u32 size);
-
-void *acpi_callocate(u32 size);
-
-void acpi_free(void *address);
-
 /*
  * ACPI table load/unload interfaces
  */
index f6abf23ad0a71d51df5c86806c1b504b678a4bc1..fed5af2bcb9341f4998f2a4e68de774c631a3765 100644 (file)
@@ -306,6 +306,33 @@ typedef u32 acpi_physical_address;
 #define ACPI_EXPORT_SYMBOL(symbol)
 #endif
 
+/*******************************************************************************
+ *
+ * Configuration
+ *
+ ******************************************************************************/
+
+#ifdef ACPI_DBG_TRACK_ALLOCATIONS
+/*
+ * Memory allocation tracking (used by acpi_exec to detect memory leaks)
+ */
+#define ACPI_MEM_PARAMETERS             _COMPONENT, _acpi_module_name, __LINE__
+#define ACPI_ALLOCATE(a)                acpi_ut_allocate_and_track ((acpi_size) (a), ACPI_MEM_PARAMETERS)
+#define ACPI_ALLOCATE_ZEROED(a)         acpi_ut_allocate_zeroed_and_track ((acpi_size) (a), ACPI_MEM_PARAMETERS)
+#define ACPI_FREE(a)                    acpi_ut_free_and_track (a, ACPI_MEM_PARAMETERS)
+#define ACPI_MEM_TRACKING(a)            a
+
+#else
+/*
+ * Normal memory allocation directly via the OS services layer
+ */
+#define ACPI_ALLOCATE(a)                acpi_os_allocate ((acpi_size) (a))
+#define ACPI_ALLOCATE_ZEROED(a)         acpi_os_allocate_zeroed ((acpi_size) (a))
+#define ACPI_FREE(a)                    acpi_os_free (a)
+#define ACPI_MEM_TRACKING(a)
+
+#endif                         /* ACPI_DBG_TRACK_ALLOCATIONS */
+
 /******************************************************************************
  *
  * ACPI Specification constants (Do not change unless the specification changes)
index fda0f3e35c03fc40043cbfdba951cbe1852d9ca6..7346a9235a4c19d5d6fd0f60f22a8d719a1491e5 100644 (file)
@@ -118,6 +118,14 @@ static inline acpi_thread_id acpi_os_get_thread_id(void)
        return (acpi_thread_id)(unsigned long)current;
 }
 
+/*
+ * Memory allocation/deallocation
+ */
+
+/* Use native linux version of acpi_os_allocate_zeroed */
+
+#define USE_NATIVE_ALLOCATE_ZEROED
+
 /*
  * The irqs_disabled() check is for resume from RAM.
  * Interrupts are off during resume, just like they are for boot.
@@ -140,9 +148,10 @@ static inline void *acpi_os_acquire_object(acpi_cache_t * cache)
                irqs_disabled() ? GFP_ATOMIC : GFP_KERNEL);
 }
 
-#define ACPI_ALLOCATE(a)        acpi_os_allocate(a)
-#define ACPI_ALLOCATE_ZEROED(a) acpi_os_allocate_zeroed(a)
-#define ACPI_FREE(a)            kfree(a)
+static inline void acpi_os_free(void *a)
+{
+       kfree(a);
+}
 
 #ifndef CONFIG_PREEMPT
 /*