All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] powerpc/boot: Only free if realloc() succeeds
@ 2024-02-29 11:51 Michael Ellerman
  2024-03-13 13:19 ` Michael Ellerman
  0 siblings, 1 reply; 2+ messages in thread
From: Michael Ellerman @ 2024-02-29 11:51 UTC (permalink / raw)
  To: linuxppc-dev

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>
---
 arch/powerpc/boot/simple_alloc.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/arch/powerpc/boot/simple_alloc.c b/arch/powerpc/boot/simple_alloc.c
index db9aaa5face3..d07796fdf91a 100644
--- a/arch/powerpc/boot/simple_alloc.c
+++ b/arch/powerpc/boot/simple_alloc.c
@@ -112,10 +112,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;
 }
 
-- 
2.43.2


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] powerpc/boot: Only free if realloc() succeeds
  2024-02-29 11:51 [PATCH] powerpc/boot: Only free if realloc() succeeds Michael Ellerman
@ 2024-03-13 13:19 ` Michael Ellerman
  0 siblings, 0 replies; 2+ messages in thread
From: Michael Ellerman @ 2024-03-13 13:19 UTC (permalink / raw)
  To: linuxppc-dev, Michael Ellerman

On Thu, 29 Feb 2024 22:51:49 +1100, Michael Ellerman wrote:
> 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.
> 
> 
> [...]

Applied to powerpc/next.

[1/1] powerpc/boot: Only free if realloc() succeeds
      https://git.kernel.org/powerpc/c/f2d5bccaca3e8c09c9b9c8485375f7bdbb2631d2

cheers

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-03-13 13:33 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-29 11:51 [PATCH] powerpc/boot: Only free if realloc() succeeds Michael Ellerman
2024-03-13 13:19 ` Michael Ellerman

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.