]> git.baikalelectronics.ru Git - kernel.git/commitdiff
of: fdt: add missing allocation-failure check
authorJohan Hovold <johan@kernel.org>
Wed, 17 May 2017 15:29:09 +0000 (17:29 +0200)
committerRob Herring <robh@kernel.org>
Wed, 17 May 2017 16:36:52 +0000 (11:36 -0500)
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: 4d41df789678 ("of/flattree: Refactor unflatten_device_tree and add fdt_unflatten_tree")
Cc: stable <stable@vger.kernel.org> # 2.6.38
Signed-off-by: Johan Hovold <johan@kernel.org>
Signed-off-by: Rob Herring <robh@kernel.org>
drivers/of/fdt.c

index a0972219ccfc5fccee139c46d9f4fd97445973e2..0373ae49d24dc43f491822ceedc7f8c5c1da45f3 100644 (file)
@@ -507,6 +507,9 @@ void *__unflatten_device_tree(const void *blob,
 
        /* Allocate memory for the expanded device tree */
        mem = dt_alloc(size + 4, __alignof__(struct device_node));
+       if (!mem)
+               return NULL;
+
        memset(mem, 0, size);
 
        *(__be32 *)(mem + size) = cpu_to_be32(0xdeadbeef);