summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--common/dlmalloc.c3
-rw-r--r--common/dummy_malloc.c4
-rw-r--r--lib/xfuncs.c32
3 files changed, 28 insertions, 11 deletions
diff --git a/common/dlmalloc.c b/common/dlmalloc.c
index 499ec93c28..9c33cc2c95 100644
--- a/common/dlmalloc.c
+++ b/common/dlmalloc.c
@@ -1753,7 +1753,6 @@ void *calloc(size_t n, size_t elem_size)
/* Utility to update current_mallinfo for malloc_stats and mallinfo() */
-#ifdef CONFIG_CMD_MEMINFO
static void malloc_update_mallinfo(void)
{
int i;
@@ -1821,8 +1820,6 @@ void malloc_stats(void)
#endif
}
-#endif /* CONFIG_CMD_MEMINFO */
-
/*
History:
diff --git a/common/dummy_malloc.c b/common/dummy_malloc.c
index dd36a5b156..641baa125a 100644
--- a/common/dummy_malloc.c
+++ b/common/dummy_malloc.c
@@ -24,6 +24,10 @@
#include <common.h>
#include <malloc.h>
+void malloc_stats(void)
+{
+}
+
void *memalign(size_t alignment, size_t bytes)
{
unsigned long mem = (unsigned long)sbrk(bytes + alignment);
diff --git a/lib/xfuncs.c b/lib/xfuncs.c
index 1dc2ea92d8..1bcaa5e10e 100644
--- a/lib/xfuncs.c
+++ b/lib/xfuncs.c
@@ -18,18 +18,30 @@
* GNU General Public License for more details.
*
*/
+#define pr_fmt(fmt) "xfuncs: " fmt
#include <common.h>
#include <malloc.h>
#include <module.h>
#include <wchar.h>
+static void __noreturn enomem_panic(size_t size)
+{
+ pr_emerg("out of memory\n");
+ if (size)
+ pr_emerg("Unable to allocate %d bytes\n", size);
+
+ malloc_stats();
+
+ panic("out of memory");
+}
+
void *xmalloc(size_t size)
{
void *p = NULL;
if (!(p = malloc(size)))
- panic("ERROR: out of memory\n");
+ enomem_panic(size);
return p;
}
@@ -40,7 +52,7 @@ void *xrealloc(void *ptr, size_t size)
void *p = NULL;
if (!(p = realloc(ptr, size)))
- panic("ERROR: out of memory\n");
+ enomem_panic(size);
return p;
}
@@ -63,7 +75,7 @@ char *xstrdup(const char *s)
p = strdup(s);
if (!p)
- panic("ERROR: out of memory\n");
+ enomem_panic(strlen(s) + 1);
return p;
}
@@ -95,7 +107,8 @@ void* xmemalign(size_t alignment, size_t bytes)
{
void *p = memalign(alignment, bytes);
if (!p)
- panic("ERROR: out of memory\n");
+ enomem_panic(bytes);
+
return p;
}
EXPORT_SYMBOL(xmemalign);
@@ -116,7 +129,7 @@ char *xvasprintf(const char *fmt, va_list ap)
p = bvasprintf(fmt, ap);
if (!p)
- panic("ERROR: out of memory\n");
+ enomem_panic(0);
return p;
}
EXPORT_SYMBOL(xvasprintf);
@@ -139,7 +152,8 @@ wchar_t *xstrdup_wchar(const wchar_t *s)
wchar_t *p = strdup_wchar(s);
if (!p)
- panic("ERROR: out of memory\n");
+ enomem_panic((wcslen(s) + 1) * sizeof(wchar_t));
+
return p;
}
EXPORT_SYMBOL(xstrdup_wchar);
@@ -149,7 +163,8 @@ wchar_t *xstrdup_char_to_wchar(const char *s)
wchar_t *p = strdup_char_to_wchar(s);
if (!p)
- panic("ERROR: out of memory\n");
+ enomem_panic((strlen(s) + 1) * sizeof(wchar_t));
+
return p;
}
EXPORT_SYMBOL(xstrdup_char_to_wchar);
@@ -159,7 +174,8 @@ char *xstrdup_wchar_to_char(const wchar_t *s)
char *p = strdup_wchar_to_char(s);
if (!p)
- panic("ERROR: out of memory\n");
+ enomem_panic((wcslen(s) + 1) * sizeof(wchar_t));
+
return p;
}
EXPORT_SYMBOL(xstrdup_wchar_to_char);