summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRoland Hieber <rhi@pengutronix.de>2019-01-07 12:07:33 +0100
committerRoland Hieber <rhi@pengutronix.de>2019-01-07 12:26:50 +0100
commit93fb4072e860a7a4e5f89b889fc8dfeb20556c11 (patch)
tree9f413ed85df6eb77a4dd16d943625155acf4ba63
parent509ce56d1e5bcaea2904cecc5b16a5c244bf9e74 (diff)
downloaddt-utils-93fb4072e860a7a4e5f89b889fc8dfeb20556c11.tar.gz
dt-utils-93fb4072e860a7a4e5f89b889fc8dfeb20556c11.tar.xz
libdt: xzalloc: die on failure
Behave like the well-known kernel variant, so existing code that doesn't check xzallocs return value can be ported easier. Signed-off-by: Roland Hieber <rhi@pengutronix.de>
-rw-r--r--src/dt/common.h10
1 files changed, 9 insertions, 1 deletions
diff --git a/src/dt/common.h b/src/dt/common.h
index 6633be6..cbe17ce 100644
--- a/src/dt/common.h
+++ b/src/dt/common.h
@@ -85,7 +85,15 @@ int dev_printf(int level, const struct device_d *dev, const char *format, ...)
static inline void *xzalloc(size_t size)
{
- return calloc(1, size);
+ void * buf = calloc(1, size);
+ if (!buf || errno == ENOMEM) {
+ /* although the glibc variant of calloc sets errno, not all
+ * variants do, but should still return NULL. */
+ errno = ENOMEM;
+ perror("xzalloc");
+ exit(1);
+ }
+ return buf;
}
static inline void *xmalloc(size_t size)