aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTakashi Iwai <tiwai@suse.de>2013-03-13 18:27:01 +0100
committerTakashi Iwai <tiwai@suse.de>2013-03-13 18:27:01 +0100
commit42213cb83037cbebca37b3088542eaf73814cc18 (patch)
tree75ac9575bee333422401346537302f6f34892911
parent33e032e0e680b344544ee2cede038578d6f05753 (diff)
downloadhda-emu-42213cb83037cbebca37b3088542eaf73814cc18.tar.gz
Enable the malloc debugging as default
Also support __GFP_ZERO flag.
-rw-r--r--configure.ac7
-rw-r--r--include/linux/slab.h20
-rw-r--r--include/wrapper.h8
-rw-r--r--snd-wrapper.c33
4 files changed, 31 insertions, 37 deletions
diff --git a/configure.ac b/configure.ac
index 2058bac..31b31cd 100644
--- a/configure.ac
+++ b/configure.ac
@@ -32,13 +32,6 @@ if test "$readline" = "yes"; then
fi
AC_SUBST(LIBREADLINE)
-AC_ARG_ENABLE(debug-malloc,
- AS_HELP_STRING([--enable-debug-malloc], [turn on malloc-debug code]),
- debug_malloc="$enableval", debug_malloc="no")
-if test "$debug_malloc" = "yes"; then
- AC_DEFINE(DEBUG_MALLOC)
-fi
-
AC_ARG_ENABLE(old-workq,
AS_HELP_STRING([--enable-old-workq], [use old workqueue API]),
old_workq="$enableval", old_workq="no")
diff --git a/include/linux/slab.h b/include/linux/slab.h
index 83afdde..b7bc2c1 100644
--- a/include/linux/slab.h
+++ b/include/linux/slab.h
@@ -6,22 +6,14 @@
typedef unsigned int gfp_t;
#define GFP_KERNEL 0
#define GFP_ATOMIC 0
+#define __GFP_ZERO (1<<8)
-#ifdef DEBUG_MALLOC
-#define kmalloc(size,gfp) __hda_malloc(size, __FILE__, __LINE__)
-#define kzalloc(size,gfp) kmalloc(size, gfp)
-#define kcalloc(elem,size,gfp) kmalloc((elem)*(size), gfp)
-#define krealloc(ptr,size,gfp) __hda_realloc(ptr, size, __FILE__, __LINE__)
+#define kmalloc(size,gfp) __hda_malloc(size, __FILE__, __LINE__, gfp)
+#define kzalloc(size,gfp) kmalloc(size, gfp | __GFP_ZERO)
+#define kcalloc(elem,size,gfp) kmalloc((elem)*(size), gfp | __GFP_ZERO)
+#define krealloc(ptr,size,gfp) __hda_realloc(ptr, size, __FILE__, __LINE__, gfp)
#define kfree(ptr) __hda_free((void*)(ptr), __FILE__, __LINE__)
-#define kstrdup(str,x) __hda_strdup(str, __FILE__, __LINE__)
-#else
-#define kmalloc(size,gfp) malloc(size)
-#define kzalloc(size,gfp) calloc(1,size)
-#define kcalloc(elem,size,gfp) calloc(elem,size)
-#define krealloc(ptr,size,gfp) realloc(ptr, size)
-#define kfree(ptr) free((void*)(ptr))
-#define kstrdup(str,x) strdup(str)
-#endif
+#define kstrdup(str,gfp) __hda_strdup(str, __FILE__, __LINE__, gfp)
static inline size_t strlcpy(char *dest, const char *src, size_t size)
{
diff --git a/include/wrapper.h b/include/wrapper.h
index 66d781b..6058ff8 100644
--- a/include/wrapper.h
+++ b/include/wrapper.h
@@ -197,12 +197,10 @@ static inline size_t strlcat(char *dest, const char *src, size_t count)
return res;
}
-#ifdef DEBUG_MALLOC
-void *__hda_malloc(size_t size, const char *file, int line);
+void *__hda_malloc(size_t size, const char *file, int line, int gfp);
void __hda_free(void *ptr, const char *file, int line);
-void *__hda_realloc(const void *p, size_t new_size, const char *file, int line);
-void *__hda_strdup(const char *str, const char *file, int line);
-#endif
+void *__hda_realloc(const void *p, size_t new_size, const char *file, int line, int gfp);
+void *__hda_strdup(const char *str, const char *file, int line, int gfp);
/*
* lock debug
diff --git a/snd-wrapper.c b/snd-wrapper.c
index 78ed28f..1ec8a49 100644
--- a/snd-wrapper.c
+++ b/snd-wrapper.c
@@ -260,9 +260,9 @@ snd_pci_quirk_lookup(struct pci_dev *pci, const struct snd_pci_quirk *list)
#endif /* snd_pci_quirk_lookup */
/* malloc debug */
-#ifdef DEBUG_MALLOC
struct __hda_malloc_elem {
void *ptr;
+ size_t size;
const char *file;
int line;
struct list_head list;
@@ -270,17 +270,21 @@ struct __hda_malloc_elem {
static LIST_HEAD(malloc_list);
-void *__hda_malloc(size_t size, const char *file, int line)
+void *__hda_malloc(size_t size, const char *file, int line, int gfp)
{
struct __hda_malloc_elem *elem = malloc(sizeof(*elem));
if (!elem)
return NULL;
- elem->ptr = calloc(1, size);
+ if (gfp & __GFP_ZERO)
+ elem->ptr = calloc(1, size);
+ else
+ elem->ptr = malloc(size);
if (!elem->ptr) {
free(elem);
return NULL;
}
elem->file = file;
+ elem->size = size;
elem->line = line;
list_add_tail(&elem->list, &malloc_list);
return elem->ptr;
@@ -306,12 +310,12 @@ void __hda_free(void *ptr, const char *file, int line)
assert(0);
}
-void *__hda_realloc(const void *p, size_t new_size, const char *file, int line)
+void *__hda_realloc(const void *p, size_t new_size, const char *file, int line, int gfp)
{
struct __hda_malloc_elem *elem;
if (!p)
- return __hda_malloc(new_size, file, line);
+ return __hda_malloc(new_size, file, line, gfp);
if (!new_size) {
__hda_free((void *)p, file, line);
return NULL;
@@ -319,26 +323,33 @@ void *__hda_realloc(const void *p, size_t new_size, const char *file, int line)
list_for_each_entry(elem, &malloc_list, list) {
if (elem->ptr == p) {
- void *nptr = realloc((void *)p, new_size);
- if (nptr)
+ void *nptr;
+ if (gfp & __GFP_ZERO)
+ nptr = calloc(1, new_size);
+ else
+ nptr = malloc(new_size);
+ if (nptr) {
+ memcpy(nptr, elem->ptr, elem->size);
+ free(elem->ptr);
elem->ptr = nptr;
+ elem->size = new_size;
+ }
return nptr;
}
}
hda_log(HDA_LOG_ERR, "Untracked malloc realloced in %s:%d\n",
file, line);
- return __hda_malloc(new_size, file, line);
+ return __hda_malloc(new_size, file, line, gfp);
}
-void *__hda_strdup(const char *str, const char *file, int line)
+void *__hda_strdup(const char *str, const char *file, int line, int gfp)
{
- char *dest = __hda_malloc(strlen(str) + 1, file, line);
+ char *dest = __hda_malloc(strlen(str) + 1, file, line, gfp);
if (!dest)
return NULL;
strcpy(dest, str);
return dest;
}
-#endif /* DEBUG_MALLOC */
/* jack API */
#include <sound/jack.h>