of: fdt: add missing allocation-failure check
authorJohan Hovold <johan@kernel.org>
Wed, 17 May 2017 15:29:09 +0000 (17:29 +0200)
committerBen Hutchings <ben@decadent.org.uk>
Fri, 15 Sep 2017 17:30:44 +0000 (18:30 +0100)
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>
[bwh: Backported to 3.2: adjust context]
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
drivers/of/fdt.c

index b77808c..29f121e 100644 (file)
@@ -388,6 +388,8 @@ static void __unflatten_device_tree(struct boot_param_header *blob,
        /* Allocate memory for the expanded device tree */
        mem = (unsigned long)
                dt_alloc(size + 4, __alignof__(struct device_node));
+       if (!mem)
+               return NULL;
 
        memset((void *)mem, 0, size);