aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohan Hovold <johan@kernel.org>2017-05-17 17:29:09 +0200
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2017-05-25 14:17:58 +0200
commit8f7f956d12ac150e69a3fd645b6e01507f3ec343 (patch)
tree8fe35cc5a52f6809a2bdfc43f544943ec0d28871
parent3829ab9ff69fb78713addc58e642d40d5c28ba56 (diff)
of: fdt: add missing allocation-failure check
commit 49e67dd17649b60b4d54966e18ec9c80198227f0 upstream. The memory allocator passed to __unflatten_device_tree() (e.g. a wrapped kzalloc) can fail so add the missing sanity check to avoid dereferencing a NULL pointer. Fixes: fe14042358fa ("of/flattree: Refactor unflatten_device_tree and add fdt_unflatten_tree") Signed-off-by: Johan Hovold <johan@kernel.org> Signed-off-by: Rob Herring <robh@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r--drivers/of/fdt.c3
1 files changed, 3 insertions, 0 deletions
diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c
index d134710de96d..74c7aba476f6 100644
--- a/drivers/of/fdt.c
+++ b/drivers/of/fdt.c
@@ -380,6 +380,9 @@ static void __unflatten_device_tree(void *blob,
/* Allocate memory for the expanded device tree */
mem = dt_alloc(size + 4, __alignof__(struct device_node));
+ if (!mem)
+ return;
+
memset(mem, 0, size);
*(__be32 *)(mem + size) = cpu_to_be32(0xdeadbeef);