]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
powerpc/boot: Handle allocation failure in simple_realloc()
authorLi zeming <zeming@nfschina.com>
Mon, 19 Dec 2022 02:18:16 +0000 (10:18 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 4 Sep 2024 11:17:36 +0000 (13:17 +0200)
[ Upstream commit 69b0194ccec033c208b071e019032c1919c2822d ]

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
Signed-off-by: Sasha Levin <sashal@kernel.org>
arch/powerpc/boot/simple_alloc.c

index 65ec135d015798490560c3a5bf419cc08e42aa9e..188c4f996512a5a6c2487c7a76a4c3fff4b47635 100644 (file)
@@ -114,7 +114,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;
 }