Skip to content

Commit 69b0194

Browse files
Li zemingmpe
authored andcommitted
powerpc/boot: Handle allocation failure in simple_realloc()
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
1 parent cda9c0d commit 69b0194

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

arch/powerpc/boot/simple_alloc.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,9 @@ static void *simple_realloc(void *ptr, unsigned long size)
112112
return ptr;
113113

114114
new = simple_malloc(size);
115-
memcpy(new, ptr, p->size);
115+
if (new)
116+
memcpy(new, ptr, p->size);
117+
116118
simple_free(ptr);
117119
return new;
118120
}

0 commit comments

Comments
 (0)