LinuxPPC-Dev Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] boot: simple_alloc: check after increasing memory allocation
@ 2022-12-19  2:18 Li zeming
  2022-12-19  6:42 ` Christophe Leroy
  2024-03-13 13:19 ` Michael Ellerman
  0 siblings, 2 replies; 3+ messages in thread
From: Li zeming @ 2022-12-19  2:18 UTC (permalink / raw)
  To: mpe, npiggin, christophe.leroy, gregkh
  Cc: linuxppc-dev, linux-kernel, Li zeming

The pointer new adds judgment and should help with program robustness.

Signed-off-by: Li zeming <zeming@nfschina.com>
---
 arch/powerpc/boot/simple_alloc.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

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


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

* Re: [PATCH] boot: simple_alloc: check after increasing memory allocation
  2022-12-19  2:18 [PATCH] boot: simple_alloc: check after increasing memory allocation Li zeming
@ 2022-12-19  6:42 ` Christophe Leroy
  2024-03-13 13:19 ` Michael Ellerman
  1 sibling, 0 replies; 3+ messages in thread
From: Christophe Leroy @ 2022-12-19  6:42 UTC (permalink / raw)
  To: Li zeming, mpe@ellerman.id.au, npiggin@gmail.com,
	gregkh@linuxfoundation.org
  Cc: linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org



Le 19/12/2022 à 03:18, Li zeming a écrit :
> The pointer new adds judgment and should help with program robustness.

This text is not understandable.

Do you mean:

simple_malloc() will return NULL when there is now enough memory left.
Check pointer 'new' before using it to copy the old data.

> 
> Signed-off-by: Li zeming <zeming@nfschina.com>
> ---
>   arch/powerpc/boot/simple_alloc.c | 4 +++-
>   1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/arch/powerpc/boot/simple_alloc.c b/arch/powerpc/boot/simple_alloc.c
> index 267d6524caac..db9aaa5face3 100644
> --- a/arch/powerpc/boot/simple_alloc.c
> +++ b/arch/powerpc/boot/simple_alloc.c
> @@ -112,7 +112,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;
>   }

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

* Re: [PATCH] boot: simple_alloc: check after increasing memory allocation
  2022-12-19  2:18 [PATCH] boot: simple_alloc: check after increasing memory allocation Li zeming
  2022-12-19  6:42 ` Christophe Leroy
@ 2024-03-13 13:19 ` Michael Ellerman
  1 sibling, 0 replies; 3+ messages in thread
From: Michael Ellerman @ 2024-03-13 13:19 UTC (permalink / raw)
  To: npiggin, christophe.leroy, gregkh, Li zeming; +Cc: linuxppc-dev, linux-kernel

On Mon, 19 Dec 2022 10:18:16 +0800, Li zeming wrote:
> The pointer new adds judgment and should help with program robustness.
> 
> 

Applied to powerpc/next.

[1/1] boot: simple_alloc: check after increasing memory allocation
      https://git.kernel.org/powerpc/c/69b0194ccec033c208b071e019032c1919c2822d

cheers

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

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

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-12-19  2:18 [PATCH] boot: simple_alloc: check after increasing memory allocation Li zeming
2022-12-19  6:42 ` Christophe Leroy
2024-03-13 13:19 ` Michael Ellerman

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox