From: Li zeming Date: Mon, 19 Dec 2022 02:18:16 +0000 (+0800) Subject: powerpc/boot: Handle allocation failure in simple_realloc() X-Git-Tag: v5.10.225~89 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=486fb5ebd5d6b09cc186d8599b51b0d907366be9;p=thirdparty%2Fkernel%2Fstable.git powerpc/boot: Handle allocation failure in simple_realloc() [ 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 [mpe: Reword subject, use change log from Christophe] Signed-off-by: Michael Ellerman Link: https://msgid.link/20221219021816.3012-1-zeming@nfschina.com Signed-off-by: Sasha Levin --- diff --git a/arch/powerpc/boot/simple_alloc.c b/arch/powerpc/boot/simple_alloc.c index 65ec135d01579..188c4f996512a 100644 --- a/arch/powerpc/boot/simple_alloc.c +++ b/arch/powerpc/boot/simple_alloc.c @@ -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; }