powerpc/boot: Handle allocation failure in simple_realloc()
authorLi zeming <zeming@nfschina.com>
Mon, 19 Dec 2022 02:18:16 +0000 (10:18 +0800)
committerMichael Ellerman <mpe@ellerman.id.au>
Sun, 3 Mar 2024 11:20:28 +0000 (22:20 +1100)
simple_malloc() will return NULL when there is not enough memory left.
Check pointer 'new' before using it to copy the old data.

Signed-off-by: Li zeming <zeming@nfschina.com>
[mpe: Reword subject, use change log from Christophe]
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Link: https://msgid.link/20221219021816.3012-1-zeming@nfschina.com
arch/powerpc/boot/simple_alloc.c

index 267d6524caac47d5897fec42fa1873d0740bc21a..db9aaa5face3ff9b3763105766b316082891421a 100644 (file)
@@ -112,7 +112,9 @@ static void *simple_realloc(void *ptr, unsigned long size)
                return ptr;
 
        new = simple_malloc(size);
-       memcpy(new, ptr, p->size);
+       if (new)
+               memcpy(new, ptr, p->size);
+
        simple_free(ptr);
        return new;
 }