diff options
author | Angela Stegmaier | 2019-09-17 15:50:01 -0500 |
---|---|---|
committer | Angela Stegmaier | 2019-09-23 10:49:59 -0500 |
commit | d3ea1ddc11bebc1a09baad9dda15f999555b7d82 (patch) | |
tree | 306d76223f22ddc90e7af304bb027984be7cbcab | |
parent | 3f88dd2e8b1ea444718b0ef10941c4e6d9a13d4a (diff) | |
download | ti-img-encode-decode-d3ea1ddc11bebc1a09baad9dda15f999555b7d82.tar.gz ti-img-encode-decode-d3ea1ddc11bebc1a09baad9dda15f999555b7d82.tar.xz ti-img-encode-decode-d3ea1ddc11bebc1a09baad9dda15f999555b7d82.zip |
decoder: Add resource leak debugging
Add code to track the allocations and frees through
the osa_mem module. By default, the memory debug tracking
is disabled in the makefile. To enable, set DEBUG_OSA_MEM
to "y":
DEBUG_OSA_MEM=y
When osa_mem debug tracing is enabled, whenever a handle
is closed or the module is removed, debug traces will print
showing outstanding allocations.
Signed-off-by: Gaviraju D B <x1046101@ti.com>
Signed-off-by: Angela Stegmaier <angelabaker@ti.com>
-rw-r--r-- | linux/decoder/Makefile | 10 | ||||
-rw-r--r-- | linux/decoder/vxd_v4l2.c | 13 | ||||
-rw-r--r-- | osal/inc/osa_mem.h | 46 | ||||
-rw-r--r-- | osal/src/linux/osa_atomic.c | 5 | ||||
-rw-r--r-- | osal/src/linux/osa_firmware.c | 3 | ||||
-rw-r--r-- | osal/src/linux/osa_idr.c | 5 | ||||
-rw-r--r-- | osal/src/linux/osa_mem.c | 136 | ||||
-rw-r--r-- | osal/src/linux/osa_mutex.c | 5 | ||||
-rw-r--r-- | osal/src/linux/osa_spin.c | 5 | ||||
-rw-r--r-- | osal/src/linux/osa_time.c | 5 | ||||
-rw-r--r-- | osal/src/linux/osa_workqueue.c | 29 |
11 files changed, 228 insertions, 34 deletions
diff --git a/linux/decoder/Makefile b/linux/decoder/Makefile index 5bbfffe..7b26228 100644 --- a/linux/decoder/Makefile +++ b/linux/decoder/Makefile | |||
@@ -57,6 +57,12 @@ ERROR_RECOVERY_SIMULATION ?=n | |||
57 | # If unsure, say Y | 57 | # If unsure, say Y |
58 | CAPTURE_CONTIG_ALLOC ?=y | 58 | CAPTURE_CONTIG_ALLOC ?=y |
59 | 59 | ||
60 | # (8) | ||
61 | # This config enables debugging of memory allocations through the | ||
62 | # osa mem module. | ||
63 | # If unsure, say N | ||
64 | DEBUG_OSA_MEM ?=n | ||
65 | |||
60 | #VXD | 66 | #VXD |
61 | vxd-dec-objs += $(DRIVER_PATH)/decoder/vxd_core.o | 67 | vxd-dec-objs += $(DRIVER_PATH)/decoder/vxd_core.o |
62 | 68 | ||
@@ -147,6 +153,10 @@ ifeq ($(CAPTURE_CONTIG_ALLOC),y) | |||
147 | ccflags-y += -DCAPTURE_CONTIG_ALLOC | 153 | ccflags-y += -DCAPTURE_CONTIG_ALLOC |
148 | endif | 154 | endif |
149 | 155 | ||
156 | ifeq ($(DEBUG_OSA_MEM),y) | ||
157 | ccflags-y += -DDEBUG_OSA_MEM | ||
158 | endif | ||
159 | |||
150 | ccflags-y += -DOSAL_LINUX | 160 | ccflags-y += -DOSAL_LINUX |
151 | 161 | ||
152 | obj-$(CONFIG_VIDEO_IMG_VXD_DEC) += vxd-dec.o | 162 | obj-$(CONFIG_VIDEO_IMG_VXD_DEC) += vxd-dec.o |
diff --git a/linux/decoder/vxd_v4l2.c b/linux/decoder/vxd_v4l2.c index a076975..fcb487a 100644 --- a/linux/decoder/vxd_v4l2.c +++ b/linux/decoder/vxd_v4l2.c | |||
@@ -54,6 +54,7 @@ | |||
54 | #include "osal/inc/osa_idr.h" | 54 | #include "osal/inc/osa_idr.h" |
55 | #include "osal/inc/osa_define.h" | 55 | #include "osal/inc/osa_define.h" |
56 | #include "osal/inc/osa_page.h" | 56 | #include "osal/inc/osa_page.h" |
57 | #include "osal/inc/osa_delay.h" | ||
57 | 58 | ||
58 | #define VXD_DEC_SPIN_LOCK_NAME "vxd-dec" | 59 | #define VXD_DEC_SPIN_LOCK_NAME "vxd-dec" |
59 | #define IMG_VXD_DEC_MODULE_NAME "vxd-dec" | 60 | #define IMG_VXD_DEC_MODULE_NAME "vxd-dec" |
@@ -1076,6 +1077,12 @@ static int32 vxd_dec_release(struct file *file) | |||
1076 | osa_free(ctx); | 1077 | osa_free(ctx); |
1077 | 1078 | ||
1078 | osa_mutex_unlock(vxd->mutex); | 1079 | osa_mutex_unlock(vxd->mutex); |
1080 | |||
1081 | #ifdef DEBUG_OSA_MEM | ||
1082 | OSA_PR_ERR("##### At the end of vxd_dec_release #####"); | ||
1083 | osa_print_mem_leak(); | ||
1084 | #endif | ||
1085 | |||
1079 | return ret; | 1086 | return ret; |
1080 | } | 1087 | } |
1081 | 1088 | ||
@@ -2082,6 +2089,12 @@ static int32 vxd_dec_remove(struct platform_device *pdev) | |||
2082 | osa_free(vxd->dwork); | 2089 | osa_free(vxd->dwork); |
2083 | osa_mutex_destroy(&vxd->mutex); | 2090 | osa_mutex_destroy(&vxd->mutex); |
2084 | 2091 | ||
2092 | #ifdef DEBUG_OSA_MEM | ||
2093 | osa_msleep(500); | ||
2094 | OSA_PR_ERR("##### At the end of vxd_dec_remove #####"); | ||
2095 | osa_print_mem_leak(); | ||
2096 | #endif | ||
2097 | |||
2085 | video_unregister_device(vxd->vfd_dec); | 2098 | video_unregister_device(vxd->vfd_dec); |
2086 | v4l2_m2m_release(vxd->m2m_dev); | 2099 | v4l2_m2m_release(vxd->m2m_dev); |
2087 | v4l2_device_unregister(&vxd->v4l2_dev); | 2100 | v4l2_device_unregister(&vxd->v4l2_dev); |
diff --git a/osal/inc/osa_mem.h b/osal/inc/osa_mem.h index 3e23142..721fd00 100644 --- a/osal/inc/osa_mem.h +++ b/osal/inc/osa_mem.h | |||
@@ -23,13 +23,29 @@ | |||
23 | #define osa_container_of(ptr, type, member) (type *)((int8 *)ptr - ((size_t)&(((type *)0)->member))) | 23 | #define osa_container_of(ptr, type, member) (type *)((int8 *)ptr - ((size_t)&(((type *)0)->member))) |
24 | #define OSA_ALIGN(x, a, type) (((x) + ((type)(a) - 1)) & ~((type)(a) - 1)) | 24 | #define OSA_ALIGN(x, a, type) (((x) + ((type)(a) - 1)) & ~((type)(a) - 1)) |
25 | 25 | ||
26 | #ifdef DEBUG_OSA_MEM | ||
27 | struct memory_release { | ||
28 | uint8 flag; | ||
29 | void *ptr; | ||
30 | uint8 func[200]; | ||
31 | uint32 line; | ||
32 | uint32 size; | ||
33 | }; | ||
34 | void osa_print_mem_leak(void); | ||
35 | #endif | ||
36 | |||
26 | /** | 37 | /** |
27 | * osa_calloc - allocate memory for an array. The memory is set to zero. | 38 | * osa_calloc - allocate memory for an array. The memory is set to zero. |
28 | * @n: number of elements. | 39 | * @n: number of elements. |
29 | * @size: element size. | 40 | * @size: element size. |
30 | * @flags: the type of memory to allocate (see osa_malloc). | 41 | * @flags: the type of memory to allocate (see osa_malloc). |
31 | */ | 42 | */ |
43 | #ifdef DEBUG_OSA_MEM | ||
44 | #define osa_calloc(a,b,c) osa_calloc_debug(a,b,c,__func__,__LINE__) | ||
45 | void *osa_calloc_debug(uint64 n, uint64 size, int64 flags, const uint8 *func, uint32 line); | ||
46 | #else | ||
32 | void *osa_calloc(uint64 n, uint64 size, int64 flags); | 47 | void *osa_calloc(uint64 n, uint64 size, int64 flags); |
48 | #endif | ||
33 | 49 | ||
34 | /** | 50 | /** |
35 | * osa_malloc - allocate memory | 51 | * osa_malloc - allocate memory |
@@ -59,7 +75,12 @@ void *osa_calloc(uint64 n, uint64 size, int64 flags); | |||
59 | * %OSA_GFP_DMA - Allocation suitable for DMA. | 75 | * %OSA_GFP_DMA - Allocation suitable for DMA. |
60 | * Should only be used for osa_malloc() caches. | 76 | * Should only be used for osa_malloc() caches. |
61 | */ | 77 | */ |
78 | #ifdef DEBUG_OSA_MEM | ||
79 | #define osa_malloc(a,b) osa_malloc_debug(a,b,__func__,__LINE__) | ||
80 | void *osa_malloc_debug(uint64 size, int64 flags, const uint8 *func, uint32 line); | ||
81 | #else | ||
62 | void *osa_malloc(uint64 size, int64 flags); | 82 | void *osa_malloc(uint64 size, int64 flags); |
83 | #endif | ||
63 | 84 | ||
64 | /** | 85 | /** |
65 | * osa_realloc - reallocate memory. The contents will remain unchanged. | 86 | * osa_realloc - reallocate memory. The contents will remain unchanged. |
@@ -83,14 +104,24 @@ void *osa_realloc(const void *p, uint64 new_size, int64 flags); | |||
83 | * Don't free memory not originally allocated by osa_malloc() | 104 | * Don't free memory not originally allocated by osa_malloc() |
84 | * or you will run into trouble. | 105 | * or you will run into trouble. |
85 | */ | 106 | */ |
107 | #ifdef DEBUG_OSA_MEM | ||
108 | #define osa_free(a) osa_free_debug(a, __func__, __LINE__) | ||
109 | void osa_free_debug(const void *objp, const uint8 *func, uint32 line); | ||
110 | #else | ||
86 | void osa_free(const void *objp); | 111 | void osa_free(const void *objp); |
112 | #endif | ||
87 | 113 | ||
88 | /** | 114 | /** |
89 | * osa_zalloc - allocate memory. The memory is set to zero. | 115 | * osa_zalloc - allocate memory. The memory is set to zero. |
90 | * @size: how many bytes of memory are required. | 116 | * @size: how many bytes of memory are required. |
91 | * @flags: the type of memory to allocate (see osa_malloc). | 117 | * @flags: the type of memory to allocate (see osa_malloc). |
92 | */ | 118 | */ |
119 | #ifdef DEBUG_OSA_MEM | ||
120 | #define osa_zalloc(a,b) osa_zalloc_debug(a,b,__func__,__LINE__) | ||
121 | void *osa_zalloc_debug(uint64 size, int64 flags, const uint8 *func, uint32 line); | ||
122 | #else | ||
93 | void *osa_zalloc(uint64 size, int64 flags); | 123 | void *osa_zalloc(uint64 size, int64 flags); |
124 | #endif | ||
94 | 125 | ||
95 | /** | 126 | /** |
96 | * osa_malloc_array - allocate memory for an array. | 127 | * osa_malloc_array - allocate memory for an array. |
@@ -98,14 +129,24 @@ void *osa_zalloc(uint64 size, int64 flags); | |||
98 | * @size: element size. | 129 | * @size: element size. |
99 | * @flags: the type of memory to allocate (see osa_malloc). | 130 | * @flags: the type of memory to allocate (see osa_malloc). |
100 | */ | 131 | */ |
132 | #ifdef DEBUG_OSA_MEM | ||
133 | #define osa_malloc_array(a,b,c) osa_malloc_array_debug(a,b,c,__func__,__LINE__) | ||
134 | void *osa_malloc_array_debug(size_t n, size_t size, int64 flags, const uint8 *func, uint32 line); | ||
135 | #else | ||
101 | void *osa_malloc_array(size_t n, size_t size, int64 flags); | 136 | void *osa_malloc_array(size_t n, size_t size, int64 flags); |
137 | #endif | ||
102 | 138 | ||
103 | /** | 139 | /** |
104 | * osa_strdup - allocate space and copy an existing string. | 140 | * osa_strdup - allocate space and copy an existing string. |
105 | * @s: The string to duplicate | 141 | * @s: The string to duplicate |
106 | * @flags: the type of memory to allocate (see osa_malloc). | 142 | * @flags: the type of memory to allocate (see osa_malloc). |
107 | */ | 143 | */ |
144 | #ifdef DEBUG_OSA_MEM | ||
145 | #define osa_strdup(a,b) osa_strdup_debug(a,b,__func__,__LINE__) | ||
146 | int8 *osa_strdup_debug(const int8 *s, int64 flags, const uint8 *func, uint32 line); | ||
147 | #else | ||
108 | int8 *osa_strdup(const int8 *s, int64 flags); | 148 | int8 *osa_strdup(const int8 *s, int64 flags); |
149 | #endif | ||
109 | 150 | ||
110 | /** | 151 | /** |
111 | * osa_memdup - duplicate region of memory | 152 | * osa_memdup - duplicate region of memory |
@@ -114,7 +155,12 @@ int8 *osa_strdup(const int8 *s, int64 flags); | |||
114 | * @len: memory region length | 155 | * @len: memory region length |
115 | * @gfp: mask to use | 156 | * @gfp: mask to use |
116 | */ | 157 | */ |
158 | #ifdef DEBUG_OSA_MEM | ||
159 | #define osa_memdup(a,b,c) osa_memdup_debug(a,b,c,__func__,__LINE__) | ||
160 | void *osa_memdup_debug(const void *src, size_t len, int64 flags, const uint8 *func, uint32 line); | ||
161 | #else | ||
117 | void *osa_memdup(const void *src, size_t len, int64 flags); | 162 | void *osa_memdup(const void *src, size_t len, int64 flags); |
163 | #endif | ||
118 | 164 | ||
119 | /** | 165 | /** |
120 | * osa_vmap - map an array of pages into virtually contiguous space | 166 | * osa_vmap - map an array of pages into virtually contiguous space |
diff --git a/osal/src/linux/osa_atomic.c b/osal/src/linux/osa_atomic.c index 4ba4ff8..3336f96 100644 --- a/osal/src/linux/osa_atomic.c +++ b/osal/src/linux/osa_atomic.c | |||
@@ -19,13 +19,14 @@ | |||
19 | #include <linux/printk.h> | 19 | #include <linux/printk.h> |
20 | #include <asm/atomic.h> | 20 | #include <asm/atomic.h> |
21 | #include "../../inc/osa_atomic.h" | 21 | #include "../../inc/osa_atomic.h" |
22 | #include "../../inc/osa_mem.h" | ||
22 | #include "img_errors.h" | 23 | #include "img_errors.h" |
23 | 24 | ||
24 | 25 | ||
25 | int32 osa_atomic_create(void **atomic_args) | 26 | int32 osa_atomic_create(void **atomic_args) |
26 | { | 27 | { |
27 | atomic_t **obj = (atomic_t **)atomic_args; | 28 | atomic_t **obj = (atomic_t **)atomic_args; |
28 | *obj = kzalloc(sizeof(atomic_t), GFP_KERNEL); | 29 | *obj = osa_zalloc(sizeof(atomic_t), GFP_KERNEL); |
29 | if (NULL == *obj) { | 30 | if (NULL == *obj) { |
30 | pr_err("Memory allocation failed for atomic\n"); | 31 | pr_err("Memory allocation failed for atomic\n"); |
31 | return IMG_ERROR_OUT_OF_MEMORY; | 32 | return IMG_ERROR_OUT_OF_MEMORY; |
@@ -41,7 +42,7 @@ void osa_atomic_destroy(void **atomic_args) | |||
41 | pr_err("Invalid atomic object\n"); | 42 | pr_err("Invalid atomic object\n"); |
42 | return; | 43 | return; |
43 | } | 44 | } |
44 | kfree(*obj); | 45 | osa_free(*obj); |
45 | *obj = NULL; | 46 | *obj = NULL; |
46 | } | 47 | } |
47 | 48 | ||
diff --git a/osal/src/linux/osa_firmware.c b/osal/src/linux/osa_firmware.c index 871539d..bcb17d6 100644 --- a/osal/src/linux/osa_firmware.c +++ b/osal/src/linux/osa_firmware.c | |||
@@ -20,13 +20,14 @@ | |||
20 | #include <linux/slab.h> | 20 | #include <linux/slab.h> |
21 | 21 | ||
22 | #include "../../inc/osa_firmware.h" | 22 | #include "../../inc/osa_firmware.h" |
23 | #include "../../inc/osa_mem.h" | ||
23 | 24 | ||
24 | void osa_init_completion(void **firmware_loading_complete_args) | 25 | void osa_init_completion(void **firmware_loading_complete_args) |
25 | { | 26 | { |
26 | struct completion ** firmware_loading_complete = | 27 | struct completion ** firmware_loading_complete = |
27 | (struct completion **) firmware_loading_complete_args; | 28 | (struct completion **) firmware_loading_complete_args; |
28 | 29 | ||
29 | *firmware_loading_complete = kmalloc(sizeof(struct completion), GFP_KERNEL); | 30 | *firmware_loading_complete = osa_malloc(sizeof(struct completion), GFP_KERNEL); |
30 | if(NULL == *firmware_loading_complete) | 31 | if(NULL == *firmware_loading_complete) |
31 | { | 32 | { |
32 | pr_err("Memory allocation failed for osa_init_completion\n"); | 33 | pr_err("Memory allocation failed for osa_init_completion\n"); |
diff --git a/osal/src/linux/osa_idr.c b/osal/src/linux/osa_idr.c index e429109..83f734b 100644 --- a/osal/src/linux/osa_idr.c +++ b/osal/src/linux/osa_idr.c | |||
@@ -19,6 +19,7 @@ | |||
19 | #include <linux/slab.h> | 19 | #include <linux/slab.h> |
20 | 20 | ||
21 | #include "../../inc/osa_idr.h" | 21 | #include "../../inc/osa_idr.h" |
22 | #include "../../inc/osa_mem.h" | ||
22 | 23 | ||
23 | 24 | ||
24 | int32 osa_idr_alloc(void *idr, void *ptr, int32 start, int32 end) | 25 | int32 osa_idr_alloc(void *idr, void *ptr, int32 start, int32 end) |
@@ -49,13 +50,13 @@ void *osa_idr_get_next(void *idr, int32 *nextid) | |||
49 | void osa_idr_destroy(void *idr) | 50 | void osa_idr_destroy(void *idr) |
50 | { | 51 | { |
51 | idr_destroy(idr); | 52 | idr_destroy(idr); |
52 | kfree(idr); | 53 | osa_free(idr); |
53 | } | 54 | } |
54 | 55 | ||
55 | void osa_idr_init(void **idr_args) | 56 | void osa_idr_init(void **idr_args) |
56 | { | 57 | { |
57 | struct idr **idr = (struct idr **)idr_args; | 58 | struct idr **idr = (struct idr **)idr_args; |
58 | *idr = kzalloc(sizeof(struct idr), GFP_KERNEL); | 59 | *idr = osa_zalloc(sizeof(struct idr), GFP_KERNEL); |
59 | if (NULL == *idr) | 60 | if (NULL == *idr) |
60 | { | 61 | { |
61 | pr_err("Memory allocation failed for idr\n"); | 62 | pr_err("Memory allocation failed for idr\n"); |
diff --git a/osal/src/linux/osa_mem.c b/osal/src/linux/osa_mem.c index fb7b33d..8da7758 100644 --- a/osal/src/linux/osa_mem.c +++ b/osal/src/linux/osa_mem.c | |||
@@ -20,15 +20,96 @@ | |||
20 | #include <linux/dma-mapping.h> | 20 | #include <linux/dma-mapping.h> |
21 | 21 | ||
22 | #include "../../inc/osa_mem.h" | 22 | #include "../../inc/osa_mem.h" |
23 | #include "../../inc/osa_define.h" | ||
23 | 24 | ||
25 | #ifdef DEBUG_OSA_MEM | ||
26 | DEFINE_MUTEX(lock); | ||
27 | #define MAX_NUM_RESOURCES 5000 | ||
28 | static struct memory_release resource[MAX_NUM_RESOURCES] = {0}; | ||
29 | static uint32 count = 0; | ||
30 | |||
31 | void osa_save_mem(void *ptr, uint32 size, const uint8 *func, uint32 line) | ||
32 | { | ||
33 | uint32 i = 0; | ||
34 | |||
35 | mutex_lock(&lock); | ||
36 | for (i = 0; i < MAX_NUM_RESOURCES; i++) { | ||
37 | if (0 == resource[i].flag) { | ||
38 | resource[i].flag = 1; | ||
39 | strcpy(resource[i].func, func); | ||
40 | resource[i].line = line; | ||
41 | resource[i].ptr = ptr; | ||
42 | resource[i].size = size; | ||
43 | count++; | ||
44 | mutex_unlock(&lock); | ||
45 | return; | ||
46 | } | ||
47 | } | ||
48 | mutex_unlock(&lock); | ||
49 | OSA_PR_ERR("##### NO MEMORY #######\n"); | ||
50 | } | ||
51 | |||
52 | void osa_remove_mem(void *ptr, const uint8 *func, uint32 line) | ||
53 | { | ||
54 | uint32 i = 0; | ||
55 | |||
56 | mutex_lock(&lock); | ||
57 | for (i = 0; i < MAX_NUM_RESOURCES; i++) { | ||
58 | if (1 == resource[i].flag) { | ||
59 | if (ptr == resource[i].ptr) { | ||
60 | resource[i].flag = 0; | ||
61 | count--; | ||
62 | mutex_unlock(&lock); | ||
63 | return; | ||
64 | } | ||
65 | } | ||
66 | } | ||
67 | mutex_unlock(&lock); | ||
68 | OSA_PR_ERR("##### INVALID ADDRESS ####### [0x%llx] function_name = %s line_no = %d\n", | ||
69 | (uint64)ptr, func, line); | ||
70 | } | ||
71 | |||
72 | void osa_print_mem_leak() | ||
73 | { | ||
74 | uint32 i = 0; | ||
75 | |||
76 | OSA_PR_ERR("##### printing %d outstanding allocations #####\n", count); | ||
77 | for (i = 0; i < MAX_NUM_RESOURCES; i++) { | ||
78 | if (1 == resource[i].flag) { | ||
79 | OSA_PR_ERR("function_name = %s, line_no = %d, ptr = 0x%llx, size = %d\n", | ||
80 | resource[i].func, resource[i].line, (uint64)resource[i].ptr, | ||
81 | resource[i].size); | ||
82 | } | ||
83 | } | ||
84 | } | ||
85 | #endif | ||
86 | |||
87 | #ifdef DEBUG_OSA_MEM | ||
88 | void *osa_calloc_debug(uint64 n, uint64 size, int64 flags, const uint8 *func, uint32 line) | ||
89 | #else | ||
24 | void *osa_calloc(uint64 n, uint64 size, int64 flags) | 90 | void *osa_calloc(uint64 n, uint64 size, int64 flags) |
91 | #endif | ||
25 | { | 92 | { |
26 | return kcalloc(n, size, flags); | 93 | void *data = NULL; |
94 | data = kcalloc(n, size, flags); | ||
95 | #ifdef DEBUG_OSA_MEM | ||
96 | osa_save_mem(data, size * n, func, line); | ||
97 | #endif | ||
98 | return data; | ||
27 | } | 99 | } |
28 | 100 | ||
101 | #ifdef DEBUG_OSA_MEM | ||
102 | void *osa_malloc_debug(uint64 size, int64 flags, const uint8 *func, uint32 line) | ||
103 | #else | ||
29 | void *osa_malloc(uint64 size, int64 flags) | 104 | void *osa_malloc(uint64 size, int64 flags) |
105 | #endif | ||
30 | { | 106 | { |
31 | return kmalloc(size, flags); | 107 | void *data = NULL; |
108 | data = kmalloc(size, flags); | ||
109 | #ifdef DEBUG_OSA_MEM | ||
110 | osa_save_mem(data, size, func, line); | ||
111 | #endif | ||
112 | return data; | ||
32 | } | 113 | } |
33 | 114 | ||
34 | void *osa_realloc(const void *p, uint64 new_size, int64 flags) | 115 | void *osa_realloc(const void *p, uint64 new_size, int64 flags) |
@@ -36,29 +117,72 @@ void *osa_realloc(const void *p, uint64 new_size, int64 flags) | |||
36 | return krealloc(p, new_size, flags); | 117 | return krealloc(p, new_size, flags); |
37 | } | 118 | } |
38 | 119 | ||
120 | #ifdef DEBUG_OSA_MEM | ||
121 | void osa_free_debug(const void *objp, const uint8 *func, uint32 line) | ||
122 | #else | ||
39 | void osa_free(const void *objp) | 123 | void osa_free(const void *objp) |
124 | #endif | ||
40 | { | 125 | { |
126 | #ifdef DEBUG_OSA_MEM | ||
127 | osa_remove_mem((void *)objp, func, line); | ||
128 | #endif | ||
41 | return kfree(objp); | 129 | return kfree(objp); |
42 | } | 130 | } |
43 | 131 | ||
132 | #ifdef DEBUG_OSA_MEM | ||
133 | void *osa_zalloc_debug(uint64 size, int64 flags, const uint8 *func, uint32 line) | ||
134 | #else | ||
44 | void *osa_zalloc(uint64 size, int64 flags) | 135 | void *osa_zalloc(uint64 size, int64 flags) |
136 | #endif | ||
45 | { | 137 | { |
46 | return kzalloc(size, flags); | 138 | void *data = NULL; |
139 | data = kzalloc(size, flags); | ||
140 | #ifdef DEBUG_OSA_MEM | ||
141 | osa_save_mem(data, size, func, line); | ||
142 | #endif | ||
143 | return data; | ||
47 | } | 144 | } |
48 | 145 | ||
146 | #ifdef DEBUG_OSA_MEM | ||
147 | void *osa_malloc_array_debug(size_t n, size_t size, int64 flags, const uint8 *func, uint32 line) | ||
148 | #else | ||
49 | void *osa_malloc_array(size_t n, size_t size, int64 flags) | 149 | void *osa_malloc_array(size_t n, size_t size, int64 flags) |
150 | #endif | ||
50 | { | 151 | { |
51 | return kmalloc_array(n, size, flags); | 152 | void *data = NULL; |
153 | data = kmalloc_array(n, size, flags); | ||
154 | #ifdef DEBUG_OSA_MEM | ||
155 | osa_save_mem(data, n * size, func, line); | ||
156 | #endif | ||
157 | return data; | ||
52 | } | 158 | } |
53 | 159 | ||
160 | #ifdef DEBUG_OSA_MEM | ||
161 | int8 *osa_strdup_debug(const int8 *s, int64 flags, const uint8 *func, uint32 line) | ||
162 | #else | ||
54 | int8 *osa_strdup(const int8 *s, int64 flags) | 163 | int8 *osa_strdup(const int8 *s, int64 flags) |
164 | #endif | ||
55 | { | 165 | { |
56 | return kstrdup(s, flags); | 166 | void *data = NULL; |
167 | data = kstrdup(s, flags); | ||
168 | #ifdef DEBUG_OSA_MEM | ||
169 | osa_save_mem(data, strlen(s), func, line); | ||
170 | #endif | ||
171 | return data; | ||
57 | } | 172 | } |
58 | 173 | ||
174 | #ifdef DEBUG_OSA_MEM | ||
175 | void *osa_memdup_debug(const void *src, size_t len, int64 flags, const uint8 *func, uint32 line) | ||
176 | #else | ||
59 | void *osa_memdup(const void *src, size_t len, int64 flags) | 177 | void *osa_memdup(const void *src, size_t len, int64 flags) |
178 | #endif | ||
60 | { | 179 | { |
61 | return kmemdup(src, len, flags); | 180 | void *data = NULL; |
181 | data = kmemdup(src, len, flags); | ||
182 | #ifdef DEBUG_OSA_MEM | ||
183 | osa_save_mem(data, len, func, line); | ||
184 | #endif | ||
185 | return data; | ||
62 | } | 186 | } |
63 | 187 | ||
64 | void *osa_vmap(void **pages, uint32 count) | 188 | void *osa_vmap(void **pages, uint32 count) |
diff --git a/osal/src/linux/osa_mutex.c b/osal/src/linux/osa_mutex.c index eebbfbb..02252ce 100644 --- a/osal/src/linux/osa_mutex.c +++ b/osal/src/linux/osa_mutex.c | |||
@@ -19,12 +19,13 @@ | |||
19 | #include <linux/printk.h> | 19 | #include <linux/printk.h> |
20 | #include <linux/mutex.h> | 20 | #include <linux/mutex.h> |
21 | #include "../../inc/osa_mutex.h" | 21 | #include "../../inc/osa_mutex.h" |
22 | #include "../../inc/osa_mem.h" | ||
22 | 23 | ||
23 | 24 | ||
24 | void osa_mutex_create(void **mutex_args) | 25 | void osa_mutex_create(void **mutex_args) |
25 | { | 26 | { |
26 | struct mutex **mutex = (struct mutex **)mutex_args; | 27 | struct mutex **mutex = (struct mutex **)mutex_args; |
27 | *mutex = kzalloc(sizeof(struct mutex), GFP_KERNEL); | 28 | *mutex = osa_zalloc(sizeof(struct mutex), GFP_KERNEL); |
28 | if (NULL == *mutex) | 29 | if (NULL == *mutex) |
29 | { | 30 | { |
30 | pr_err("Memory allocation failed for mutex\n"); | 31 | pr_err("Memory allocation failed for mutex\n"); |
@@ -47,7 +48,7 @@ void osa_mutex_destroy(void **mutex_args) | |||
47 | { | 48 | { |
48 | struct mutex **mutex = (struct mutex **)mutex_args; | 49 | struct mutex **mutex = (struct mutex **)mutex_args; |
49 | mutex_destroy(*mutex); | 50 | mutex_destroy(*mutex); |
50 | kfree(*mutex); | 51 | osa_free(*mutex); |
51 | *mutex = NULL; | 52 | *mutex = NULL; |
52 | } | 53 | } |
53 | 54 | ||
diff --git a/osal/src/linux/osa_spin.c b/osal/src/linux/osa_spin.c index bc40de7..367ed6c 100644 --- a/osal/src/linux/osa_spin.c +++ b/osal/src/linux/osa_spin.c | |||
@@ -20,13 +20,14 @@ | |||
20 | #include <linux/slab.h> | 20 | #include <linux/slab.h> |
21 | 21 | ||
22 | #include "../../inc/osa_spin.h" | 22 | #include "../../inc/osa_spin.h" |
23 | #include "../../inc/osa_mem.h" | ||
23 | 24 | ||
24 | 25 | ||
25 | 26 | ||
26 | void osa_spin_lock_create(void **lock_args, const int8 *name) | 27 | void osa_spin_lock_create(void **lock_args, const int8 *name) |
27 | { | 28 | { |
28 | spinlock_t **lock = (spinlock_t **)lock_args; | 29 | spinlock_t **lock = (spinlock_t **)lock_args; |
29 | *lock = kzalloc(sizeof(spinlock_t), GFP_KERNEL); | 30 | *lock = osa_zalloc(sizeof(spinlock_t), GFP_KERNEL); |
30 | if (NULL == *lock) | 31 | if (NULL == *lock) |
31 | { | 32 | { |
32 | pr_err("Memory allocation failed for spin-lock\n"); | 33 | pr_err("Memory allocation failed for spin-lock\n"); |
@@ -80,6 +81,6 @@ void osa_spin_unlock_irq(void *lock) | |||
80 | 81 | ||
81 | void osa_spin_destroy(void **lock_args) | 82 | void osa_spin_destroy(void **lock_args) |
82 | { | 83 | { |
83 | kfree(*lock_args); | 84 | osa_free(*lock_args); |
84 | } | 85 | } |
85 | 86 | ||
diff --git a/osal/src/linux/osa_time.c b/osal/src/linux/osa_time.c index c01f39b..b5937b3 100644 --- a/osal/src/linux/osa_time.c +++ b/osal/src/linux/osa_time.c | |||
@@ -20,6 +20,7 @@ | |||
20 | #include <linux/slab.h> | 20 | #include <linux/slab.h> |
21 | 21 | ||
22 | #include "../../inc/osa_time.h" | 22 | #include "../../inc/osa_time.h" |
23 | #include "../../inc/osa_mem.h" | ||
23 | 24 | ||
24 | uint64 osa_get_number_of_ticks(void) | 25 | uint64 osa_get_number_of_ticks(void) |
25 | { | 26 | { |
@@ -44,7 +45,7 @@ void osa_getnstimeofday(void **ts_args) | |||
44 | 45 | ||
45 | /* Here memory allocating for struct timespec variable | 46 | /* Here memory allocating for struct timespec variable |
46 | * and memory deallocation should be taken care by the user */ | 47 | * and memory deallocation should be taken care by the user */ |
47 | *ts = kmalloc(sizeof(struct timespec), GFP_KERNEL); | 48 | *ts = osa_malloc(sizeof(struct timespec), GFP_KERNEL); |
48 | if(NULL == *ts) | 49 | if(NULL == *ts) |
49 | { | 50 | { |
50 | pr_err("Failed to allocate memory in 'osa_getnstimeofday' function \n"); | 51 | pr_err("Failed to allocate memory in 'osa_getnstimeofday' function \n"); |
@@ -61,7 +62,7 @@ void *osa_timespec_sub(void *end_time, void *start_time) | |||
61 | { | 62 | { |
62 | struct timespec *dif_time; | 63 | struct timespec *dif_time; |
63 | 64 | ||
64 | dif_time = kmalloc(sizeof(struct timespec), GFP_KERNEL); | 65 | dif_time = osa_malloc(sizeof(struct timespec), GFP_KERNEL); |
65 | if(NULL == dif_time) | 66 | if(NULL == dif_time) |
66 | { | 67 | { |
67 | pr_err("Failed to allocate memory in 'osa_timespec_sub' function\n"); | 68 | pr_err("Failed to allocate memory in 'osa_timespec_sub' function\n"); |
diff --git a/osal/src/linux/osa_workqueue.c b/osal/src/linux/osa_workqueue.c index 609249d..42dd0cb 100644 --- a/osal/src/linux/osa_workqueue.c +++ b/osal/src/linux/osa_workqueue.c | |||
@@ -20,6 +20,7 @@ | |||
20 | #include <linux/mutex.h> | 20 | #include <linux/mutex.h> |
21 | 21 | ||
22 | #include "../../inc/osa_workqueue.h" | 22 | #include "../../inc/osa_workqueue.h" |
23 | #include "../../inc/osa_mem.h" | ||
23 | 24 | ||
24 | DEFINE_MUTEX(mutex); | 25 | DEFINE_MUTEX(mutex); |
25 | 26 | ||
@@ -36,7 +37,7 @@ struct node *delayed_work_head = NULL; | |||
36 | void osa_insertfirst(struct node **head, void **key) | 37 | void osa_insertfirst(struct node **head, void **key) |
37 | { | 38 | { |
38 | //create a link | 39 | //create a link |
39 | struct node *link = (struct node*) kmalloc(sizeof(struct node), GFP_KERNEL); | 40 | struct node *link = (struct node*) osa_malloc(sizeof(struct node), GFP_KERNEL); |
40 | 41 | ||
41 | link->key = key; | 42 | link->key = key; |
42 | mutex_lock(&mutex); | 43 | mutex_lock(&mutex); |
@@ -167,7 +168,7 @@ void osa_destroy_workqueue(void *wq) | |||
167 | void osa_init_work(void **work_args, void *work_fn) | 168 | void osa_init_work(void **work_args, void *work_fn) |
168 | { | 169 | { |
169 | struct work_struct **work = (struct work_struct **)work_args; | 170 | struct work_struct **work = (struct work_struct **)work_args; |
170 | *work = kzalloc(sizeof(struct work_struct), GFP_KERNEL); | 171 | *work = osa_zalloc(sizeof(struct work_struct), GFP_KERNEL); |
171 | if(NULL == *work) | 172 | if(NULL == *work) |
172 | { | 173 | { |
173 | pr_err("Memory allocation failed for work_queue\n"); | 174 | pr_err("Memory allocation failed for work_queue\n"); |
@@ -181,7 +182,7 @@ void osa_init_work(void **work_args, void *work_fn) | |||
181 | void osa_init_delayed_work(void **work_args, void *work_fn) | 182 | void osa_init_delayed_work(void **work_args, void *work_fn) |
182 | { | 183 | { |
183 | struct delayed_work **work = (struct delayed_work **)work_args; | 184 | struct delayed_work **work = (struct delayed_work **)work_args; |
184 | *work = kzalloc(sizeof(struct delayed_work), GFP_KERNEL); | 185 | *work = osa_zalloc(sizeof(struct delayed_work), GFP_KERNEL); |
185 | if(NULL == *work) | 186 | if(NULL == *work) |
186 | { | 187 | { |
187 | pr_err("Memory allocation failed for delayed_work_queue\n"); | 188 | pr_err("Memory allocation failed for delayed_work_queue\n"); |
@@ -303,13 +304,10 @@ void *osa_get_work_buff(void *key, int8 flag) | |||
303 | void *work = NULL; | 304 | void *work = NULL; |
304 | 305 | ||
305 | data = osa_delete_work_key(key, flag); | 306 | data = osa_delete_work_key(key, flag); |
306 | if(NULL != data) | 307 | if (NULL != data) { |
307 | { | 308 | work = data->key; |
308 | work = data->key; | 309 | if (flag == TRUE) |
309 | if(flag == TRUE) | 310 | osa_free(data); |
310 | { | ||
311 | kfree(data); | ||
312 | } | ||
313 | } | 311 | } |
314 | return work; | 312 | return work; |
315 | } | 313 | } |
@@ -320,13 +318,10 @@ void *osa_get_delayed_work_buff(void *key, int8 flag) | |||
320 | void *dwork = NULL; | 318 | void *dwork = NULL; |
321 | 319 | ||
322 | data = osa_delete_delayed_work_key(key, flag); | 320 | data = osa_delete_delayed_work_key(key, flag); |
323 | if(NULL != data) | 321 | if (NULL != data) { |
324 | { | 322 | dwork = data->key; |
325 | dwork = data->key; | 323 | if (flag == TRUE) |
326 | if(flag == TRUE) | 324 | osa_free(data); |
327 | { | ||
328 | kfree(data); | ||
329 | } | ||
330 | } | 325 | } |
331 | return dwork; | 326 | return dwork; |
332 | } | 327 | } |