]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
powerpc/boot: Only free if realloc() succeeds
authorMichael Ellerman <mpe@ellerman.id.au>
Thu, 29 Feb 2024 11:51:49 +0000 (22:51 +1100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 4 Sep 2024 11:17:36 +0000 (13:17 +0200)
[ Upstream commit f2d5bccaca3e8c09c9b9c8485375f7bdbb2631d2 ]

simple_realloc() frees the original buffer (ptr) even if the
reallocation failed.

Fix it to behave like standard realloc() and only free the original
buffer if the reallocation succeeded.

Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Link: https://msgid.link/20240229115149.749264-1-mpe@ellerman.id.au
Signed-off-by: Sasha Levin <sashal@kernel.org>
arch/powerpc/boot/simple_alloc.c

index 188c4f996512a5a6c2487c7a76a4c3fff4b47635..bc99f75b8582d259de52ee5615450d0c6a5dcbb6 100644 (file)
@@ -114,10 +114,11 @@ static void *simple_realloc(void *ptr, unsigned long size)
                return ptr;
 
        new = simple_malloc(size);
-       if (new)
+       if (new) {
                memcpy(new, ptr, p->size);
+               simple_free(ptr);
+       }
 
-       simple_free(ptr);
        return new;
 }